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 Objective | kubectl Command | Exam Speed Note |
|---|---|---|
Generate Pod YAML Skeleton | kubectl run web --image=nginx --port=80 --dry-run=client -o yaml > pod.yaml | Zero YAML typos under 2-hour CKA clock |
Generate Deployment w/ 3 Replicas | kubectl create deployment api --image=nginx:1.27 --replicas=3 --dry-run=client -o yaml > deploy.yaml | Edit strategy/env cleanly before applying |
Expose Deployment as ClusterIP/NodePort | kubectl expose deployment api --port=80 --target-port=8080 --type=NodePort | Matches deployment labels automatically |
Create ConfigMap from Env Key/Value | kubectl create configmap app-cfg --from-literal=ENV=prod --from-literal=LOG=info | Verify with kubectl describe cm app-cfg |
Create Secret TLS Certificate | kubectl create secret tls web-tls --cert=tls.crt --key=tls.key | Bind inside Ingress spec.tls block |
Cluster Upgrade, etcd Backup & Triage Commands
High-weight CKA Domain commands covering etcdctl snapshot, node drainage, and RBAC validation.
| Operation | Command Pattern | Critical Verification |
|---|---|---|
Switch Cluster Context Safely | kubectl config use-context k8s-prod | Always run at start of EVERY CKA question |
Verify RBAC User Permission | kubectl auth can-i create deployments --as=dev-user -n payments | Returns exact yes/no authorization answer |
Safely Drain Worker Node for Maintenance | kubectl drain node-02 --ignore-daemonsets --delete-emptydir-data | Always follow with kubectl uncordon post-upgrade |
Snapshot etcd Control Plane State | ETCDCTL_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.key | Confirm with etcdctl snapshot status /opt/etcd-backup.db |
Inspect Failing Pod & InitContainer Logs | kubectl logs my-pod -c app --previous && kubectl describe pod my-pod | Reveals CrashLoopBackOff exit codes & OOMKilled |
Sort Nodes / Pods by Resource Usage | kubectl top nodes --sort-by=cpu && kubectl top pods -A --sort-by=memory | Requires 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.