kubectl <command>
-h
kubectl explain RESOURCE [options]
e.g.: kubectl explain deployment.spec.template
export now="--force --grace-period 0"
export do="--dry-run=client -o yaml"
kubectl delete pod NAME $now
kubectl create configmap NAME [--from-file=[key=]source]
[--from-literal=key1=value1] [--dry-run=server|client|none] [options]
e.g.: kubectl create configmap sample-cm $do > sample-cm.yaml
kubectl create deployment NAME --image=IMAGE -- [COMMAND] [args...] [options]
e.g.: kubectl create deployment NAME --image=image $do > my-deployment.yaml
kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]] [options]
e.g. kubectl create ingress example-ingress --rule=hello-world.info/=web:8080 $do > hello-world-ingress.yaml
kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...] [options]
e.g.: kubectl run nginx --image=nginx $do > my-pod.yaml
kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client|none] [options]
e.g. kubectl create role testadmin --verb='*' --resource='*' $do > my-role.yaml
kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [--serviceaccount=namespace:serviceaccountname] [--dry-run=server|client|none] [options]
e.g. ubectl create rolebinding testadminbinding --role=testadmin --serviceaccount=test1:myaccount $do > tastadmin-role-binding.yaml
kubectl create secret [flags] [options]
e.g. kubectl create secret generic NAME --from-literal=password=very_complex $do > literal.yaml
kubectl create service [flags] [options]
e.g. kubectl create service TYPE NAME --tcp=80 $do > my-svc.yaml
or e.g. kubectl expose deployment NAME --type=NodePort --port=9000
kubectl exec --it POD_NAME --container CONTAINER_NAME -- sh
or
kubectl exec -i -t POD_NAME --container CONTAINER_NAME -- sh -c "clear; (bash || ash || sh)"
kubectl run -it --image nicolaka/netshoot dns-test --restart=Never --rm
https://kubernetes.io/docs/reference/kubectl/cheatsheet/
kubectl taint nodes NODE_NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N [options]
Pod specification:
tolerations:
- key: "key1"
# operator: "Equal" # set only if `value` not specified
value: "value1"
effect: "NoSchedule"
effect:
NoSchedule
|PreferNoSchedule
|NoExecute
Select node by label in pod specification:
spec:
containers:
- ...
nodeSelector:
<LabelKey>: <LabelValue>
Select node by name in pod specification:
spec:
containers:
- ...
nodeName: <NodeName>
kubectl scale --replicas=<REPLICAS> deployment/<DEPLOYMENT_NAME>
Check rollout status: kubectl rollout status deployment/<DEPLOYMENT_NAME>
Check rollout history: kubectl rollout history deployment/<DEPLOYMENT_NAME>
Check revision details: kubectl rollout history deployment/<DEPLOYMENT_NAME>
--revison=
Rollback to previous revision: kubectl rollout undo deployment/<DEPLOYMENT_NAME>
Rollback to specific revision: kubectl rollout undo deployment/<DEPLOYMENT_NAME> --to-revision=<NUMBER>
https://kubernetes.io/docs/tasks/debug/debug-cluster/crictl/
Used to debug container runtimes on a node.