Kubernetes Cheatsheet
#
Kubernetes, also known as K8s, is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. Originally developed by Google, Kubernetes is now maintained by the Cloud Native Computing Foundation (CNCF) and is widely used to manage complex microservices architectures.
Kubernetes Basics
#
Command/Option | Example | Description |
---|
kubectl version | kubectl version | Show the kubectl version |
kubectl cluster-info | kubectl cluster-info | Display cluster information |
kubectl get nodes | kubectl get nodes | List all nodes in the cluster |
Working with Pods
#
Command/Option | Example | Description |
---|
kubectl get pods | kubectl get pods | List all pods in the current namespace |
kubectl describe pod | kubectl describe pod <pod_name> | Show details of a specific pod |
kubectl logs | kubectl logs <pod_name> | Print the logs from a container in a pod |
kubectl exec | kubectl exec -it <pod_name> -- /bin/bash | Execute a command in a container in a pod |
Working with Deployments
#
Command/Option | Example | Description |
---|
kubectl get deployments | kubectl get deployments | List all deployments in the current namespace |
kubectl describe deployment | kubectl describe deployment <deployment_name> | Show details of a specific deployment |
kubectl create deployment | kubectl create deployment nginx --image=nginx | Create a new deployment |
kubectl scale deployment | kubectl scale deployment <deployment_name> --replicas=3 | Scale a deployment to a specified number of replicas |
kubectl delete deployment | kubectl delete deployment <deployment_name> | Delete a deployment |
Working with Services
#
Command/Option | Example | Description |
---|
kubectl get services | kubectl get services | List all services in the current namespace |
kubectl describe service | kubectl describe service <service_name> | Show details of a specific service |
kubectl expose deployment | kubectl expose deployment <deployment_name> --type=NodePort --port=8080 | Expose a deployment as a service |
kubectl delete service | kubectl delete service <service_name> | Delete a service |
ConfigMaps and Secrets
#
Command/Option | Example | Description |
---|
kubectl create configmap | kubectl create configmap my-config --from-literal=key1=value1 | Create a ConfigMap from a literal value |
kubectl get configmaps | kubectl get configmaps | List all ConfigMaps in the current namespace |
kubectl describe configmap | kubectl describe configmap <configmap_name> | Show details of a specific ConfigMap |
kubectl delete configmap | kubectl delete configmap <configmap_name> | Delete a ConfigMap |
kubectl create secret | kubectl create secret generic my-secret --from-literal=password=my-password | Create a Secret from a literal value |
kubectl get secrets | kubectl get secrets | List all Secrets in the current namespace |
kubectl describe secret | kubectl describe secret <secret_name> | Show details of a specific Secret |
kubectl delete secret | kubectl delete secret <secret_name> | Delete a Secret |
Persistent Volumes and Claims
#
Command/Option | Example | Description |
---|
kubectl get pv | kubectl get pv | List all PersistentVolumes in the cluster |
kubectl get pvc | kubectl get pvc | List all PersistentVolumeClaims in the current namespace |
kubectl describe pv | kubectl describe pv <pv_name> | Show details of a specific PersistentVolume |
kubectl describe pvc | kubectl describe pvc <pvc_name> | Show details of a specific PersistentVolumeClaim |
kubectl delete pv | kubectl delete pv <pv_name> | Delete a PersistentVolume |
kubectl delete pvc | kubectl delete pvc <pvc_name> | Delete a PersistentVolumeClaim |
Namespaces
#
Command/Option | Example | Description |
---|
kubectl get namespaces | kubectl get namespaces | List all namespaces in the cluster |
kubectl describe namespace | kubectl describe namespace <namespace_name> | Show details of a specific namespace |
kubectl create namespace | kubectl create namespace <namespace_name> | Create a new namespace |
kubectl delete namespace | kubectl delete namespace <namespace_name> | Delete a namespace |
Additional Commands
#
Command/Option | Example | Description |
---|
kubectl apply | kubectl apply -f <file.yaml> | Apply a configuration to a resource by file or stdin |
kubectl delete | kubectl delete -f <file.yaml> | Delete resources by file or stdin |
kubectl config view | kubectl config view | Display merged kubeconfig settings |
kubectl config use-context | kubectl config use-context <context_name> | Set the current context in your kubeconfig |
kubectl top nodes | kubectl top nodes | Display resource (CPU/memory) usage of nodes |
kubectl top pods | kubectl top pods | Display resource (CPU/memory) usage of pods |
This cheatsheet covers the most commonly used Kubernetes commands and options, helping you to manage clusters, pods, deployments, services, ConfigMaps, Secrets, and more.