CKA · CKAD · Shell set-up, aliases and the kubectl commands you reach for most in CKA and CKAD tasks, grouped by topic.https://gazeek.com

Kubernetes cheat sheet

Gazeek Labs cheat sheet · 3 sections

Opens your browser's print dialog: choose Save as PDF.

Kubernetes shell set-up and commands for CKA and CKAD practice. Generated 2026-11-27.

1Exam-day set-up

Type these in the first minute. Lines marked with a star in the tables below are the same set.

2Aliases and settings

3Commands by topic

Pods

Run a pod:

kubectl run web --image=nginx --port=80

Write the YAML instead of creating it:

kubectl run web --image=nginx --dry-run=client -o yaml > web.yaml

A pod with a command and labels:

kubectl run box --image=busybox --labels=app=box,tier=tools -- sleep 3600

A shell inside a pod:

kubectl exec -it web -- sh

Replace a pod from an edited file:

kubectl replace --force -f web.yaml

Deployments

Create a deployment:

kubectl create deployment api --image=nginx --replicas=3

Scale it:

kubectl scale deployment api --replicas=5

Change the image:

kubectl set image deployment/api nginx=nginx:1.27

Watch the rollout, then roll back:

kubectl rollout status deployment/api
kubectl rollout undo deployment/api

Rollout history:

kubectl rollout history deployment/api

Services

Expose a deployment inside the cluster:

kubectl expose deployment api --port=80 --target-port=8080

Expose on a node port:

kubectl expose deployment api --type=NodePort --port=80

A service for a pod:

kubectl expose pod web --port=80 --name=web-svc

See where a service sends traffic:

kubectl get endpointslices -l kubernetes.io/service-name=api

ConfigMaps and Secrets

ConfigMap from values:

kubectl create configmap app-config --from-literal=MODE=prod --from-literal=LEVEL=info

ConfigMap from a file:

kubectl create configmap nginx-conf --from-file=nginx.conf

Secret from values:

kubectl create secret generic db --from-literal=user=app --from-literal=password=s3cret

Read one secret value:

kubectl get secret db -o jsonpath='{.data.password}' | base64 -d

Jobs and CronJobs

A one-off job:

kubectl create job hello --image=busybox -- echo hello

A cron job every five minutes:

kubectl create cronjob tick --image=busybox --schedule='*/5 * * * *' -- date

Run a cron job now:

kubectl create job tick-now --from=cronjob/tick

RBAC

A service account:

kubectl create serviceaccount app

A role that reads pods:

kubectl create role pod-reader --verb=get,list,watch --resource=pods

Bind it to the service account:

kubectl create rolebinding app-reads --role=pod-reader --serviceaccount=default:app

Check what it may do:

kubectl auth can-i list pods --as=system:serviceaccount:default:app

Networking

Test a service from a throwaway pod:

kubectl run tmp --rm -it --image=busybox --restart=Never -- wget -qO- http://api

DNS lookup inside the cluster:

kubectl run tmp --rm -it --image=busybox --restart=Never -- nslookup api.default.svc.cluster.local

Network policies in a namespace:

kubectl get networkpolicy -n team-a

Forward a port to your node:

kubectl port-forward svc/api 8080:80

Debugging

Why a pod is not running:

kubectl describe pod web

Logs of the previous crash:

kubectl logs web --previous

Logs of one container:

kubectl logs web -c sidecar

Recent events, newest last:

kubectl get events --sort-by=.lastTimestamp

Node health and the kubelet:

kubectl describe node node-1
sudo journalctl -u kubelet --since '10 min ago'

Output formats

Wide, with node and IP:

kubectl get pods -o wide

One field with JSONPath:

kubectl get pod web -o jsonpath='{.status.podIP}'

Your own columns:

kubectl get pods -o custom-columns=NAME:.metadata.name,NODE:.spec.nodeName

Sort by a field:

kubectl get pods --sort-by=.metadata.creationTimestamp

Labels as columns:

kubectl get pods --show-labels

Helm

Add a repository and refresh it:

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

Install a chart with a value:

helm install web bitnami/nginx --set replicaCount=2 -n web --create-namespace

List releases everywhere:

helm list -A

Upgrade, then roll back:

helm upgrade web bitnami/nginx --set replicaCount=3 -n web
helm rollback web 1 -n web