Command Description
k get pods --label-columns=mycustomlabel Affiche mycustomlabel
k get pods --show-labels Affiche tous les labels
k explain networkpolicy.spec.podSelector.MatchExpression Documentation
- -
k run -it dbgpod --image Execute un pod avec curl
k exec dbgpod -it -- /bin/sh Start a shell in existing pod
- -
k config set-context --current --namespace=ofa Change current namespace
--- ----
k apply -f my.yaml Update (or create) resource
k replace -f my.yaml Replace/recreate given resources
k get all -A List all resources from all namespaces
kubectl expose pod redis --port=6379 --name redis-service Expose redis port 6379
k create deploy testdep --image=nginx --replicas=3 Deploy 3 nginx
k scale deploy/mydep --replicas=2 Scale up/down
- -
k create serviceaccount alice Create alice account
k create role podgetter --verb=list --resource=pods
k create rolebinding podgetter-bindint --role podgetter --serviceaccount=alice Create rolebinding
k get sa -A Returns all serviceAccounts
k get sa -n myns Returns serviceAccounts for myns namespace
k --as=alice get pods Try to get pods with alice account
k --as=alice auth can-i list pods Check if bob can list pods
curl --insecure -H "Authorization: Bearer xxx" "https://kubernetes.k8s.home/api/v1/namespaces/unifi/pods" Query API with cUrl
- -
k patch pv pvc-id -p '{"spec":{"persistentVolumeReclaimPolicy":"Delete"}}' Change reclaim policy to delete Release Retained PV
kubectl patch storageclass gold -p '{"metadata": {"annotations":{"":"true"}}}' Change defaut storageclass
- -
for p in $(kubectl get pods --no-headers -o custom-columns="" grep -i "my-pods" ); do k get pod --show-labels $p; done


Create Token and kubeconfig: