Skip to content

Instantly share code, notes, and snippets.

@mahigupta
Last active August 9, 2019 20:52
Show Gist options
  • Save mahigupta/bb5e64f1e92ff1baaa91cdb57d269de7 to your computer and use it in GitHub Desktop.
Save mahigupta/bb5e64f1e92ff1baaa91cdb57d269de7 to your computer and use it in GitHub Desktop.
Kubectl quick command

kubectl


1. kubectl explain pod.spec
2.   kubectl explain pods
3.    kubectl create -f kubia-manual.yaml    — creating new pod from yaml file
4.   kubectl port-forward kubia-manual 8888:8080   — port forwarding to reach a manually added pod from outside
5.  kubectl label pods kubia-manual creation_method=manual  — adding label to a running container
6.  kubectl label pods kubia-manual-v2 env=debug --overwrite — edit label on a running container
7.  kubectl get pods -l creation_method=manual — filter pods using label value
8.  kubectl get pods -l env — pod with label key env
9.  kubectl get pods -l ‘!env’  — pod with no label key env
10.  kubectl get pods -l 'env in (prod,debug)'
11.  kubectl get pods -l 'env notin (prod,debug)'
12.  nodeSelector: gpu: "true"    — select a node with this label to put this container
13.   kubectl annotate pod kubia-manual example.com/author="Mahesh Gupta"    — add annotation to a pod
14.   kubectl get ns   — list all namespaces
15.  kubectl create namespace custom-namespace  —= create a custom namespace
16.   kubectl create -f kubia-manual -n custom-namespace   — add a pod in custom namespace
17.   kubectl delete po kubia-manual-v2  — delete a pod 
18.   kubectl delete po kubia-manual -n custom-namespace   — delete pod in a namespace 
19.    kubectl delete ns custom-namespace  — delete a namespace, all pod belonging to this namespace will also get deleted
20.  kubectl  delete po --all
21.  kubectl delete all --all  — delete all in current namespace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment