Kubernetes kubectl commands part-2

Kubernetes Cheat Sheet

 

Viewing Resource Information (Cont. )

StorageClass

$ kubectl get sc
$ kubectl get sc -o yaml

MultipleResources

$ kubectl get svs .po
$ kubectl get deploy, no
$ kubectl get all
$ kubectl get all --all-namespaes

Changing Resource Attrbuters

Taint

$ kubectl taint[node-name] [taint-name]

Labels

$ kubectl label[node-name] disktype=ssd
$ kubectl label[pod-name] env=prod

Cordon/uncordon

$ kubectl cordon [node-name]
$ kubectl uncordon [node-name]

Drain

$ kubectl drain [node-name]

Nodes/pods

$ kubectl delete node [node-name]
$ kubectl delete pod [pode-name]
$ kubectl edit node [node-name]
$ kubectl edit pode [pode-name]

Deployments/Namespaces

$ kubectl edit deploy [deploy-name]
$ kubectl delete deploy [deploy-name]
$ kubectl expose deploy [deploy-name]--port=80 --type=nodeport
$ kubectl scale deploy [deploy-name]--replicas=5
$ kubectl delete ns
$ kubectl edit ns [ns-name]

Services 

$ kubectl edit svs [svs-name]
$ kubectl delete svs [svs-name]

Daemonsets

$ kubectl edit ds [ds-name] -n kube-system
$ kubectl delete ds [ds-name]

Service Accounts

$ kubectl edit sa [sa-name]
$ kubectl delete sa [sa-name]

Annotate

$ kubectl annotate po [pod-name] [annotation]
$ kubectl annotate no [node-name]
Adding Resources

Creatinga pod

$ kubectl create -f [name-of-file]
$ kubectl apply -f [name-of-file]
$ kubectl run [pod-name] --imag=nginx --restart=never
$ kubectl run [pod-name] --generator=run-pod/v1 --image=nginx
$ kubectl run [pod-name] --imag=nginx --restart=never

Creatinga Service

$ kubectl create svc nodeport [svc-name]--tcp=8080:80

Creatinga Deployment

$ kubectl cerate -f [name-of-file]
$ kubectl apply -f [name-of-file]
$ kubectl cerate deploy [deploy-name] --image=nginx

Interactive Pod

$ kubectl run [pod-name] --image=bsybox --rm -it --restart=never --sh

Output YAML to a file

$ kubectl create diploy [deploy-name --inage=nginx --dry-run -o yaml>
deploy.yaml
$ kubectl get po [pod-name] -o yaml --export
pod.yaml

Getting Help

$ kubectl -h
$ kubectl create -h
$ kubectl run -h
$ kubectl explain deploy.spec
Requests

API Call

$ kubectl get --raw /apis/metrics.io/

Cluster Info

$ kubectl config
$ kubectl cluster- info
$ kubectl get componentstatuses

You may also like...

Leave a Reply

Your email address will not be published.