Commands

kubectl

Get pods

$ kubectl get pod
$ kubectl get pod --show-labels -o wide

Get config

$ kubectl config get-contexts

Get deployment

$ kubectl get deployment -n <namespace>

Get service

$ kubectl get svc -n <namespace>

Port forwarding

$ kubectl port-forward <pod-name> 5000:5000 -n data

Access to pod

$ kubectl exec -it <pod-name> bash

Get log of pod

$ kubectl logs <pod-name>

Delete pod

$ kubectl delete <pod-name>

Create namespace

$ kubectl create namespace <namspace>

Get PersistentVolume / PersistentVolumeClaim / StorageClass

# persistentVolume
$ kubectl get pv
# persistentVolumeClaim
$ kubectl get pvc -n <namespace>
# storageClass
$ kubectl get sc

Get the cluster roles

$ kubectl get clusterroles

Create new user

$ kubectl create clusterrolebinding jane --clusterrole=edit --user=jane

Get context

$ kubectl config get-contexts

Create new context

$ kubectl config set-context <new-context-name> --cluster <cluster-from-old-context> --user <auth-info-from-old-context>

Delete the context

$ kubectl config delete-context <old-context-name>

Label the node

kubectl label node hostname node-role.kubernetes.io/worker=worker

kubectx

List all the kubeconfigs

$ kubectx

Select the kubeconfig

$ kubectx <kubeconfig name>