Kubectl and K9s
Description:
After downloading your context file for an Azure Kubernetes Services (AKS) cluster, you have many ways of interacting with the cluster. I will show the two I’m most familiar with here.
To Resolve:
-
If you haven’t already, install
kubectl
andk9s
on your machine locally -
First we will cover k9s since it is a console program for interacting with clusters:
- main commands:
ctrl+a
/:alias
=> shows all reasources for a cluster:q
/Ctrl+c
=> quit:ctx
=> shows context:node
=> navigates to a resource like all nodesd
describev
viewe
editl
logs- Reference all cli options here
-
From the k9s site:
1 2 3 4 5 6 7 8 9 10 11 12
# List all available CLI options k9s help # Get info about K9s runtime (logs, configs, etc..) k9s info # Run K9s in a given namespace. k9s -n mycoolns # Run K9s and launch in pod view via the pod command. k9s -c pod # Start K9s in a non default KubeConfig context k9s --context coolCtx # Start K9s in readonly mode - with all modification commands disabled k9s --readonly
-
So that is a tool to get familiar with, but more important is to get familiar with kubectl
- First, let’s look at context commands
1 2 3 4
kubectl config view # Show Merged kubeconfig settings. kubectl config get-contexts # display list of contexts kubectl config current-context # display the current-context kubectl config use-context my-cluster-name # set the default context to my-cluster-name
- Get all deployments:
kubectl get deployments --all-namespaces=true
- Get all pods:
kubectl get pods -A
- Follow the link above and this link for a full list of commands. Only way to learn is to practice!
-
To Do: Use kubelogin for authentication without the
--admin
credentials. See this post for details. -
List IAM roles at Resource level:
az role assignment list --scope /subscriptions/<subscriptionID>/resourceGroups/<resourcegroupname>/providers/Microsoft.ContainerRegistry/registries/<acrname> -o table
-
Attach Azure Container Registry (ACR) to AKS:
az aks update -n <myAKSCluster> -g <myResourceGroup> --attach-acr <acr-resource-id>
-
Service principle used for AKS:
az aks show --resource-group <myResourceGroup> --name <myAKSCluster> --query servicePrincipalProfile.clientId -o tsv
-
If in a test environment, stop the cluster after testing to save resources:
az aks stop --resource-group my-cluster-rg --name my-cluster
-
Full List of AKS commands for reference.
Comments