Kubectl Cheatsheet

Quick References

CommandDescription
kubectl create -f demo.yamlCreate a demo service
kubectl get podsLists all pods in the current namespace.
kubectl get pods -n Lists all pods in a specific namespace.
kubectl describe pod Displays detailed information about a specific pod.
kubectl logs Fetches logs from a specific pod.
kubectl logs -c Fetches logs from a specific container within a pod.
kubectl exec -it – /bin/bashOpens an interactive shell session in a running pod.
kubectl apply -f .yamlApplies a configuration change to a resource defined in a YAML file.
kubectl create -f .yamlCreates a resource defined in a YAML file.
kubectl delete -f .yamlDeletes a resource defined in a YAML file.
kubectl get svcLists all services in the current namespace.
kubectl get nodesLists all nodes in the cluster.
kubectl top nodeDisplays resource usage for nodes in the cluster.
kubectl top podDisplays resource usage for pods in the cluster.
kubectl scale deployment –replicas=Scales a deployment to the specified number of replicas.
kubectl rollout status deployment Watches the status of a deployment rollout until it completes.
kubectl edit deployment Edits a deployment’s configuration.
kubectl delete pod Deletes a specific pod.
kubectl config viewDisplays the kubeconfig configuration.
kubectl get configmapsLists all ConfigMaps in the current namespace.
kubectl get secretsLists all secrets in the current namespace.
kubectl port-forward :Forwards a port from a local machine to a port on a pod.
kubectl get events –sort-by=.metadata.creationTimestampLists all events, sorted by their creation timestamp.
kubectl drain –ignore-daemonsetsSafely evicts all pods from a node for maintenance.
kubectl cordon Marks a node as unschedulable (prevents new pods from being scheduled).
kubectl uncordon Marks a node as schedulable (allows new pods to be scheduled).
kubectl version –shortDisplays the client and server versions of Kubernetes.
kubectl get ingressLists all ingress resources in the current namespace.
kubectl get allLists all resources in the current namespace.