Show Menu
Cheatography

Kubernetes Cheat Sheet (DRAFT) by

Kubernetes Commands and Tips and Tricks

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Pod Commands

kubectl get nodes
Get list of all nodes
kubectl get pods --all-­nam­espaces
Get list of all pods in all namespaces
kubectl apply -f calico.yaml
Apply a Calico Container Networking Config­uration
kubectl init --apis­erv­er-­adv­ert­ise­-ad­dre­s<p­vt_­ip_­add­r> --pod-­net­wor­k-c­idr­=19­2.1­68.0.0/16
Initialise current node as Manager with Calico Container N/w soln
kubectl get pods --all-­nam­espaces -o wide
List pods and their nodes (ip addrs)

Service Commands

Create Service
kubectl create service nodeport nginx --tcp=­80:80
List services
kubectl get svc
Nodeport is the type of service endpoint being created. It allows an external client to access the service (One out of 3 types).

Admini­str­ation Commands

kubectl get all
Get all resources in a namespace
kubectl get all -A
Get all resources in ALL Namespaces
kubectl config view
Show Kubectl context.

Deployment Commands

kubectl get deploy­ments
Get deploy­ments

Kubectl Commands

kubectl config
Context and Config­ura­tion.
view,
get-contexts,
current-context,
use-context,
set-cluster,
set-credentials,
set-context,
use-context,
unset
kubectl apply
Create and Update Resources.
-f ./my1.yaml -f ./my2.yaml
kubectl create
Create a single instance.
deployment nginx --image=nginx
cronjob
job
kubectl explain
Get docume­nta­tion, Schema Definition
Pod
Pod.sp­ec.c­on­tainers
kubectl get
Viewing & Finding Resources
services
pods --all-namespaces
pods -o wide
deployment my-dep
pod my-pod-o yaml
kubectl describe
Obtain real-time info abt resources
nodes my-node
pods my-pod
kubectl set
kubectl rollout
kubectl replace
kubectl expose
kubectl label
kubectl annotate
kubectl patch
kubectl edit
kubectl scale
kubectl delete
kubectl logs
kubectl run
kubectl attach
kubectl port-f­orward
kubectl exec
kubectl debug
kubectl top
kubectl cp
kubectl cordon
kubectl drain
kubectl uncordon
kubectl cluste­r-info
kubectl taint

Google Cloud

Create a K8s Cluster
gcloud container clusters create [CLUST­ER-­NAME]
Authen­ticate Cluster to interact with it
gcloud container clusters get-cr­ede­ntials [CLUST­ER-­NAME]
Create a deployment on created cluster
kubectl create deployment [DEPL_­NAME] --imag­e=g­cr.i­o/­[PA­TH]­/[I­MG_­NAM­E]:­[TAG]
Expose created deployment to external network i.e Create Service
kubectl expose deployment [DEPL_­NAME] --type­=Lo­adB­alancer --port [PORT]
Inspect created Service
kubectl get service
Delete Cluster
gcloud container clusters delete [CLUST­ER-­NAME]