main_kubectl-commands-cheat-sheet
main_kubectl-commands-cheat-sheet
kubectl get namespaces Generate a plain-text kubectl describe nodes See details about kubectl logs [pod-name] Print logs from a
list of [node-name] a pod
all namespaces particular node kubectl logs -f [pod-name] Stream logs from a
kubectl get pods Generate a plain-text kubectl describe pods See details about pod
list of [pod-name] a
all pods particular pod
Kubectl describe –f pod.json See details about a pod
Resource Types - Short Names
kubectl get pods -o wide Generate a detailed
plain-text list of all whose name and type are
pods listed in pod.json Short name Full name
kubectl get pods Generate a list of all
--field-selector=spec. pods kubectl describe pods See details about all csr certificatesigningreque
nodeName=[server-name] running on a pods
[replication-controller-name] managed by a specific sts
particular node server replication
cs componentstatus
kubectl get List a specific controller
replicationcontroller es
replication kubectl describe pods See details about all
[replication-controller- controller in plain pods cm configmap
name] s
ds daemonse
kubectl get Generate a plain-text
Deleting Resources ts
replicationcontroller, list of all replication
services deploy deploymen
controllers kubectl delete -f pod.yaml Remove a pod using ts
the name and type
ep endpoin
kubectl get deamonset Generate a plain-text listed in ts
list of
all daemon sets kubectl delete pods,services Remove all the pods and ev event
s
-l [label-key]=[label-value] services with a specific
label: hpa horizontalpodautoscal
Creating a Resource ers
kubectl delete pods --all Remove all pods. The ing ingresse
kubectl create namespace Create a new command will include s
[namespace-name] namespace uninitialized pods as
limits limitrang
well
es
kubectl create –f [filename] Create a resource
from a ns namespace
JSON or YAML file Executing a Command s
no node
kubectl exec [pod-name] -- s
Applying & Updating a Resource [command]
Receive output from a
command run on the pvc persistentvolumeclai
first ms
kubectl apply -f Create a new service
[service-name].yaml pv persistentvolum
with the definition kubectl exec [pod-name] -c Receive output from a es
contained in [container-name] -- command run on a
[command] po pod
specific
s
kubectl apply -f Create a new
[controller-name].yaml replication controller kubectl exec -ti [pod-name] -- Run /bin/bash from a pdb poddisruptionbudget
with the definition /bin/bash specific pod. The s
contained in output received psp podsecuritypolici
comes from the first es
kubectl apply -f Create the objects container
[directory-name] rs replicase
defined ts
in any .yaml, .yml, or Modifying kubeconfig Files rc replicationcontroller
.json file in a directory
s
kubectl edit svc/ Edit a
[service-name] service kubectl config Display the current quota resourcequot
current-context context as
KUBE_EDITOR=” Edit a service in sa serviceaccount
[editor-name]” kubectl edit a kubectl config set-cluster Set a cluster s
svc/[service-name] non-default [cluster-name] --server= entry in
[server-name] svc service
kubeconfig s