Kubernetes Cheatsheet
Kubernetes Basics:
- kubectl version: Check the Kubernetes client and server versions.
- kubectl cluster-info: View cluster details.
- kubectl get pods: List all pods in the current namespace.
- kubectl get nodes: List all nodes in the cluster.
- kubectl describe pod [pod-name]: Get detailed information about a pod.
Creating and Managing Resources:
- kubectl create -f [yaml-file]: Create a resource from a YAML file.
- kubectl apply -f [yaml-file]: Apply changes to a resource.
- kubectl delete [resource-type] [resource-name]: Delete a resource.
- kubectl edit [resource-type] [resource-name]: Edit a resource in the default text editor.
- kubectl get [resource-type]: List resources of a specific type.
- kubectl logs [pod-name]: View logs of a pod.
Scaling:
- kubectl scale deployment [deployment-name] --replicas=[num-replicas]: Scale a deployment.
- kubectl autoscale deployment [deployment-name] --min=[min-replicas] --max=[max-replicas]: Autoscale a deployment.
Networking:
- kubectl expose [resource-type] [resource-name] --port=[port] --target-port=[target-port] --type=[service-type]:Expose a resource as a service.
- kubectl get svc: List services.
- kubectl port-forward [pod-name] [local-port]:[pod-port]: Forward ports from a local machine to a pod.
Configuration:
- kubectl config view: View the current configuration.
- kubectl config use-context [context-name]: Set the current context.
Pods:
- kubectl exec -it [pod-name] -- [command]: Execute a command in a pod.
- kubectl run [pod-name] --image=[image-name]: Create a new pod running a specific image.
Namespaces:
- kubectl create namespace [namespace-name]: Create a new namespace.
- kubectl get namespaces: List namespaces.
- kubectl config set-context --current --namespace=[namespace-name]: Set the default namespace.
Secrets and ConfigMaps:
- kubectl create secret generic [secret-name] --from-literal=[key]=[value]: Create a secret.
- kubectl create configmap [configmap-name] --from-literal=[key]=[value]: Create a ConfigMap.
- kubectl describe secret [secret-name]: View secret details.
- kubectl describe configmap [configmap-name]: View ConfigMap details.
Storage:
- kubectl get pv: List persistent volumes.
- kubectl get pvc: List persistent volume claims.
Advanced Troubleshooting:
- kubectl describe [resource-type] [resource-name]: Get detailed information about a resource.
- kubectl top [resource-type] [resource-name]: Display resource usage statistics.
Remember to replace placeholders like [resource-type], [resource-name], [pod-name], etc., with your actual resource and object names.
This cheatsheet should help you get started with Kubernetes and serve as a handy reference as you work with containers and orchestration in Kubernetes.
Top comments (1)
The official cheatsheet is pretty straightforward, and there is a community A4 cheatsheet.