Kubernetes Administration — Level by Level›Level 1 · Cheat sheet & self-check

Level 1 — Foundations · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

01 · Set up your practice lab

Cluster lifecycle (kind)

kind create cluster --name lab --config kind-lab.yamlCreate the 3-node practice cluster
kind get clustersList your kind clusters
kind delete cluster --name labDelete it (start fresh any time)

First kubectl commands

kubectl versionClient and server versions
kubectl cluster-infoWhere the API server lives
kubectl get nodes -o wideNodes, their IPs, OS and runtime
kubectl config get-contextsWhich clusters kubectl knows about
kubectl config use-context kind-labPoint kubectl at the lab cluster

Make life easier

alias k=kubectlShorter commands
source <(kubectl completion bash)Tab completion in bash
kubectl explain pod.specBuilt-in docs for any field

02 · Architecture & the control plane

See the control plane

kubectl get pods -n kube-system -o wideControl-plane and system pods, and which node they run on
kubectl get --raw='/readyz?verbose'API server health checks, one line each
kubectl get events -A --sort-by=.lastTimestampRecent cluster events, newest last
kubectl api-resourcesEvery object type the API server knows

Look inside a node (kind)

docker exec -it lab-control-plane bashOpen a shell 'on' the node
ls /etc/kubernetes/manifestsStatic pod manifests for the control plane
crictl psContainers the kubelet is running
journalctl -u kubelet -fFollow kubelet logs

03 · Pods, Deployments & workload types

Pods

kubectl apply -f pod.yamlCreate or update from a file
kubectl get pods -o widePods with IP and node
kubectl describe pod <name>Details and events: first stop when debugging
kubectl logs <pod> [-c container] [--previous]Logs; --previous shows the crashed run
kubectl exec -it <pod> -- shShell inside the container
kubectl run tmp --rm -it --image=busybox:1.36 -- shThrowaway debug pod

Deployments

kubectl create deployment web --image=nginx:1.27Quick Deployment
kubectl scale deployment web --replicas=5Scale out or in
kubectl set image deployment/web nginx=nginx:1.27-alpineStart a rolling update
kubectl rollout status deployment/webWait for the rollout to finish
kubectl rollout history deployment/webPast revisions
kubectl rollout undo deployment/webRoll back to the previous revision
kubectl rollout restart deployment/webRestart all pods, one by one

Generate YAML instead of typing it

kubectl create deployment web --image=nginx:1.27 --dry-run=client -o yaml > web.yamlA starter manifest

04 · Services, DNS & basic networking

Services

kubectl expose deployment web --port=80Create a ClusterIP Service for a Deployment
kubectl get svc,endpointslices -l app=webService and the pod IPs behind it
kubectl describe svc webSelector, ports and endpoints in one view
kubectl port-forward svc/web 8080:80Reach a Service from your laptop

DNS & connectivity tests

kubectl run tmp --rm -it --image=busybox:1.36 --restart=Never -- shDebug shell inside the cluster
nslookup webResolve a Service name (inside the debug pod)
wget -qO- http://webCall the Service (inside the debug pod)
kubectl get pods -n kube-system -l k8s-app=kube-dnsAre the CoreDNS pods healthy?

DNS names

webSame namespace
web.shopService 'web' in namespace 'shop'
web.shop.svc.cluster.localFully qualified name

05 · Ingress: getting traffic in

Install & inspect

kubectl apply -f https://kind.sigs.k8s.io/examples/ingress/deploy-ingress-nginx.yamlingress-nginx for kind (cluster needs port mappings + ingress-ready label)
helm upgrade --install ingress-nginx ingress-nginx --repo https://kubernetes.github.io/ingress-nginx -n ingress-nginx --create-namespaceingress-nginx with Helm (other clusters)
kubectl get svc -n ingress-nginx ingress-nginx-controllerThe controller's Service: EXTERNAL-IP or NodePorts
kubectl get ingressclassWhich controllers exist (e.g. nginx)

Rules & debugging

kubectl get ingress -A / kubectl describe ingress shopRules, backends, address
kubectl get endpointslices -l kubernetes.io/service-name=shopPod IPs the controller will use
kubectl logs -n ingress-nginx deploy/ingress-nginx-controllerAccess log: status, upstream, latency
curl -H 'Host: shop.example.com' http://<ingress-ip>/Test a host rule without DNS

06 · Configuration & Secrets

ConfigMaps

kubectl create configmap app-config --from-literal=APP_COLOR=blueFrom key=value pairs
kubectl create configmap nginx-conf --from-file=default.confFrom a file (key = file name)
kubectl get configmap app-config -o yamlSee the contents

Secrets

kubectl create secret generic db-cred --from-literal=username=app --from-literal=password='S3cr3t!'Generic secret
kubectl create secret tls web-tls --cert=tls.crt --key=tls.keyTLS certificate + key
kubectl get secret db-cred -o jsonpath='{.data.password}' | base64 -dDecode one value (anyone with read access can)

Apply changes

kubectl rollout restart deployment/appPick up changed env vars
kubectl exec deploy/app -- env | grep APP_Check what a pod actually sees

07 · Storage basics

Inspect storage

kubectl get storageclassAvailable storage types (default marked)
kubectl get pvc,pvClaims and the volumes bound to them
kubectl describe pvc <name>Why a claim is Pending (events)

Access modes

ReadWriteOnce (RWO)Read-write by pods on ONE node
ReadOnlyMany (ROX)Read-only by many nodes
ReadWriteMany (RWX)Read-write by many nodes (NFS, CephFS, EFS)
ReadWriteOncePod (RWOP)Read-write by exactly one pod

Volume types

emptyDirScratch space; lives and dies with the pod
hostPathA folder on the node; avoid for apps
persistentVolumeClaimDurable storage that outlives pods
configMap / secretConfig files (lesson 05)

08 · Checkpoint: deploy a 3-tier app

Namespaces

kubectl create namespace shopCreate a namespace
kubectl config set-context --current --namespace=shopMake it your default for this context
kubectl get all -n shopDeployments, pods, Services in one list
kubectl delete namespace shopDelete it and everything inside

Everyday debugging

kubectl get pods -n shop -wWatch pods change state
kubectl -n shop describe pod <name>Events: scheduling, pulls, probes, mounts
kubectl -n shop logs deploy/webLogs from one pod of a Deployment
kubectl -n shop get endpointslicesWhich pods each Service really points to
kubectl -n shop exec deploy/postgres -- psql -U shop -d shop -c 'select 1'Run a command in a pod