Common Azure Kubernetes Services AKS Commands (Cheet Sheet)


k8s Common Azure Kubernetes Services AKS Commands (Cheet Sheet) cloud cloud computing DevOps docker Kubernetes Microsoft Azure

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.

Install AKS cli

1
az aks install-cli
az aks install-cli

Install AKS Extension

1
az extension add --name aks-preview
az extension add --name aks-preview

Create a AKS Cluster

1
2
3
4
5
6
7
8
9
10
az aks create \
    --resource-group RESOURCE_GROUP \
    --name AKS_NAME \
    --node-count 1 \
    --max-pods 30 \
    --kubernetes-version 1.25.4 \
    --generate-ssh-keys \
    --enable-cluster-autoscaler \
    --min-count 1 \
    --max-count 3
az aks create \
    --resource-group RESOURCE_GROUP \
    --name AKS_NAME \
    --node-count 1 \
    --max-pods 30 \
    --kubernetes-version 1.25.4 \
    --generate-ssh-keys \
    --enable-cluster-autoscaler \
    --min-count 1 \
    --max-count 3

Get supported Kubernetes Versions

1
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.

List current contexts.

1
kubectl config get-contexts
kubectl config get-contexts

Get current context.

1
kubectl  config current-context
kubectl  config current-context

Switch to another context.

1
kubectl config use-context CONTEXT
kubectl config use-context CONTEXT

Create a AKS Secret

1
kubectl create secret -n NAMESPACE docker-registry CRED_NAME --docker-server=https://ACR.azurecr.io  --docker-username=USERNAME --docker-password=PASSWORD
kubectl create secret -n NAMESPACE docker-registry CRED_NAME --docker-server=https://ACR.azurecr.io  --docker-username=USERNAME --docker-password=PASSWORD

Get a AKS Secret

1
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…

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
574 words
Last Post: Teaching Kids Programming - Sum of Number and Its Reverse (Bruteforce Algorithm)
Next Post: Teaching Kids Programming - How to Design a Random Maze? Random Maze Generation Algorithm

The Permanent URL is: Common Azure Kubernetes Services AKS Commands (Cheet Sheet)

Leave a Reply