How to connect Azure Kubernetes Service(AKS) Cluster and run Kubectl commands

How to connect Azure Kubernetes Service(AKS) Cluster and run Kubectl commands


This KB has information about connecting the Azure Kubernetes Cluster using Azure CLI and kubectl commands.

Notes
Verify both Azure CLI and kubectl are configured in Applications Manager installed server as mentioned in our prerequisites.
This document provides the steps involving in connecting the Azure Kubernetes Cluster:
  1. Login to the Azure account
  2. Login and connect to the AKS cluster
    1. Generate kubeconfig file for the cluster
    2. Connect and run kubectl commands 
Alert
Before proceeding to connect to the AKS cluster, please ensure that all the steps in the pre-requisites have been done.

Login to the Azure account

  1. To set the Azure Cloud type for the Azure CLI. Open command prompt, run the below command:
    1. az cloud set --name <CloudType>
    2. For the CloudType, use the below values accordingly:
      1. Azure Global: AzureCloud
      2. Azure US Gov Cloud: AzureUSGovernment
      3. Azure China: AzureChinaCloud
  2. To login to the Azure subscription, runthe below command:
    1. az login --service-principal -u <app-id> -p <password-or-cert> --tenant <tenant>, Refer here for more details.
      1. Formataz 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

  1. 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.
  1. Open command prompt, run the below command
Quoteaz account set --subscription aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  1. To generate kubeconfig file, run the below command
Quote
az aks get-credentials --resource-group resourcegroupname --name clustername
Notes
Above command will create the kubeconfig file in the user root directory. To get kubeconfig file in the specific location, use below command
  1. az aks get-credentials --resource-group resourcegroupname --name clustername --file <specific_location>
 

b. Connect and run kubectl commands

  1. (Optional) To bypass interactive login for kubectl commands:
  2. Quotekubelogin convert-kubeconfig -l azurecli --kubeconfig <FILEPATH>
  3. Execute the below commands to verify the connectivity to the cluster, replace <FILEPATH> with the path where the KUBECONFIG file is created:
  4. Quotekubectl get nodes --kubeconfig <FILEPATH>
    kubectl get pods -A --kubeconfig <FILEPATH>

List of kubectl commands used in Applications Manager

  1. All the commands will be appended with --kubeconfig <FILEPATH>.
  2. If proxy configured, then run the below command by replacing the clustername and proxyurl 
Quotekubectl config set clusters.clustername.proxy-url proxyurl
  1. Below are the list of commands used for kubectl performance metrics data collection.
    1. kubectl get namespaces -o json
    2. kubectl get componentstatuses -o json --all-namespaces
    3. kubectl get nodes -o json
    4. kubectl get pods -o json --all-namespaces
    5. kubectl get services -o json --all-namespaces
    6. kubectl get deployments -o json --all-namespaces
    7. kubectl get persistentvolumes -o json --all-namespaces
    8. kubectl get persistentvolumeclaims -o json --all-namespaces
    9. kubectl describe nodes
    10. kubelogin convert-kubeconfig -l azurecli - Only used for Microsoft Entra ID authentication

List of Azure CLI commands used in Applications Manager

  1. az version
  2. az cloud set --name <cloud-type>
  3. az account set --subscription <subscription-id>
    1. az login -u <useremail> -p <password> (OR)
    2. az login --service-principal -u <client-id> -p <client-secret> --tenant <tenant-id>
  4. az aks get-credentials --resource-group <resource-group-name> --name <cluster-name> --file <kubeconfig-file>
Notes
If any issue persists, please reach out via mail to appmanager-support@manageengine.com with the below information:
  1. Latest Support Information File (SIF)ensuring that 'print all logs' is enabled.
  2. 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)
  3. Command: kubectl version --client (To connect to EKS cluster) --> Sample Output starts with: Client Version: v1.23.2
  4. Check if the Applications Manager installed user has permission to access installed kubectl/azure-cli by verifying prerequisites mentioned above.
  5. Screenshot of network configuration in Azure portal > Kubernetes services > Networking.
  6. 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.
    1. For Example, if you chose 'Microsoft Entra ID authentication with Kubernetes RBAC', send the following details:


      1. Screenshot of the owners of the groups.
      2. 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 ...