Kubernetes Cheat sheet

Listing Resources:

To list one or more pods, replication controllers, services, or daemon sets, use the kubectl get command.

Generate a plain-text list of all namespaces.

command: kubectl get namespace


Generate a plain-text list of all pods.

command: kubectl get pods


Generate a detailed plain-text list of all pods.

command: kubectl get pods -o wide


Generate a list of all pods running on a particular node server.

command: kubectl get pods --field-selector=spec.nodeName=[server-name]


List a specific replication controller in plain-text.

command: kubectl get replicationcontroller [replication-controller-name]


Generate a plain-text list of all replication controllers and services.

command: kubectl get replicationcontroller, services


Generate a plain-text list of all daemon sets:

command: kubectl get daemonset

Creating a Resource:

Create a resource such as a service, a deployment, a job, or a namespace using the kubectl create command.

create a new namespace.

command: kubectl create namespace [namespace-name]


Create a resource from a JSON or YAML file.

command: kubectl create –f [filename]


Applying and Updating a Resource:

To apply or update a resource using the kubectl apply command. The source in this operation can be either a file or the standard input (stdin).


Create a new service with the definition contained in [service-name].yaml.

command: kubectl apply -f [service-name].yaml


Create a new replication controller with the definition contained in [controller-name].yaml.

command: kubectl apply -f [controller-name].yaml


Create the objects defined in any .yaml, .yml, or .json file in a directory.

command: kubectl apply -f [directory-name]


Edit a service.

command: kubectl edit svc/[service-name]


Edit a service in a non-default editor.

command: KUBE_EDITOR=”[editor-name]” kubectl edit svc/[service-name]



Displaying the State of Resources:

To display the state of any number of resources in detail, use the kubectl describe command. By default, the output also lists uninitialized resources.


View details about a particular node.

command: kubectl describe nodes [node-name]


View details about a particular pod.

command: kubectl describe pods [pod-name]


Display details about a pod whose name and type are listed in pod.json.

command: Kubectl describe –f pod.json


See details about all pods managed by a specific replication controller.

command: kubectl describe pods [replication-controller-name]


Show details about all pods.

command: kubectl describe pods


Deleting Resources:

To remove resources from a file or stdin, use the kubectl delete command.


Remove a pod using the name and type listed in pod.yaml.

command: kubectl delete -f pod.yaml


Remove all pods and services with a specific label:

command: kubectl delete pods,services -l [label-key]=[label-value]


Remove all pods.

command: kubectl delete pods --all


Executing a Command:

Use kubectl exec to issue commands to a container or to open a shell in a container.


Receive output from a command run on the first container in a pod.

command: kubectl exec [pod-name] -- [command]


Get output from a command run on a specific container in a pod.

command: kubectl exec [pod-name] -c [container-name] -- [command]


Run /bin/bash from a specific pod. The received output comes from the first container.

command: kubectl exec -ti [pod-name] -- /bin/bash


Modifying kubeconfig Files:

The kubectl config command lets you view and modify kubeconfig files. This command is usually followed by another sub-command.


Display the current context.

command: kubectl config current-context


Set a cluster entry in kubeconfig.

command: kubectl config set-cluster [cluster-name] --server=[server-name]


Unset an entry in kubeconfig.

command: kubectl config unset [property-name]


Printing Container Logs:

To print logs from containers in a pod, use the kubectl logs command.


To print logs from a pod.

command: kubectl logs [pod-name]


To stream logs from a pod.

Recent Comments

No comments

Leave a Comment