Common Azure Kubernetes Services AKS Commands (Cheet Sheet)
ACMer
Kubernetes
Kubernetes is a de-facto standard to deploy and manage applications in the cloud. The cloud apps are running in pods (containers). With Kubernetes, the pods can restart themselves if they crash. And the applications can auto scale themselve easily. This post shows some common commands using azure cli to manage the Kubernetes.
FULL_CAPTIAL_LETTERS are parameters. Recommended to do “alias k=kubectl” to improve the productivity.
az aks get-versions --location eastus --output table
az aks get-versions --location eastus --output table
Merge AKS Cluster kubeconfig
The ~/.kube/config stores the configurations to access different clusters. The following command will merge the given AKS Cluster (as above) to your local workstation so that you can manage it.
1
az aks get-credentials --resource-group RESOURCE_GROUP --name AKS_NAME --admin
az aks get-credentials --resource-group RESOURCE_GROUP --name AKS_NAME --admin
AKS Context
You can manage several clusters by switching contexts.
kubectl get secrets -n NAMESPACE CRED_NAME -o yaml
kubectl get secrets -n NAMESPACE CRED_NAME -o yaml
Delete a AKS Secret
1
kubectl delete secret -n NAMESPACE CRED_NAME
kubectl delete secret -n NAMESPACE CRED_NAME
List all Namespaces
1
kubectl get namespaces
kubectl get namespaces
Describe a Pod
1
kubectl describe pod -n NAMESPACE PODNAME
kubectl describe pod -n NAMESPACE PODNAME
List all Nodes
1
2
kubectl get pods -A
kubectl get pods -A-w
kubectl get pods -A
kubectl get pods -A -w
Update AKS Version
We can use the following az command to update (upgrade) an existing AKS Cluster to a specific Kubernetes version:
1
2
3
# set KUBERNETES_VERSION based on the result from this query
az aks get-upgrades --resource-group$RESOURCE_GROUP--name$AKS_CLUSTER--output table
az aks upgrade --resource-group$RESOURCE_GROUP--name$AKS_CLUSTER--kubernetes-version$KUBERNETES_VERSION-y
# set KUBERNETES_VERSION based on the result from this query
az aks get-upgrades --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER --output table
az aks upgrade --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER --kubernetes-version $KUBERNETES_VERSION -y
Set to Auto Upgrade for AKS Version
We can use the following az command to set AKS auto upgrade policy:
1
az aks update --resource-group$RESOURCE_GROUP--name$AKS_CLUSTER--auto-upgrade-channel stable
az aks update --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER --auto-upgrade-channel stable
This cheetsheet will be updated from time to time…