To manage Kubernetes, the kubectl command line is used and installed locally (or used in the Azure cloud shell). This is command-line interface tooling that will communicate with the Kubernetes API. Let's see how to work with Kubernetes with this command line:
- If you do not already have it installed, run the following command to install the Azure CLI on your machine:
az aks install-cli
- To connect to the cluster, the credentials need to be retrieved and saved to the local system. This can be done by using the az aks get-credentials command and specifying the resource group and cluster name:
az aks get-credentials --resource-group mpn-rg-kubernetes --name mykubernetescluster
- With all the prerequisites configured, a lot of the base functionality can be run against the Kubernetes cluster. Take a look at these two commands for example:
-
- Retrieve the nodes of the cluster:
kubectl get nodes
-
- Get the pods in the cluster:
kubectl get pods
- Next to the preceding commands, you can also try the following Azure CLI command to open up the Kubernetes dashboard. This dashboard is a management interface built on top of the Kubernetes API that can be used next to the kubectl command line:
az aks browse --resource-group mpn-rg-kubernetes --name mykubernetescluster
The dashboard is shown in the following screenshot:
A deployment file needs to be created to be able to run containers within the cluster. So let's see how to do this.