Kubernetes Cheat Sheet
Published in
2 min readApr 30, 2024
Kubernetes has become the go-to platform for managing containerized applications at scale. However, mastering Kubernetes requires understanding its extensive command-line interface (CLI) to efficiently manage resources. In this article, we’ll provide a comprehensive command cheat sheet with examples to help you navigate Kubernetes like a pro.
1. Pod Commands:
- Create a Pod:
$ kubectl create -f <pod-definition.yaml>
- List Pods:
$ kubectl get pods
- Describe a Pod:
$ kubectl describe pod <pod-name>
- Delete a Pod:
$ kubectl delete pod <pod-name>
- Exec into a Pod:
$ kubectl exec -it <pod-name> - /bin/bash
2. Deployment Commands:
- Create a Deployment:
$ kubectl create deployment <deployment-name> - image=<image-name>
- List Deployments:
$ kubectl get deployments
- Scale a Deployment:
$ kubectl scale deployment <deployment-name> - replicas=<number-of-replicas>
- Rollout Status:
$ kubectl rollout status deployment/<deployment-name>
- Rollout History:
$ kubectl rollout history deployment/<deployment-name>
3. Service Commands:
- Create a Service:
$ kubectl expose deployment <deployment-name> - type=NodePort - port=<port-number>
- List Services:
$ kubectl get services
- Describe a Service:
$ kubectl describe service <service-name>
- Delete a Service:
$ kubectl delete service <service-name>
4. Namespace Commands:
- Create a Namespace:
$ kubectl create namespace <namespace-name>
- List Namespaces:
$ kubectl get namespaces
- Describe a Namespace:
$ kubectl describe namespace <namespace-name>
- Delete a Namespace:
$ kubectl delete namespace <namespace-name>
5. ConfigMap and Secret Commands:
- Create a ConfigMap:
$ kubectl create configmap <configmap-name> - from-literal=<key1>=<value1> - from-literal=<key2>=<value2>
- List ConfigMaps:
$ kubectl get configmaps
- Describe a ConfigMap:
$ kubectl describe configmap <configmap-name>
- Delete a ConfigMap:
$ kubectl delete configmap <configmap-name>
- Create a Secret:
$ kubectl create secret generic <secret-name> - from-literal=<key1>=<value1> - from-literal=<key2>=<value2>
- List Secrets:
$ kubectl get secrets
- Describe a Secret:
$ kubectl describe secret <secret-name>
- Delete a Secret:
$ kubectl delete secret <secret-name>
6. Other Useful Commands:
- Apply Changes to Resources:
$ kubectl apply -f <resource-definition.yaml>
- Access Kubernetes Dashboard:
$ kubectl proxy
- Get Logs of a Pod:
$ kubectl logs <pod-name>
- Port Forwarding:
$ kubectl port-forward <pod-name> <local-port>:<pod-port>
- Export YAML Manifest of a Resource:
$ kubectl get <resource-type> <resource-name> -o yaml > <resource-definition.yaml>
This cheat sheet covers the fundamental commands for managing Kubernetes resources efficiently. Always refer to the official documentation or specific tutorials for deeper understanding and advanced usage.
In Plain English 🚀
Thank you for being a part of the In Plain English community! Before you go:
- Be sure to clap and follow the writer ️👏️️
- Follow us: X | LinkedIn | YouTube | Discord | Newsletter
- Visit our other platforms: Stackademic | CoFeed | Venture | Cubed
- More content at PlainEnglish.io