This a comprehensive list of kubectl commands you'll likely use during the CKA exam, categorized by function:
kubectl cluster-info
Shows the master and service endpoints.
Kubernetes control plane is running at https://kubernetes.docker.internal:6443
CoreDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
kubectl api-resources
Lists all API resources available in the cluster.
NAME SHORTNAMES APIVERSION NAMESPACED KIND
bindings v1 true Binding
componentstatuses cs v1 false ComponentStatus
configmaps cm v1 true ConfigMap
...
kubectl get componentstatuses
Check health of control plane components.
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health":"true"}
kubectl get nodes
Shows all nodes in the cluster.
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 5d20h v1.26.3
kubectl describe node <node-name>
Shows detailed information about a specific node.
Name: minikube
Roles: control-plane
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/arch=amd64
...
kubectl get pods [-n namespace] [-o wide]
Lists all pods in the default or specified namespace.
NAME READY STATUS RESTARTS AGE
nginx-deploy-6c9f56c8-7pvzl 1/1 Running 0 15m
kubectl run nginx --image=nginx
Creates a pod named nginx using the nginx image.
pod/nginx created
kubectl describe pod <pod-name> [-n namespace]
Shows detailed information about a specific pod.
Name: nginx
Namespace: default
Priority: 0
Node: minikube/192.168.49.2
Start Time: Wed, Mar 26, 2025 10:15:32 -0400
...
kubectl edit pod <pod-name> [-n namespace]
Opens the pod manifest in an editor to make changes.
kubectl delete pod <pod-name> [-n namespace]
Deletes a pod.
pod "nginx" deleted
kubectl exec -it <pod-name> [-n namespace] -- <command>
Runs a command inside a pod container.
kubectl exec -it nginx -- /bin/bash
root@nginx:/#
kubectl logs <pod-name> [-c container-name] [-n namespace] [--previous]
Shows logs from a pod container.
10.244.0.1 - - [26/Mar/2025:14:28:43 +0000] "GET / HTTP/1.1" 200 615 "-" "Mozilla/5.0" "-"
kubectl create deployment nginx --image=nginx --replicas=3
Creates a deployment with specified replicas.
deployment.apps/nginx created
kubectl get deployments [-n namespace]
Lists all deployments.
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 3/3 3 3 45s
kubectl scale deployment <deployment-name> --replicas=<count>
Changes the number of replicas.
deployment.apps/nginx scaled
kubectl rollout status deployment/<deployment-name>
Checks the rollout status of a deployment.
deployment "nginx" successfully rolled out
kubectl rollout undo deployment/<deployment-name> [--to-revision=<number>]
Rolls back to a previous deployment version.
deployment.apps/nginx rolled back
kubectl get services [-n namespace]
Lists all services.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5d20h
nginx NodePort 10.106.145.116 <none> 80:30080/TCP 2m
kubectl expose deployment <deployment-name> --port=<port> --type=NodePort
Creates a service for a deployment.
service/nginx exposed
kubectl create configmap <name> --from-literal=key1=value1 --from-literal=key2=value2
Creates a ConfigMap from literal values.
configmap/app-config created
kubectl create configmap <name> --from-file=<path-to-file>
Creates a ConfigMap from a file.
configmap/app-config created
kubectl get configmaps [-n namespace]
Lists all ConfigMaps.
NAME DATA AGE
app-config 2 30s
kube-root-ca.crt 1 5d20h
kubectl create secret generic <name> --from-literal=key1=value1
Creates a Secret from literal values.
secret/db-creds created
kubectl get secrets [-n namespace]
Lists all Secrets.
NAME TYPE DATA AGE
db-creds Opaque 1 25s
default-token-abcde kubernetes.io/service-account-token 3 5d20h
kubectl get namespaces
Lists all namespaces.
NAME STATUS AGE
default Active 5d20h
kube-node-lease Active 5d20h
kube-public Active 5d20h
kube-system Active 5d20h
kubectl create namespace <name>
Creates a new namespace.
namespace/dev created
kubectl get roles [-n namespace]
Lists all roles in a namespace.
NAME CREATED AT
pod-reader 2025-03-26T14:32:10Z
kubectl get clusterroles
Lists all cluster roles.
NAME CREATED AT
admin 2025-03-20T15:12:47Z
cluster-admin 2025-03-20T15:12:47Z
...
kubectl get rolebindings [-n namespace]
Lists all role bindings.
NAME ROLE AGE
read-pods Role/pod-reader 5m
kubectl get resourcequota [-n namespace]
Lists resource quotas.
NAME AGE REQUEST LIMIT
mem-cpu-demo 10s requests.cpu: 0/1, requests.memory: 0/1Gi limits.cpu: 0/2, limits.memory: 0/2Gi
kubectl get limitrange [-n namespace]
Lists limit ranges.
NAME CREATED AT
mem-limit 2025-03-26T14:40:10Z
kubectl get pv
Lists all persistent volumes.
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv001 1Gi RWO Retain Available standard 5m
kubectl get pvc [-n namespace]
Lists all persistent volume claims.
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-pvc Bound pv001 1Gi RWO standard 2m
kubectl get sc
Lists all storage classes.
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
standard (default) k8s.io/minikube-hostpath Delete Immediate false 5d20h
kubectl config view
Shows the current kubeconfig.
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://kubernetes.docker.internal:6443
name: docker-desktop
...
kubectl config use-context <context-name>
Switches to a different context.
Switched to context "docker-desktop".
kubectl config get-contexts
Lists all available contexts.
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* docker-desktop docker-desktop docker-desktop
minikube minikube minikube default
kubectl get networkpolicies [-n namespace]
Lists all network policies.
NAME POD-SELECTOR AGE
allow-frontend app=frontend 45s
kubectl run -it --rm dns-test --image=busybox:1.28 -- nslookup kubernetes.default
Tests DNS resolution within the cluster.
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: kubernetes.default
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local
kubectl run -it --rm curl-test --image=curlimages/curl -- curl <service-name>.<namespace>.svc.cluster.local
Tests connectivity to a service.
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
kubectl run -it --rm debug --image=busybox -- sh
Creates a temporary pod for debugging.
/ #
kubectl get pod <pod-name> -o yaml
Gets pod configuration in YAML format.
kubectl get pod <pod-name> -o json
Gets pod configuration in JSON format.
kubectl get pods -o custom-columns=NAME:.metadata.name,STATUS:.status.phase
Displays specific fields in columns.
NAME STATUS
nginx-deploy-6c9f56c8-7pvzl Running
kubectl apply -f <file-name.yaml>
Creates or updates resources defined in a YAML file.
deployment.apps/nginx created
service/nginx created