This page is under regular updates. Please check back later for more content.
Command Cheatsheet

Kubernetes Commands Cheatsheet

This cheatsheet provides a comprehensive cheatsheet of commonly used kubectl commands for managing Kubernetes clusters. Use this guide as a quick reference to efficiently interact with your Kubernetes environment.

Cluster Management

CommandDescription
kubectl cluster-infoDisplay endpoint information about the master and services in the cluster
kubectl versionDisplay the Kubernetes version running on the client and server
kubectl config viewGet the configuration of the cluster
kubectl api-resourcesList the API resources that are available
kubectl api-versionsList the API versions that are available
kubectl get all --all-namespacesList everything

Common Commands

CommandDescription
kubectl run <name> --image=<image_name>Run a container within a pod in default namespace

Daemonsets

CommandDescription
kubectl get daemonsetList one or more daemonsets
kubectl edit daemonset <daemonset_name>Edit and update the definition of one or more daemonsets
kubectl delete daemonset <daemonset_name>Delete a daemonset
kubectl create daemonset <daemonset_name>Create a new daemonset
kubectl rollout daemonsetManage the rollout of a daemonset
kubectl describe ds <daemonset_name> -n <namespace_name>Display the detailed state of daemonsets within a namespace

Deployments

CommandDescription
kubectl get deploymentList one or more deployments
kubectl describe deployment <deployment_name>Display the detailed state of one or more deployments
kubectl edit deployment <deployment_name>Edit and update the definition of one or more deployments
kubectl create deployment <deployment_name>Create a new deployment
kubectl delete deployment <deployment_name>Delete deployments
kubectl rollout status deployment <deployment_name>See the rollout status of a deployment

Events

CommandDescription
kubectl get eventsList recent events for all resources in the system
kubectl get events --field-selector type=WarningList Warnings only
kubectl get events --field-selector involvedObject.kind!=PodList events but exclude Pod events
kubectl get events --field-selector involvedObject.kind=Node, involvedObject.name=<node_name>Pull events for a single node with a specific name
kubectl get events --field-selector type!=NormalFilter out normal events from a list of events

Logs

CommandDescription
kubectl logs <pod_name>Print the logs for a pod
kubectl logs --since=1h <pod_name>Print the logs for the last hour for a pod
kubectl logs --tail=20 <pod_name>Get the most recent 20 lines of logs
kubectl logs -f <service_name> [-c <$container>]Get logs from a service and optionally select a container
kubectl logs -f <pod_name>Print the logs for a pod and follow new logs
kubectl logs -c <container_name> <pod_name>Print the logs for a container in a pod
kubectl logs <pod_name> pod.logOutput the logs for a pod into a file named ‘pod.log’
kubectl logs --previous <pod_name>View the logs for a previously failed pod

Manifest Files

CommandDescription
kubectl apply -f manifest_file.yamlApply a configuration to an object by filename or stdin. Overrides the existing configuration.
kubectl create -f manifest_file.yamlCreate objects
kubectl create -f ./dirCreate objects in all manifest files in a directory
kubectl create -f ‘url’Create objects from a URL
kubectl delete -f manifest_file.yamlDelete an object

Namespaces

CommandDescription
kubectl create namespace <namespace_name>Create a namespace
kubectl get namespace [<namespace_name>]List one or more namespaces
kubectl describe namespace <namespace_name>Display the detailed state of one or more namespaces
kubectl delete namespace <namespace_name>Delete a namespace
kubectl edit namespace <namespace_name>Edit and update the definition of a namespace
kubectl top namespace <namespace_name>Display Resource (CPU/Memory/Storage) usage for a namespace

Nodes

CommandDescription
kubectl taint node <node_name>Update the taints on one or more nodes
kubectl get nodeList one or more nodes
kubectl delete node <node_name>Delete a node or multiple nodes
kubectl top nodeDisplay Resource usage (CPU/Memory/Storage) for nodes
kubectl describe nodes (use grep Allocated -A 5)Resource allocation per node
kubectl get pods -o wide (use grep <node_name>)Pods running on a node
kubectl annotate node <node_name>Annotate a node
kubectl cordon node <node_name>Mark a node as unschedulable
kubectl uncordon node <node_name>Mark node as schedulable
kubectl drain node <node_name>Drain a node in preparation for maintenance
kubectl label nodeAdd or update the labels of one or more nodes

Pods

CommandDescription
kubectl explain podGives the information about YAML file for pods
kubectl get pod [-o wide]List one or more pods in detail
kubectl delete pod <pod_name>Delete a pod
kubectl describe pod <pod_name>Display the detailed state of pods
kubectl create pod <pod_name>Create a pod
kubectl exec <pod_name> -c <container_name> <command>Execute a command against a container in a pod
kubectl exec -it <pod_name> /bin/shGet interactive shell on a single-container pod
kubectl top podDisplay Resource usage (CPU/Memory/Storage) for pods
kubectl annotate pod <pod_name> <annotation>Add or update the annotations of a pod
kubectl label pod <pod_name>Add or update the label of a pod

Replication Controllers

CommandDescription
kubectl get rcList the replication controllers
kubectl get rc --namespace="<namespace_name>"List the replication controllers by namespace

ReplicaSets

CommandDescription
kubectl get replicasetsList ReplicaSets
kubectl describe replicasets <replicaset_name>Display the detailed state of one or more ReplicaSets
kubectl scale --replicas=[x]Scale a ReplicaSet

Secrets

CommandDescription
kubectl create secretCreate a secret
kubectl get secretsList secrets
kubectl describe secretsList details about secrets
kubectl delete secret <secret_name>Delete a secret

Services

CommandDescription
kubectl get servicesList one or more services
kubectl describe servicesDisplay the detailed state of a service
kubectl expose deployment [deployment_name]Expose a replication controller, service, deployment, or pod as a new Kubernetes service
kubectl edit servicesEdit and update the definition of one or more services

Service Accounts

CommandDescription
kubectl get serviceaccountsList service accounts
kubectl describe serviceaccountsDisplay the detailed state of one or more service accounts
kubectl replace serviceaccountReplace a service account
kubectl delete serviceaccount <service_account_name>Delete a service account

StatefulSet

CommandDescription
kubectl get statefulsetList StatefulSet
kubectl delete statefulset/[stateful_set_name] --cascade=falseDelete StatefulSet only (not pods)

Common Options

CommandDescription
kubectl get pods -o wideList all of the pods in ps output format with more information
kubectl get pods --namespace=[namespace_name]List all the Pods in a specific Namespace
kubectl get pods -n=[namespace_name]Alternative command to list Pods in a Namespace
kubectl create -f ./newpod.jsonCreate a pod using data in a file named newpod.json
kubectl -lSelector to filter on, supports '=', '==', and '!='
kubectl -hHelp for kubectl