A practical guide to Kubernetes administration on the three most common managed services: AKS (Azure), GKE (Google Cloud) and EKS (AWS). The kubectl commands are the same on all three; what changes is how you connect, scale the nodes and upgrade the cluster, and here you have them side by side. All the commands are also in the README.md on the left.
What you’ll learn
- Connecting to an AKS, GKE or EKS cluster from Windows and switching between clusters without mistakes.
- Checking the status of nodes, pods and services, and diagnosing a failing pod.
- Deploying, scaling and rolling back a deployment with
kubectl. - Scaling nodes, carrying out maintenance on a node and upgrading the Kubernetes version on each cloud.
Prerequisites
- An AKS, GKE or EKS cluster, and permissions to administer it on that cloud.
- Windows with PowerShell and
winget(thekubectlcommands are the same on macOS and Linux). - For EKS, eksctl (see its official installation guide).
- Knowledge of the basic Kubernetes objects: pod, deployment, service and namespace.
Step by step
1. Install the tools
kubectl is the common tool; each cloud adds its own CLI to create credentials and manage the infrastructure:
# kubectl (common to all three clouds)
winget install -e --id Kubernetes.kubectl
# Your cloud's CLI
winget install -e --id Microsoft.AzureCLI # Azure (AKS)
winget install -e --id Google.CloudSDK # Google Cloud (GKE)
winget install -e --id Amazon.AWSCLI # AWS (EKS)
Close and reopen PowerShell, and check with kubectl version --client.
2. Connect to the cluster
Each CLI downloads the cluster’s credentials and adds them to your ~/.kube/config file:
# AKS
az login
az aks get-credentials --resource-group rg-production --name aks-production
# GKE (needs the authentication plugin)
gcloud auth login
gcloud components install gke-gcloud-auth-plugin
gcloud container clusters get-credentials gke-production --region europe-southwest1 --project my-project
# EKS
aws configure
aws eks update-kubeconfig --region eu-south-2 --name eks-production
3. Switch between clusters without mistakes
Each cluster is a context. Before making any change, check which one you are in: a command in the wrong context can affect production.
kubectl config get-contexts # all configured clusters
kubectl config current-context # which one you are in
kubectl config use-context aks-production
kubectl config set-context --current --namespace=orders # default namespace
4. Check the cluster’s status
kubectl get nodes -o wide # nodes, version, IP and status
kubectl get pods -A # all pods in all namespaces
kubectl get pods -n orders -o wide # pods in a namespace and which node they are on
kubectl get deploy,svc,ingress -n orders
kubectl top nodes # CPU and memory usage (needs metrics-server)
kubectl top pods -n orders
5. Diagnose a failing pod
The usual order: describe to see the events and the reason, logs (with --previous if it restarted) to see the application error and, if needed, open a shell in the container:
kubectl describe pod tasks-api-7c9d8 -n orders # status, events and reason for failure
kubectl logs tasks-api-7c9d8 -n orders # container logs
kubectl logs -f deploy/tasks-api -n orders # follow the logs live
kubectl logs tasks-api-7c9d8 -n orders --previous # logs of the previous container (after a restart)
kubectl get events -n orders --sort-by=.lastTimestamp
kubectl exec -it tasks-api-7c9d8 -n orders -- sh # open a shell in the container
kubectl port-forward svc/tasks-api 8080:80 -n orders # test an internal service at localhost:8080
6. Deploy, scale and roll back changes
A basic Deployment, with resources and health checks, which is what gives the most stability:
apiVersion: apps/v1
kind: Deployment
metadata:
name: tasks-api
namespace: orders
spec:
replicas: 2
selector:
matchLabels:
app: tasks-api
template:
metadata:
labels:
app: tasks-api
spec:
containers:
- name: api
image: ghcr.io/company/tasks-api:1.4.0
ports:
- containerPort: 80
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
memory: 256Mi
readinessProbe:
httpGet:
path: /
port: 80
livenessProbe:
httpGet:
path: /
port: 80
And the everyday commands:
kubectl apply -f deployment.yaml # create or update from a file
kubectl set image deployment/tasks-api api=ghcr.io/company/tasks-api:1.4.0 -n orders
kubectl rollout status deployment/tasks-api -n orders # wait for it to finish
kubectl rollout history deployment/tasks-api -n orders
kubectl rollout undo deployment/tasks-api -n orders # go back to the previous version
kubectl rollout restart deployment/tasks-api -n orders # restart all pods in an orderly way
kubectl scale deployment/tasks-api --replicas=4 -n orders
7. Scale the nodes
More pod replicas need more nodes. Each cloud scales its node groups with its own CLI (or with the cluster autoscaler, if you enable it):
# AKS
az aks nodepool scale --resource-group rg-production --cluster-name aks-production --name nodepool1 --node-count 4
# GKE
gcloud container clusters resize gke-production --node-pool default-pool --num-nodes 4 --region europe-southwest1
# EKS (with eksctl)
eksctl scale nodegroup --cluster eks-production --name ng-general --nodes 4
8. Carry out maintenance on a node
Before restarting or replacing a node, drain it: cordon stops it from receiving new pods and drain moves the ones it has to other nodes while respecting the PodDisruptionBudgets:
kubectl cordon aks-nodepool1-12345678-vmss000002 # do not schedule new pods on the node
kubectl drain aks-nodepool1-12345678-vmss000002 --ignore-daemonsets --delete-emptydir-data
# ... node maintenance ...
kubectl uncordon aks-nodepool1-12345678-vmss000002 # receives pods again
9. Upgrade the Kubernetes version
All three clouds upgrade the control plane first and then the nodes, one minor version at a time. Check the release notes beforehand in case an API you use is being removed:
# AKS: available versions and upgrade
az aks get-upgrades --resource-group rg-production --name aks-production --output table
az aks upgrade --resource-group rg-production --name aks-production --kubernetes-version 1.31.2
# GKE: first the control plane, then the node pools
gcloud container clusters upgrade gke-production --master --cluster-version 1.31 --region europe-southwest1
gcloud container clusters upgrade gke-production --node-pool default-pool --region europe-southwest1
# EKS: control plane and then the node groups
eksctl upgrade cluster --name eks-production --approve
eksctl upgrade nodegroup --cluster eks-production --name ng-general
10. Keep the equivalences between clouds to hand
| Task | AKS (Azure) | GKE (Google Cloud) | EKS (AWS) |
|---|---|---|---|
| Connect | az aks get-credentials | gcloud container clusters get-credentials | aws eks update-kubeconfig |
| Scale nodes | az aks nodepool scale | gcloud container clusters resize | eksctl scale nodegroup |
| Upgrade version | az aks upgrade | gcloud container clusters upgrade | eksctl upgrade cluster |
| Image registry | Azure Container Registry | Artifact Registry | Amazon ECR |
| User authentication | Microsoft Entra ID | Google Cloud IAM | IAM and access entries |
Common errors
CrashLoopBackOff
The container starts and crashes over and over again. Look at kubectl logs <pod> --previous: it is usually an application error, a missing environment variable or secret, or a connection that cannot be established.
ImagePullBackOff or ErrImagePull
It cannot download the image: the name or tag is misspelt, or the cluster does not have permission for the registry. On AKS, az aks update --resource-group rg --name aks --attach-acr my-registry; on the others, an imagePullSecrets or the node’s IAM permissions.
Pod in Pending
No node can host it. kubectl describe pod tells you why: not enough CPU or memory, a nodeSelector or toleration that does not match, or a volume that cannot be mounted. Scale the nodes or adjust the requests.
OOMKilled
The container exceeded its memory limit and Kubernetes killed it. Increase limits.memory or review the application’s usage with kubectl top pods.
“You must be logged in to the server (Unauthorized)”
The credentials have expired or your user does not have access. Run the credentials command from step 2 again; on EKS, your IAM user or role must have an access entry in the cluster.
“gke-gcloud-auth-plugin not found”
Since version 1.26, kubectl needs Google’s authentication plugin. Install it with gcloud components install gke-gcloud-auth-plugin and request the credentials again.
“drain” keeps waiting
A PodDisruptionBudget does not allow more pods of that application to be evicted. Check with kubectl get pdb -A and increase the replicas before draining the node.
Next steps
- Automate deployments with a pipeline (see the CI/CD with GitHub Actions guide).
- Enable autoscaling for pods (Horizontal Pod Autoscaler) and nodes (cluster autoscaler).
- Describe the infrastructure with Terraform to create and update clusters reproducibly.
- Centralise logs and metrics (for example, Prometheus and Grafana) and define alerts.
- Manage deployments with GitOps (Argo CD or Flux).