Kubernetescheatsheet
Kubernetescheatsheet
Kubernetes Commands
Author by Unnati Gupta
Pods
i) To List all pods in the current namespace
kubectl get pods
Unnati Gupta
Deployments
i) To List all deployments in the current namespace
kubectl get deployments
Unnati Gupta
ReplicaSets
i) To List all replicasets in the current namespace
kubectl get replicasets
Unnati Gupta
NameSpaces
i) To Create a Namespace
kubectl create ns <namespace-name>
Unnati Gupta
Services
i) To list all the services in the current namespace
kubectl get service
Unnati Gupta
Label & Selectors
i) Label Resources
kubectl label pods <pod-name> <key>=<value>
Unnati Gupta
Taints & Tolerations
i) Applying Taints to a Nodes
kubectl taint nodes <node-name> key=value:taint-
effect
Note:
taint-effect: The effect of the taint, which can be one of
the following:
a) NoSchedule: Pods will not be scheduled on the node
unless they tolerate the taint.
b) PreferNoSchedule: Kubernetes will try to avoid
placing a pod on the node but it's not guaranteed.
c) NoExecute: New pods will not be scheduled on the
node and existing pods on the node if they do not
tolerate the taint will be evicted if they do not tolerate
the taint.
Unnati Gupta
Daemonsets
i) To list all daemonsets in the current
namespace
kubectl get daemonsets
Unnati Gupta
Logging & Monitoring
i) To view the logs of a Pod
kubectl logs <pod-name>
Unnati Gupta
Rolling Updates & RollBacks
i) Perform a Rolling Update
kubectl set image deployment/<deployment-name>
<container-name>=<new-image>:<tag>
Unnati Gupta
Envirnoment Variables
i) List the envirnoment variables define in all pods
kubectl set env pods --all-list
Unnati Gupta
ConfigMap
i) Create a configmap based on the file
kubectl create configmap <configmap-name> --from-
file=<file-path>
Unnati Gupta
Secrets
i) Create a secret with specified keys
kubectl create secret generic <secret-name> --from-
literal=<key-name>=<value-name>
Unnati Gupta
Role & RoleBinding
i) Create a role
kubectl create role <role_name> --verb=<verb> --
resource=<resource> --namespace=<namespace>
Unnati Gupta
ClusterRole
i) Create a clusterrole
kubectl create clusterrole <clusterrole_name> --verb=
<verb> --resource=<resource>
v) Delete a clusterrole
kubectl delete clusterrole <clusterrole_name>
Unnati Gupta
ClusterRoleBindings
i) Create a clusterrolebindings
kubectl create clusterrolebinding <binding_name> --
clusterrole=<role_name> --user=<user>
v) Delete a clusterrolebinding
kubectl delete clusterrolebinding
<clusterrolebinding_name>
Unnati Gupta
ServiceAccount
i) Create an serviceaccount
kubectl create serviceaccount <serviceaccount-name>
Unnati Gupta
Ingress
i) Create an Ingress Resource
kubectl create ingress NAME --
rule=HOST/PATH=SERVICE:PORT [--
namespace=NAMESPACE]
Unnati Gupta
Cluster Configuration Command
i) Display the current context
kubectl config current-context
Unnati Gupta
Cluster Configuration Command
viii) Add user in kubeconfig file
kubectl config set-credentials USER_NAME [--
token=TOKEN] [--client-certificate=CERT_FILE] [--client-
key=KEY_FILE]
Unnati Gupta
ThankYou