Kubernetes Cheat Sheet

Cheetsheet for K8s with popular cli commands

What isKubernetes?

  • Kubernetes is a platform for managing containerized workloads.
  • Kubernetes orchestrates computing, networking and storage to provide a seamless portability across infrastructure providers.

Cluster Info

List all services

 kubectl get services                

List all pods

kubectl get pods                    

Watch nodes continuously

kubectl get nodes -w                

Get version information

kubectl version                     

Get cluster information

kubectl cluster-info                

Get the configuration

kubectl config view                 

Output information about a node

kubectl describe node <node>        

Pod and Container Info

List the current pods

kubectl get pods                         

Describe pod

kubectl describe pod <name>              

List the replication controllers

kubectl get rc                           

List the replication controllers in

kubectl get rc --namespace="<namespace>" 

Describe replication controller

kubectl describe rc <name>               

List the services

kubectl get svc                          

Describe service

kubectl describe svc <name>              

Interacting with Pods

Launch a pod called using image

 kubectl run <name> --image=<image-name>                             

Create a service described in

 kubectl create -f <manifest.yaml>                                   

Scale replication controller to instances

 kubectl scale --replicas=<count> rc <name>                          

Map port to port on replication controller

 kubectl expose rc <name> --port=<external> --target-port=<internal> 

Stopping Kubernetes

Delete pod

kubectl delete pod <name>                                         

Delete replication controller

kubectl delete rc <name>                                          

Delete service

kubectl delete svc <name>                                         

Stop all pods on

kubectl drain <n> --delete-local-data --force --ignore-daemonsets 

Remove from the cluster

kubectl delete node <name>                                        

Debugging

execute on selecting container <$container>

kubectl exec <service> <command> [-c <$container>] 

Get logs from service selecting container <$container>

kubectl logs -f <name> [-c <$container>]           

Watch the Kublet logs

watch -n 2 cat /var/log/kublet.log                 

Show metrics for nodes

kubectl top node                                   

Show metrics for pods

kubectl top pod                                    

Administration

Initialize your master node

kubeadm init                                              

Join a node to your Kubernetes cluster

kubeadm join --token <token> <master-ip>:<master-port>    

Create namespace

kubectl create namespace <namespace>                      

Allow Kubernetes master nodes to run pods

kubectl taint nodes --all node-role.kubernetes.io/master- 

Reset current state

kubeadm reset                                             

List all secrets

kubectl get secrets                                       

Leave a comment