back to listing index

Kubernetes commands cheat sheet – DevOps Process and Tools – Medium

[web search]
Original source (medium.com)
Tags: kubernetes
Clipped on: 2017-10-25

Image (Asset 1/7) alt=kubectl create -f pod.yml
#create pod from pod.yml file in namespace=testing
kubectl -namespace="testing" create -f pod.yml
#create replications from rc.yml( in default namespace)
kubectl create -f rc.yml
#create replications from rc.yml in name space called testing.
kubectl — namespace=”testing” create -f rc.yml
#Get all the existing name spaces( each app/group- maintain different namespace)
kubectl get ns
#Get the number of pods running
kubectl get pods
#Get the number of running pods with details of every pod
kubectl get pods — o wide
#Get details of all services running in console
kubectl get services
#Get services sorted by name
kubectl get services — sort-by=.metadata.name
#Get details of all nodes
kubectl get node
#Get details of resource quota per namespace
kubectl get quota
#To delete pod
kubectl delete pod -l name=<podname>
#To get details of replications controllers
kubectl get rc
#To resize the pods to 4.
kubectl resize — replicas=4 rc name=<podname>
Note: rc — represents the number of replicas — means number of pods
#To get all secrets (passwords,api credentials)
kubectl get secrets
#To list the endpoints
kubectl get ep
#will create a pod of name ubuntu and an rc from a docker image
kubectl run ubuntu — image=ubuntu
#List all rc in a namespace
kubectl get rc — namespace=”namespacedetails”
#Add a label to the pods.
kubectl label pods <podname>new-label=<labelname>
# to see the logs of the pod 
kubectl logs <pod-name>

Port and forwards:

#To forward to the port that service is running
kubectl port-forward servicename <port>
#Forward port of pod to local machine or forward to the pod running on port (80) on localhost/host machine.
kubectl port-forward <pod-name> <local/remote port> 
#To expose a service runs on port 80(port) inside a pod and the pod runs on port 8000 (target port)of the Replicas
kubetl expose rc <RCNAME> — port=<service port> — target-port=<pod port>