You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?
Kubernetes cheat sheet
The commands you learned, in one place.
Look around
kubectl get podsShow my trays and how they are doing.kubectl get pods -o wideAlso show each pod's IP and node.kubectl get deployment shop -o yamlShow the whole object, spec and status.kubectl get pods -l app=shopOnly pods with the label app=shop.kubectl get pods -APods in every namespace.kubectl describe pod trayWhy is this tray not ready? Read the Events.kubectl explain deployment.spec.replicasWhat does replicas mean?kubectl wait --for=condition=Ready pod/tray --timeout=60sWait until the tray is ready.kubectl versionWhich Kubernetes am I using?
Change the cluster
kubectl apply -f shop.yamlPut up the order written in shop.yaml.Risk: Carefulkubectl apply -f shop.yaml --dry-run=serverAsk the cluster to check it, change nothing.Risk: Carefulkubectl diff -f shop.yamlSee what apply would change first.Risk: Carefulkubectl create deployment shop --image=nginx:1.29-alpine --replicas=3A standing order: always 3 trays of nginx.Risk: Carefulkubectl create deployment shop --image=nginx:1.29-alpine --dry-run=client -o yamlPrint the YAML, create nothing.Risk: Carefulkubectl create namespace foodMake a new zone called food.Risk: Carefulkubectl delete pod trayTake away one tray.Risk: Can lose workkubectl delete -f shop.yamlRemove what the file made.Risk: Can lose workkubectl scale deployment shop --replicas=5Want 5 now. The manager makes 2 more.Risk: Carefulkubectl expose deployment shop --port=80Give the shop the order number shop.Risk: Carefulkubectl run tray --image=nginx:1.29-alpineOne tray, no manager.Risk: Carefulkubectl label pod tray tier=frontStick a tier=front sticker on the tray.Risk: Carefulkubectl create role deployer --verb=get,list,patch --resource=deploymentsA card for reading and patching Deployments.Risk: Carefulkubectl create clusterrole node-reader --verb=get,list --resource=nodesA card for every zone, and things with no zone.Risk: Carefulkubectl create rolebinding ci-bot-deployer --role=deployer --serviceaccount=default:ci-botGive the CI bot the deployer card here.Risk: Carefulkubectl create serviceaccount ci-botFirst, make the bot's badge.Risk: Carefulkubectl autoscale deployment shop --cpu=50% --min=3 --max=103 to 10 trays, aiming at half-busy CPU.Risk: Carefulkubectl create configmap settings --from-literal=GREETING=HaiA note that says GREETING is Hai.kubectl create configmap settings --from-literal=GREETING=Hai --dry-run=client -o yamlPrint the YAML, create nothing.kubectl create secret generic till --from-literal=PASSWORD=practice-onlyA Secret called till with one key, PASSWORD.Risk: Carefulkubectl get secret till -o jsonpath={.data.PASSWORD}Show the base64 text. Anyone who can read it can decode it.Risk: Carefulkubectl set resources deployment big --requests=cpu=100mBook a tenth of a CPU, not 64.Risk: Carefulkubectl set resources deployment shop --limits=memory=128MiCap each tray at 128Mi of memory.Risk: Carefulkubectl create job tally-now --from=cronjob/nightlyCount the plates now, with tonight's recipe.Risk: Careful
Rollouts
kubectl set image deployment/shop web=nginx:1.30-alpineSwap the trays to version 1.30, a few at a time.Risk: Carefulkubectl rollout status deployment/shopTell me when all new trays are ready.kubectl rollout history deployment/shopWhich versions has the shop had?kubectl rollout undo deployment/shopBack to the last good version.Risk: Carefulkubectl rollout restart deployment/shopFresh trays, same recipe.Risk: Careful
Debug
kubectl logs deployment/oops --previousWhat did it say before it crashed?kubectl exec client -- wget -qO- http://shopFrom the client pod, ask the shop for its page.Risk: Carefulkubectl port-forward svc/shop 8080:80localhost:8080 now reaches a shop pod.kubectl debug -it tray --image=busybox:1.37 --target=webBring a toolbox into the tray.Risk: Carefulkubectl top podsWho is using the most?kubectl eventsWhat happened in this zone lately?kubectl get events --field-selector reason=FailedSchedulingOnly the notes about trays with no stall.
Where am I?
kubectl config get-contextsWhich cluster am I talking to?kubectl config use-context kind-devBack to my practice cluster.Risk: Carefulkubectl config set-context --current --namespace=foodFrom now on, work in the food zone.Risk: Carefulkubectl auth can-i delete pods --as=system:serviceaccount:default:ci-botMay the CI bot delete pods?kubectl auth whoamiWho am I in this cluster?kubectl config current-contextWhere am I? kind-dev, good.kubectl cluster-infoSay hello to the manager's office.kind create cluster --name dev --config kind-dev.yamlOpen the food court dev with 3 stalls. kubectl now points at kind-dev.kind delete cluster --name devClose the practice food court for the night.Risk: Can lose work
Nodes
kubectl cordon dev-workerNo new trays at this stall.Risk: Carefulkubectl uncordon dev-workerThe stall takes trays again.Risk: Carefulkubectl drain dev-worker --ignore-daemonsetsMove every tray off this stall.Risk: Can lose workkubectl taint nodes dev-worker2 gpu=yes:NoScheduleOnly GPU pods at this stall.Risk: Careful
Packages and overlays
kubectl kustomize overlays/prodShow the prod version before applying it.helm template shop ./kedai --set replicaCount=3Show the YAML for 3 replicas.helm install shop ./kedaiInstall the kedai chart as release shop.Risk: Careful