A one-stop guide covering Pods → ConfigMaps/Secrets → Storage → Networking → Namespaces → RBAC → Scheduling
1️⃣ Basic Commands
Command | Explanation |
kubectl version | Check client & server Kubernetes version |
kubectl cluster-info | Show cluster master & services info |
kubectl get nodes | List all nodes in cluster |
kubectl get pods -A | List all pods across namespaces |
kubectl describe pod <pod-name> | Show detailed info about a pod |
2️⃣ Pods & Deployments
Command | Explanation |
kubectl run nginx --image=nginx | Create a pod with Nginx image |
kubectl create deployment myapp --image=nginx | Create a Deployment |
kubectl scale deployment myapp --replicas=3 | Scale deployment to 3 pods |
kubectl rollout status deployment/myapp | Check rollout status |
kubectl rollout undo deployment/myapp | Rollback last deployment |
3️⃣ ConfigMaps & Secrets
Command | Explanation | |
kubectl create configmap app-config --from-literal=APP_MODE=prod | Create ConfigMap | |
kubectl get configmap app-config -o yaml | View ConfigMap | |
kubectl create secret generic db-secret --from-literal=USER=admin --from-literal=PASS=1234 | Create Secret | |
kubectl get secret db-secret -o yaml | View Secret (base64 encoded) | |
`echo "YWRtaW4=" | base64 -d` | Decode Secret value |
4️⃣ Storage (PV & PVC)
Command | Explanation |
kubectl get pv | List Persistent Volumes |
kubectl get pvc | List Persistent Volume Claims |
kubectl describe pvc myclaim | Show PVC details |
kubectl delete pvc myclaim | Delete PVC |
kubectl apply -f pvc.yaml | Apply PVC manifest |
5️⃣ Networking (Services & Ingress)
Command | Explanation |
kubectl expose deployment myapp --port=80 --type=NodePort | Expose Deployment as NodePort |
kubectl get svc | List all services |
kubectl describe svc myapp | Show service details |
kubectl apply -f ingress.yaml | Apply Ingress rule |
kubectl get ingress | List ingress resources |
6️⃣ Namespaces
Command | Explanation |
kubectl get ns | List all namespaces |
kubectl create ns dev | Create new namespace |
kubectl config set-context --current --namespace=dev | Switch default namespace |
kubectl get pods -n kube-system | List pods in kube-system namespace |
7️⃣ RBAC (Role-Based Access Control)
Command | Explanation |
kubectl create role pod-reader --verb=get --verb=list --resource=pods -n dev | Create role to read pods |
kubectl create rolebinding read-pods --role=pod-reader --user=alice -n dev | Bind role to user |
kubectl get roles -n dev | List roles |
kubectl describe rolebinding read-pods -n dev | Show rolebinding details |
8️⃣ Scheduling (Affinity, Taints & Tolerations)
Command | Explanation |
kubectl describe node <node-name> | View node labels & taints |
kubectl taint nodes <node> key=value:NoSchedule | Add taint to node |
kubectl taint nodes <node> key=value:NoSchedule- | Remove taint |
kubectl label nodes <node> disktype=ssd | Add label to node |
kubectl get pods --field-selector spec.nodeName=<node> | Check pods scheduled on node |
9️⃣ Monitoring & Debugging
Command | Explanation |
kubectl logs <pod> | View logs of a pod |
kubectl logs -f <pod> | Stream logs |
kubectl exec -it <pod> -- /bin/sh | Enter pod shell |
kubectl top pods | Show resource usage (requires metrics-server) |
kubectl get events | Show cluster events |
🔟 YAML Quick Reference
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: myapp
image: nginx
ports:
- containerPort: 80
Subscribe to my newsletter
Read articles from DevOpsLaunchpad directly inside your inbox. Subscribe to the newsletter, and don't miss out.