How to connect Azure Kubernetes Service(AKS) Cluster and run Kubectl commands
Login to the Azure account
- To set the Azure Cloud type for the Azure CLI. Open command prompt, run the below command:
- az cloud set --name <CloudType>
- For the CloudType, use the below values accordingly:
- Azure Global: AzureCloud
- Azure US Gov Cloud: AzureUSGovernment
- Azure China: AzureChinaCloud
- To login to the Azure subscription, runthe below command:
- az login --service-principal -u <app-id> -p <password-or-cert> --tenant <tenant>, Refer here for more details.
- Format: az login --service-principal -u aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee -p aaaaaaa.bbbbbb~ccccc~ddd-eeeee~fff --tenant aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
Login and connect to Azure AKS Cluster:
a. Generate kubeconfig file for the cluster
- Go to Azure Portal -> Kubernetes Services -> Select the required Cluster -> Overview -> Connect to find the entire command for the specific cluster itself or follow the below commands one by one by replacing with subscription Id, cluster name and resource group name.
- Open command prompt, run the below command
az account set --subscription aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
- To generate kubeconfig file, run the below command
az aks get-credentials --resource-group resourcegroupname --name clustername
Above command will create the kubeconfig file in the user root directory. To get kubeconfig file in the specific location, use below command
- az aks get-credentials --resource-group resourcegroupname --name clustername --file <specific_location>
b. Connect and run kubectl commands
- (Optional) To bypass interactive login for kubectl commands:
kubelogin convert-kubeconfig -l azurecli --kubeconfig <FILEPATH> - Execute the below commands to verify the connectivity to the cluster, replace <FILEPATH> with the path where the KUBECONFIG file is created:
kubectl get nodes --kubeconfig <FILEPATH>
kubectl get pods -A --kubeconfig <FILEPATH>
List of kubectl commands used in Applications Manager
All the commands will be appended with --kubeconfig <FILEPATH>.
If proxy configured, then run the below command by replacing the clustername and proxyurl
kubectl config set clusters.clustername.proxy-url proxyurl
Below are the list of commands used for kubectl performance metrics data collection.
kubectl get namespaces -o json
kubectl get componentstatuses -o json --all-namespaces
kubectl get nodes -o json
kubectl get pods -o json --all-namespaces
kubectl get services -o json --all-namespaces
kubectl get deployments -o json --all-namespaces
kubectl get persistentvolumes -o json --all-namespaces
kubectl get persistentvolumeclaims -o json --all-namespaces
kubelogin convert-kubeconfig -l azurecli - Only used for Microsoft Entra ID authentication
List of Azure CLI commands used in Applications Manager
- az version
- az cloud set --name <cloud-type>
- az account set --subscription <subscription-id>
- az login -u <useremail> -p <password> (OR)
- az login --service-principal -u <client-id> -p <client-secret> --tenant <tenant-id>
- az aks get-credentials --resource-group <resource-group-name> --name <cluster-name> --file <kubeconfig-file>
- Latest Support Information File (SIF), ensuring that 'print all logs' is enabled.
- Command: az --version (To login to Azure account) --> Sample Output (For windows 10): azure-cli/2.31.0 Python/3.8.9 Windows/10 exe/AMD64 prompt/off)
- Command: kubectl version --client (To connect to EKS cluster) --> Sample Output starts with: Client Version: v1.23.2
- Check if the Applications Manager installed user has permission to access installed kubectl/azure-cli by verifying prerequisites mentioned above.
- Screenshot of network configuration in Azure portal > Kubernetes services > Networking.
- If Microsoft Entra ID authentication is used out of the three supported modes, send the screenshot of the configuration of the user for the Kubernetes cluster.
- For Example, if you chose 'Microsoft Entra ID authentication with Kubernetes RBAC', send the following details:
-
- Screenshot of the owners of the groups.
- Screenshot of the IAM role binding of the Kubernetes cluster from the prerequisites.
New to ADSelfService Plus?
Related Articles
Azure Kubernetes Service(AKS) Troubleshooting FAQs
Azure Kubernetes Service (AKS) monitor can be configured only if you have already added a Microsoft Azure monitor in Applications Manager. Ensure that you have met all the prerequisites for the Microsoft Azure monitor before monitoring Azure ...
Unable to Add Kubernetes Monitor
If you are having trouble adding a Kubernetes monitor in Applications Manager, ensure that the the prerequisites have been met: Verify whether you can establish an SSH connection to the Kubernetes server from the APM installed machine. Use the ...
Absence of data in the Pods tab or some tabs in the Kubernetes monitor
This is a known issue in the older version of Applications Manager, which is fixed in APM v16800. So, we recommend upgrading the Applications Manager to the stable version to properly fix this issue. To collect data for the Kubernetes Monitor, ...
Microsoft Azure - FAQ
1. What happens to the Azure monitor in Applications Manager when you delete any of the supported services from the Azure portal? When you perform a delete operation on any of the supported Azure resources in the Azure portal, the respective monitor ...
How to add an APM Insight Java agent in Kubernetes via InitContainers?
Step 1. Create a secret to access the APM Insight license key in your application namespace: kubectl create secret generic app-secret --from-literal=s247licensekey='your_APMInsight_license_key' -n petclinic The license key can be obtained from the ...