You are on page 1of 1

kubectl Commands Cheat Sheet

Listing Resources Displaying the State of Resources Printing Container Logs

kubectl get namespaces Generate a plain-text list of kubectl describe nodes See details about a kubectl logs [pod-name] Print logs from a pod
all namespaces [node-name] particular node
kubectl logs -f [pod-name] Stream logs from a pod
kubectl get pods Generate a plain-text list of kubectl describe pods See details about a
all pods [pod-name] particular pod
Resource Types - Short Names
kubectl get pods -o wide Generate a detailed Kubectl describe –f pod.json See details about a pod
plain-text list of all pods whose name and type are
listed in pod.json Short name Full name
kubectl get pods Generate a list of all pods
--field-selector=spec. running on a particular kubectl describe pods See details about all pods csr certificatesigningrequests
nodeName=[server-name] node server [replication-controller-name] managed by a specific
replication controller
cs componentstatuses
kubectl get List a specific replication
replicationcontroller controller in plain text kubectl describe pods See details about all pods
[replication-controller- cm configmaps
name]
ds daemonsets
Deleting Resources
kubectl get Generate a plain-text list of
replicationcontroller, all replication controllers deploy deployments
services and services kubectl delete -f pod.yaml Remove a pod using the
name and type listed in
ep endpoints
kubectl get deamonset Generate a plain-text list of pod.yaml:
all daemon sets
kubectl delete pods,services Remove all the pods and ev events
-l [label-key]=[label-value] services with a specific
label: hpa horizontalpodautoscalers
Creating a Resource
kubectl delete pods --all Remove all pods. The ing ingresses
kubectl create namespace Create a new namespace command will include
[namespace-name] uninitialized pods as well
limits limitranges

kubectl create –f [filename] Create a resource from a


JSON or YAML file ns namespaces
Executing a Command
no nodes
kubectl exec [pod-name] -- Receive output from a
Applying & Updating a Resource [command] command run on the first pvc persistentvolumeclaims
container in a pod:
kubectl apply -f Create a new service with
pv persistentvolumes
[service-name].yaml the definition contained in kubectl exec [pod-name] -c Receive output from a
[service-name].yaml [container-name] -- command run on a specific
po pods
[command] container in a pod
kubectl apply -f Create a new replication
[controller-name].yaml controller with the kubectl exec -ti [pod-name] -- Run /bin/bash from a pdb poddisruptionbudgets
definition contained in /bin/bash specific pod. The output
[controller-name].yaml received comes from the psp podsecuritypolicies
first container
kubectl apply -f Create the objects defined rs replicasets
[directory-name] in any .yaml, .yml, or .json
file in a directory Modifying kubeconfig Files rc replicationcontrollers
kubectl edit svc/ Edit a service
[service-name] kubectl config Display the current context quota resourcequotas
current-context
KUBE_EDITOR=” Edit a service in a sa serviceaccounts
[editor-name]” kubectl edit non-default editor kubectl config set-cluster Set a cluster entry in
svc/[service-name] [cluster-name] --server= kubeconfig svc services
[server-name]

kubectl config unset Unset an entry in


[property-name] kubeconfig

You might also like