Kubernetes Commands Cheat Sheet
Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. This comprehensive cheat sheet will guide you through various Kubernetes commands for interacting with clusters and managing resources.
Cluster Management:
Create a Cluster:
kubeadm init
Join a Node to the Cluster:
kubeadm join <control-plane-host>:<port> --token <token> --discovery-token-ca-cert-hash <hash>
Get Cluster Info:
kubectl cluster-info
Check Nodes in the Cluster:
kubectl get nodes
View Detailed Node Information:
kubectl describe node <node-name>
Check Kubernetes Events:
kubectl get events
Workloads:
Deploy an Application:
kubectl create deployment <deployment-name> --image=<image>
Expose a Deployment as a Service:
kubectl expose deployment <deployment-name> --port=<port> --type=<service-type>
Scale a Deployment:
kubectl scale deployment <deployment-name> --replicas=<replica-count>
Update a Deployment:
kubectl set image deployment/<deployment-name> <container-name>=<new-image>
Pods:
List Pods:
kubectl get pods
View Pod Logs:
kubectl logs <pod-name>
Exec into a Pod:
kubectl exec -it <pod-name> -- /bin/sh
Delete a Pod:
kubectl delete pod <pod-name>
Services:
List Services:
kubectl get services
Describe a Service:
kubectl describe service <service-name>
Expose a Port on Service:
kubectl port-forward service/<service-name> <local-port>:<service-port>
Configurations:
Get ConfigMaps:
kubectl get configmaps
Describe a ConfigMap:
kubectl describe configmap <configmap-name>
Create a Secret from File:
kubectl create secret generic <secret-name> --from-file=<file-path>
Monitoring and Troubleshooting:
Check Cluster Events:
kubectl get events
Get Component Status:
kubectl get componentstatus
Run Diagnostic on a Node:
kubectl describe node <node-name>
Run Diagnostic on a Pod:
kubectl describe pod <pod-name>
Check Cluster API Versions:
kubectl api-versions
This Kubernetes cheat sheet provides a starting point for managing clusters, deploying applications, and troubleshooting issues. Refer to the official Kubernetes documentation for in-depth information: Kubernetes Documentation.