Kubernetes CKA kubectl Commands Cheat Sheet (Imperative Speed & etcd)

One-click copyable kubectl imperative YAML generators, context switching, node drain/upgrade workflows, RBAC `auth can-i`, and `etcdctl` snapshot backup commands.

Exam Code: CKA · CNCF | Track: Cloud & DevOps | Recommended Course: Certified Kubernetes Administrator (CKA) Bootcamp

Fast Imperative YAML Generators (Exam Speed)

Generate clean YAML skeletons in 2 seconds on CKA instead of hand-writing indentation from scratch.

Task Objectivekubectl CommandExam Speed Note
Generate Pod YAML Skeletonkubectl run web --image=nginx --port=80 --dry-run=client -o yaml > pod.yamlZero YAML typos under 2-hour CKA clock
Generate Deployment w/ 3 Replicaskubectl create deployment api --image=nginx:1.27 --replicas=3 --dry-run=client -o yaml > deploy.yamlEdit strategy/env cleanly before applying
Expose Deployment as ClusterIP/NodePortkubectl expose deployment api --port=80 --target-port=8080 --type=NodePortMatches deployment labels automatically
Create ConfigMap from Env Key/Valuekubectl create configmap app-cfg --from-literal=ENV=prod --from-literal=LOG=infoVerify with kubectl describe cm app-cfg
Create Secret TLS Certificatekubectl create secret tls web-tls --cert=tls.crt --key=tls.keyBind inside Ingress spec.tls block

Cluster Upgrade, etcd Backup & Triage Commands

High-weight CKA Domain commands covering etcdctl snapshot, node drainage, and RBAC validation.

OperationCommand PatternCritical Verification
Switch Cluster Context Safelykubectl config use-context k8s-prodAlways run at start of EVERY CKA question
Verify RBAC User Permissionkubectl auth can-i create deployments --as=dev-user -n paymentsReturns exact yes/no authorization answer
Safely Drain Worker Node for Maintenancekubectl drain node-02 --ignore-daemonsets --delete-emptydir-dataAlways follow with kubectl uncordon post-upgrade
Snapshot etcd Control Plane StateETCDCTL_API=3 etcdctl snapshot save /opt/etcd-backup.db --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.keyConfirm with etcdctl snapshot status /opt/etcd-backup.db
Inspect Failing Pod & InitContainer Logskubectl logs my-pod -c app --previous && kubectl describe pod my-podReveals CrashLoopBackOff exit codes & OOMKilled
Sort Nodes / Pods by Resource Usagekubectl top nodes --sort-by=cpu && kubectl top pods -A --sort-by=memoryRequires Metrics Server installed in cluster

Frequently Asked Questions

What single kubectl trick saves the most time on the 2-hour CKA practical exam?

Generating base manifests cleanly with `--dry-run=client -o yaml > file.yaml` instead of typing YAML blocks by hand eliminates indentation errors and saves 20+ minutes across tasks.