-
Get Running Pods:
kubectl get pods --field-selector=status.phase=Running -n [namespace]
-
Get Failed or Errored Pods:
kubectl get pods --field-selector=status.phase=Failed -n [namespace]
-
Describe Deployment:
kubectl describe deployment my-deployment -n [namespace]
-
Tail Logs from Container in Pod:
kubectl logs -f pod my-pod -c container-name -n [namespace]
-
Access or Execute Command from Container:
kubectl exec -it my-pod -n [namespace] --container container-name -- /bin/bash
-
Edit ConfigMap:
kubectl edit configmap my-configmap -n [namespace]
-
Rollout Status:
kubectl rollout status deployment my-deployment -n [namespace]
-
Scale Deployment:
kubectl scale deployment my-deployment --replicas=3 -n [namespace]
-
Select Pods by Label:
kubectl get pods -l app=my-app -n [namespace]
-
Port Forward Pod so it is accessible from localhost:
kubectl port-forward -n [namespace] pod my-pod 8080:80
-
Get Resource Usage from Specific Pod:
kubectl top pod my-pod -n [namespace]
-
Apply Remote Manifest:
kubectl apply -f https://url-to-resource.yaml -n [namespace]
-
Explain Field:
kubectl explain pod.spec.containers
-
List Events Sorted by Timestamp:
kubectl get events --sort-by=.metadata.creationTimestamp
-
Annotate Deployment:
kubectl annotate deployment my-deployment my-label=updated -n [namespace]
-
Rollback Deployment:
kubectl rollout undo deployment my-deployment -n [namespace]
-
PVCs by Capacity:
kubectl get pvc --sort-by=.spec.capacity.storage
-
View Deployment Rollout History:
kubectl rollout history deployment my-deployment -n [namespace]
-
Label a Pod:
kubectl label pod my-pod my-label=updated -n [namespace]
-
Diff Manifests:
kubectl diff -f https://url-to-new-resource.yaml
-
Node Details:
kubectl describe node my-node
-
Get Services with Details:
kubectl get services --all-namespaces -o wide
-
Pause Rollout:
kubectl rollout pause deployment my-deployment -n [namespace]
-
Describe Ingress:
kubectl describe ingress my-ingress -n [namespace]
-
Force Delete Pod:
kubectl delete pod my-pod --grace-period=0 --force -n [namespace]
-
Decode Secret (Kubernetes Secrets are too easy to break):
kubectl get secret my-secret -o jsonpath='{.data.username}' | base64 -d
-
Resume Rollout:
kubectl rollout resume deployment my-deployment -n [namespace]
-
Export HPA:
kubectl get hpa my-hpa -n [namespace] -o yaml > hpa.yaml
-
Taint a Node:
kubectl taint node my-node key=value:NoSchedule
-
Get Completed Jobs:
kubectl get jobs -n [namespace] --field-selector=status.successful=1
-
Drain a Node:
kubectl drain my-node --ignore-daemonsets
-
Service IPs:
kubectl get endpoints my-service -n [namespace] -o jsonpath='{.subsets[0].addresses[*].ip}'
-
Rollback by Revision:
kubectl rollout history deployment my-deployment --revision=3
-
Explain Replica Count:
kubectl explain deployment.spec.replicas
-
Replace Resource:
kubectl replace -f https://url-to-updated-resource.yaml
-
Restart Deployment:
kubectl rollout restart deployment my-deployment
-
Uncordon Node:
kubectl uncordon my-node
-
Pending CSRs:
kubectl get csr --sort-by=.metadata.creationTimestamp
-
Rollback with Revision:
kubectl rollout undo deployment my-deployment --to-revision=2
-
Cordon Node:
kubectl cordon my-node
-
CRD List:
kubectl api-resources | grep CustomResourceDefinition
-
DaemonSet Status:
kubectl rollout status daemonset/my-daemonset
-
Ingress Hostname:
kubectl get ingress my-ingress -o jsonpath='{.spec.rules[0].host}'
-
Debug Pod:
kubectl run -it --rm --restart=Never debug-pod --image=busybox -- sh
-
Label Value:
kubectl get rs my-replicaset -o jsonpath='{.metadata.labels.app}'
-
Create Secret:
kubectl create secret generic my-secret --from-literal=username=admin --from-literal=password=pass
-
Rollback DaemonSet:
kubectl rollout undo daemonset/my-daemonset
-
Namespace Deployments:
kubectl get deploy -n my-namespace
-
ConfigMap Data:
kubectl get cm my-configmap -o jsonpath='{.data.key}'
-
DaemonSet History:
kubectl rollout history daemonset/my-daemonset
-
Service Ports:
kubectl explain svc.spec.ports
-
Notifications
You must be signed in to change notification settings - Fork 0
OLeonardoRodrigues/cheatsheet-kubectl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Kubectl Cheatsheet (WIP)