0% found this document useful (0 votes)
5 views

kubernetes_cheat_sheet

This document is a comprehensive cheat sheet for Kubernetes commands, detailing various operations related to namespaces, nodes, pods, deployments, services, and more. It includes command syntax and descriptions for creating, deleting, and managing Kubernetes resources. The document serves as a quick reference for engineers working with Kubernetes infrastructure as code (IaC).

Uploaded by

sibuni65
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

kubernetes_cheat_sheet

This document is a comprehensive cheat sheet for Kubernetes commands, detailing various operations related to namespaces, nodes, pods, deployments, services, and more. It includes command syntax and descriptions for creating, deleting, and managing Kubernetes resources. The document serves as a quick reference for engineers working with Kubernetes infrastructure as code (IaC).

Uploaded by

sibuni65
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

// The Most Flexible IaC Platform

Kubernetes Cheat Sheet


Common Options N a mesp ces a

alias kubectl create names ace <names ace_name> p p

Set an alias for kubectl. C reate a namespace.


-o=json kubectl get names ace <names ace_name>
p p

Output format in JSON. List one or more namespaces.


-o=yaml kubectl describe names ace <names ace_name> p p

Output format in YAML. D isplay the detailed state of one or more namespaces.
-o=wide kubectl delete names ace <names ace_name> p p

Output in the plain-text format with any additional information, and for pods, D elete a namespace.
the node name is included.
kubectl edit names ace <names ace_name>
p p

-n
Edit and update the definition of a namespace.
Alias for namespace.
kubectl to names ace <names ace_name>
p p p

-f
D isplay Resource ( PU/Memory/Storage) usage for a namespace.
C

Filename, directory, or URL to files to use to create a resource.


-l
Nodes
Filter using a specified label.
-h kubectl taint node <node_name>
Help for kubectl. Update the taints on one or more nodes.
kubectl get node
List one or more nodes.
Con gur tion i esfi a F l

kubectl delete node <node_name>


kubectl create -f <configuration file>
D elete a node or multiple nodes.
C reate ob ects.
j

kubectl to node <node_name>


p

kubectl create -f <configuration file directory>


D isplay Resource usage ( PU/Memory/Storage) for nodes.
C

C reate ob ects in all manifest files in a directory.


j

kubectl get ods -o wide gre <node_name>


p | p

kubectl create -f < url > ‘ ’


P ods running on a node.
C reate ob ects from a URL.
j

kubectl annotate node <node_name>


kubectl delete -f <configuration file> Annotate a node.
D elete an ob ect. j

kubectl cordon node <node_name>


Mark a node as unschedulable.
C uster M n gement nd Context
l a a a
kubectl uncordon node <node_name>
kubectl cluster-info Mark node as schedulable.
D isplay endpoint information about the master and ser ices in the cluster. v
kubectl drain node <node_name>
kubectl ersion
v
D rain a node in preparation for maintenance.
D isplay the ubernetes ersion running on the client and ser er.
K v v
kubectl label node
kubectl config iew v
Add or update the labels of one or more nodes.
G et the configuration of the cluster.
kubectl config iew -o json ath= users name
v p '{. [*]. }'
Pods
G et a list of users.
kubectl get od p

kubectl config current-conte t x


List one or more pods.
D isplay the current context.
kubectl get ods --sort-by= status container tatuses 0 restart ount
p '. . S [ ]. C '

kubectl config get-conte ts x


List pods Sorted by Restart ount. C

D isplay a list of contexts.


kubectl get ods --field-selector=status hase= unning
p .p R

kubectl config use-conte t <cluster name> x


G et all running pods in the namespace.
Set the default context.
kubectl delete od < od_name>
p p

kubectl a i-resources
p
D elete a pod.
List the API resources that are a ailable. v

kubectl describe od < od_name>p p

kubectl a i- ersions
p v
D isplay the detailed state of a pods.
List the API ersions that are a ailable.
v v

kubectl create od < od_name>


p p

C reate a pod.
D a emonsets kubectl e ec < od_name> -c <container_name> <command>
x p

kubectl get daemonset E xecute a command against a container in a pod.


List one or more daemonsets. kubectl e ec -it < od_name> /bin/sh
x p

kubectl edit daemonset <daemonset_name> G et an interacti e shell on a single-container pod.


v

Edit and update the definition of one or more daemonset. kubectl to od p p

kubectl delete daemonset <daemonset_name> D isplay Resource usage ( PU/Memory/Storage) for pods.C

D elete a daemonset. kubectl annotate od < od_name> <annotation>


p p

kubectl create daemonset <daemonset_name> Add or update the annotations of a pod.


C reate a new daemonset. kubectl label ods < od_name> new-label=<label name>
p p

kubectl rollout daemonset Add or update the label of a pod.


Manage the rollout of a daemonset. kubectl get ods --show-labels
p

kubectl describe ds <daemonset_name> -n <names ace_name> p


G et pods and show labels.
D isplay the detailed state of daemonsets within a namespace. kubectl ort-forward < od name> < ort number to listen on>:< ort number to
forward to>
p p p p

Listen on a port on the local machine and forward to a port on a specified


pod.
Dep oyments l

kubectl get de loyment


Rep ic tion Contro ers
p

List one or more deployments.


l a ll

kubectl describe de loyment <de loyment_name>


p p
kubectl get rc
D isplay the detailed state of one or more deployments. List the replication controllers.
kubectl edit de loyment <de loyment_name>
p p
kubectl get rc --names ace=”<names ace_name>” p p

Edit and update the definition of one or more deployments on the ser er. v
List the replication controllers by namespace.
kubectl create de loyment <de loyment_name>
p p

C reate a new deployment. Rep ic Sets l a

kubectl delete de loyment <de loyment_name>


p p
kubectl get re licasets
p

D elete deployments. List ReplicaSets.


kubectl rollout status de loyment <de loyment_name>
p p
kubectl describe re licasets <re licaset_name>
p p

See the rollout status of a deployment. D isplay the detailed state of one or more ReplicaSets.
kubectl set image de loyment/<de loyment name> <container name>=image:
kubectl scale --re licas=
<new image ersion>
p p
p [x]
v

Perform a rolling update ( 8S default ), set the image of the container to a


K
Scale a ReplicaSet.
new ersion for a particular deployment.
v

kubectl rollout undo de loyment/<de loyment name>


Secrets
p p

Rollback a pre ious deployment.


v

kubectl re lace --force -f <configuration file>


p
kubectl create secret
Perform a replace deployment — Force replace, delete and then re-create the C reate a secret.
resource.
kubectl get secrets
List secrets.
Events kubectl describe secrets
kubectl get e ents v
List details about secrets.
List recent e ents for all resources in the system.
v kubectl delete secret <secret_name>
kubectl get e ents --field-selector ty e=Warning
v p
D elete a secret.
List Warnings only.
kubectl get e ents --sort-by= metadata creationTimestam
v . . p Services
List e ents sorted by timestamp.
kubectl get ser ices
v

kubectl get e ents --field-selector in ol edObject kind!=Pod


v v v .
List one or more ser ices. v

List e ents but exclude Pod e ents.


kubectl describe ser ices
v v

kubectl get e ents --field-selector in ol edObject kind=Node, in ol edObject name


isplay the detailed state of a ser ice.
=<node_name>
v v v . v v .
D v

P ull e ents for a single node with a specific name.


v kubectl e ose de loyment de loyment_name
xp p [ p ]

kubectl get e ents --field-selector ty e!=Normal E xpose a replication controller, ser ice, deployment, or pod as a new v
v p
K ubernetes ser ice. v

Filter out normal e ents from a list of e ents.


v v

kubectl edit ser ices v

Edit and update the definition of one or more ser ices. v

L ogs
kubectl logs < od_name> p
Services Accounts
P rint the logs for a pod.
kubectl get ser iceaccounts
v

kubectl logs --since=6h < od_name> p


List ser ice accounts.
v

P rint the logs for the last 6 hours for a pod.


kubectl describe ser iceaccounts v

kubectl logs --tail=50 < od_name> p


D isplay the detailed state of one or more ser ice accounts. v

G et the most recent 50 lines of logs.


kubectl re lace ser iceaccount
p v

kubectl logs -f <ser ice_name> -c < container>


v [ $ ]
Replace a ser ice account.
v

G et logs from a ser ice and optionally select which container.


v

kubectl delete ser iceaccount <ser ice_account_name>


v v

kubectl logs -f < od_name> p

D elete a ser ice account.


v

P rint the logs for a pod and follow new logs.


kubectl logs -c <container_name> < od_name>
St tefu Set
p

P rint the logs for a container in a pod. a l

kubectl logs < od_name> od log


p p .
kubectl get statefulset
Output the logs for a pod into a file named pod.log . ‘ ’
List StatefulSet
kubectl logs -- re ious < od_name>
p v p
kubectl delete statefulset/ stateful_set_name --cascade=false
[ ]

V iew the logs for a pre iously failed pod.v


D elete StatefulSet only (not pods).

The IaC Orchestration Platform Engineers Trust

You might also like