Files
cheatsheets/kubernetes-cheatsheet.md
2025-10-10 21:21:39 +02:00

48 lines
1.6 KiB
Markdown

# Kubernetes Cheatsheet
## Basics
- Get cluster info: `kubectl cluster-info`
- Get nodes: `kubectl get nodes`
- Get pods: `kubectl get pods`
- Get all resources: `kubectl get all`
## Contexts and Config
- View config: `kubectl config view`
- Set context: `kubectl config use-context <context-name>`
- Set namespace: `kubectl config set-context --current --namespace=<namespace>`
## Pods
- Create pod: `kubectl run <pod-name> --image=<image>`
- Describe pod: `kubectl describe pod <pod-name>`
- Exec into pod: `kubectl exec -it <pod-name> -- /bin/sh`
- Logs: `kubectl logs <pod-name>`
- Delete pod: `kubectl delete pod <pod-name>`
## Deployments
- Create deployment: `kubectl create deployment <name> --image=<image>`
- Get deployments: `kubectl get deployments`
- Scale: `kubectl scale deployment <name> --replicas=<num>`
- Update image: `kubectl set image deployment/<name> <container>=<new-image>`
- Delete: `kubectl delete deployment <name>`
## Services
- Expose deployment: `kubectl expose deployment <name> --type=NodePort --port=80`
- Get services: `kubectl get services`
- Describe service: `kubectl describe service <name>`
- Delete service: `kubectl delete service <name>`
## Namespaces
- Create namespace: `kubectl create namespace <name>`
- Get namespaces: `kubectl get namespaces`
- Delete namespace: `kubectl delete namespace <name>`
## Apply YAML
- Apply file: `kubectl apply -f <file.yaml>`
- Delete from file: `kubectl delete -f <file.yaml>`
## Other
- Port forward: `kubectl port-forward <pod> 8080:80`
- Get events: `kubectl get events`
- Proxy API: `kubectl proxy`
For more, refer to official docs: https://kubernetes.io/docs/