Quick commands

Command Description Example
kubectl auth can-i Check whether an action is allowed kubectl auth can-i create pods --all-namespaces
kubectl get pods POD_NAME_HERE -o jsonpath='{.spec.containers[*].name}' List all contains in a pod  

kubectl

Patching

kubectl patch uses json patch, which means it’s possible to use replace, add, and remove operations.

Replace

This will replace the expiry of the zeroth index user in .spec.users to 2022-01-17.

kubectl patch pod pod-tgmgb --type='json' -p '[{"op":"replace","path":"/spec/users/0/expiry","value":"2022-01-17"}]'

Add

This will add a foo field onto the zeroth index user in .spec.users of value bar

kubectl patch pod pod-tgmgb --type='json' -p '[{"op":"add","path":"/spec/users/0/foo","value":"bar"}]'

Remove

This will remove the zeroth index user in .spec.users

kubectl patch pod pod-tgmgb --type='json' -p '[{"op":"remove","path":"/spec/users/0"}]'