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

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

Below information used to connect to Azure Kubernetes Cluster using Az commands and to run Kubectl commands to collect the cluster performance metrics.
Verify both Azure CLI and Kubectl are configured in AppManager installed server as mentioned in our prerequisites.
First we need to login to the Azure account by configuring Azure subscription and login details. And then we need to connect to Kubernetes Cluster only then we can able to run Kubectl commands.

Steps to connect Azure account:
  1. Open command prompt, run az cloud set --name AzureCloud
To set Azure Government cloud, run az cloud set --name AzureUSGovernment, click here to know more.
  1. To set subscription, run az login --service-principal -u <app-id> -p <password-or-cert> --tenant <tenant>, Refer here for more details.
az login --service-principal -u aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee -p aaaaaaa.bbbbbb~ccccc~ddd-eeeee~fff --tenant aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee

Steps to connect Azure AKS 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
az account set --subscription aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  1. 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
  1. az aks get-credentials --resource-group resourcegroupname --name clustername --file <specific_location>

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 
kubectl 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
If any of the above command fails, then send us the command and its output in a text file.
Reach out to our support team with the text file containing the output to along with the latest Support Information File (SIF) from Applications Manager with print all logs enabled for analysis.

      • 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 ...
      • Setup Applications Manager as Service in Ubuntu 16 and above

        Follow the steps mentioned below to install AppManager as a service on a Linux box. Copy the attached AppManagerLinuxService file to /etc/init.d directory as the file "AppManager" Edit the MDIR variable in this file (in two locations) which should ...
      • Installing Applications Manager in Microsoft Azure

        Applications manager can be installed in Azure Virtual Machines in both Windows and Linux platforms.  Applications Manager comes with bundled PostgreSQL. Installing Applications Manager in VM for Windows Go to Virtual Machines and create a "Windows" ...
      • Azure SQL Database - Troubleshooting - Add client IP to Azure firewall

        "Connection to the database failed with error : Cannot open server <ServerName> requested by the login. Client with IP address <SomeIP> is not allowed to access the server.  To enable access, use the Windows Azure Management Portal or run ...
      • Enabling data collection for Cluster Details in MS SQL Monitor

        If you have installed Applications Manager in Linux, Cluster Tab details won't be available. Only Windows Admistrative users will be able to view Cluster Details tab in MS SQL Monitor. To view cluster details, you must have provided Windows ...