Arunav Goswami
Data Science Consultant at almaBetter
Explore our Kubernetes cheat sheet for essential commands and concepts. Learn kubectl commands, Kubernetes objects, and more to streamline orchestration tasks
Kubernetes, an open-source container orchestration platform, automates the deployment, scaling, and management of containerized applications. For developers and system administrators, having a cheat sheet for Kubernetes commands can significantly improve efficiency and understanding. This guide provides an essential Kubernetes commands cheat sheet, covering kubectl commands, Kubernetes objects, concepts, and more.
Kubernetes is designed to manage containerized applications in a clustered environment, providing mechanisms for deployment, maintenance, and scaling of applications. This cheat sheet will help you navigate through essential commands and concepts of Kubernetes, ensuring you have the necessary tools and knowledge at your fingertips.
kubectl version # Display the Kubernetes client and server version.
kubectl version --short # Displays a concise version information.
kubectl cluster-info # Display cluster information.
kubectl get [resource] # List one or more resources.
kubectl get pods # Lists all pods in the current namespace.
kubectl describe [resource] [name] # Show detailed information about a resource.
kubectl describe pod [pod-name] # Provides detailed information about the specified pod.
kubectl logs [pod] # Print the logs for a container in a pod.
kubectl logs [pod-name] # Prints logs from the specified pod.
kubectl create -f [file] # Create a resource from a file.
kubectl create -f deployment.yaml # Creates resources defined in deployment.yaml.
kubectl apply -f [file] # Apply a configuration to a resource by file name or stdin.
kubectl apply -f deployment.yaml # Applies changes from deployment.yaml.
kubectl delete [resource] [name] # Delete resources by names.
kubectl delete pod [pod-name] # Deletes the specified pod.
kubectl delete -f [file] # Delete resources defined in a file.
kubectl delete -f deployment.yaml # Deletes resources defined in deployment.yaml.
Pods are the smallest, most basic deployable objects in Kubernetes. A pod represents a single instance of a running process in your cluster.
Deployments provide declarative updates to applications. They are used to manage stateless services.
kubectl get deployments # Lists all deployments.
Services are an abstract way to expose an application running on a set of pods as a network service.
kubectl get services # Lists all services in the current namespace.
ConfigMaps are used to store configuration data in key-value pairs.
kubectl get configmaps # Lists all ConfigMaps.
Secrets are used to store sensitive data, such as passwords and tokens.
kubectl get secrets # Lists all secrets.
Namespaces are used to divide cluster resources between multiple users.
kubectl get namespaces # Lists all namespaces in the cluster.
Labels are key-value pairs attached to objects, used for organizing and selecting subsets of objects.
kubectl get pods --selector app=myapp # Lists all pods with the label app=myapp.
Annotations are key-value pairs attached to objects, used to store non-identifying information.
kubectl annotate pod [pod-name] description='my pod' # Adds an annotation to a pod.
Taints are applied to nodes to prevent them from accepting any pods that do not tolerate the taints.
kubectl taint nodes node1 key=value:NoSchedule # Applies a taint to a node.
Tolerations are applied to pods, allowing them to be scheduled on nodes with matching taints.
kubectl get pods --selector key=value # Lists pods that tolerate specific taints.
kubectl run nginx --image=nginx # Creates a pod with the nginx image.
kubectl create deployment nginx --image=nginx # Creates a deployment named nginx.
kubectl expose deployment nginx --port=80 --target-port=80 # Exposes the nginx deployment on port 80.
kubectl scale deployment nginx --replicas=3 # Scales the nginx deployment to 3 replicas.
kubectl get pods [--namespace [namespace]] # Lists all pods in the specified namespace.
kubectl describe pod [pod-name] # Describes a pod in detail.
kubectl logs [pod-name] # Retrieves logs for a pod.
kubectl exec [pod-name] -- [command] # Executes a command in a container in the pod.
kubectl delete pod [pod-name] # Deletes a specified pod.
kubectl get deployments [--namespace [namespace]]
kubectl describe deployment [deployment-name]
kubectl create deployment [deployment-name] --image=[image]
kubectl scale deployment [deployment-name] --replicas=[number]
kubectl rollout status deployment [deployment-name]
kubectl rollout undo deployment [deployment-name]
kubectl get services [--namespace [namespace]]
kubectl describe service [service-name]
kubectl expose deployment [deployment-name] --type=[type] --port=[port]
kubectl create configmap [configmap-name] --from-literal=[key]=[value]
kubectl get configmaps
kubectl describe configmap [configmap-name]
kubectl create secret generic [secret-name] --from-literal=[key]=[value]
kubectl get secrets
kubectl describe secret [secret-name]
kubectl get pv
kubectl describe pv [pv-name]
kubectl get pvc
kubectl describe pvc [pvc-name]
kubectl get namespaces
kubectl create namespace [namespace]
kubectl delete namespace [namespace]
kubectl top nodes
kubectl top pods [--namespace [namespace]]
kubectl logs [pod-name]
kubectl port-forward [pod-name] [local-port]:[pod-port]
This Kubernetes cheat sheet serves as a quick reference guide for developers and system administrators. Keep this cheat sheet handy to streamline your Kubernetes operations and enhance your productivity.
More Cheat Sheets and Top Picks