Kubernetes: Patch, label, annotate & scale
9 Kubernetes commands: Patch, label, annotate & scale. Click a command to see what each part does.
Kubernetes: Patch, label, annotate & scaleIndex
- Whole sheet137
- Basics: cluster, namespaces & resources17
- Get & list resources23
- Context & namespace3
- Find resources9
- Debug: describe, events, logs8
- Exec, port-forward, copy4
- Deploy, roll out, roll back, scale7
- Cleanup & nodes4
- Services, DNS & networking checks6
- Environment, config & secrets of workloads9
- Create, generate & apply YAML10
- Patch, label, annotate & scale9
- Delete & force delete6
- Nodes, scheduling & access control11
- Productivity: aliases, contexts & output11
Patch, label, annotate & scale9
kubectl patch deploy <deployment> -n <namespace> -p '{"spec":{"replicas":3}}'Patch a field (strategic merge)CautionWhat each part does
patchchange part of a live object without a full manifest-p '{...}'JSON or YAML snippet merged into the object
kubectl patch svc <service> --type=json -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]'Patch with a JSON patchCautionWhat each part does
--type=jsonRFC 6902 operations: add, remove, replace at a path-p '[...]'the operations
kubectl label po <pod> <key>=<value>; kubectl label po <pod> <key>-Add / remove a labelWhat each part does
<key>=<value>add (add --overwrite to change)<key>-remove the label; also a way to take a pod out of a service for debugging
kubectl annotate deploy <deployment> <key>='<value>' --overwriteAdd an annotationWhat each part does
annotatenon-identifying metadata read by tools--overwritereplace an existing value
kubectl autoscale deploy <deployment> --min=2 --max=10 --cpu-percent=80Autoscale a deploymentWhat each part does
autoscalecreate an HPA--min / --maxreplica bounds--cpu-percent=80target average CPU vs requests (pods need CPU requests)
kubectl set resources deploy <deployment> -c <container> --requests=cpu=100m,memory=128Mi --limits=memory=256MiSet CPU / memory requests and limitsCautionWhat each part does
set resourceschange resources in the pod template (rollout follows)--requests / --limitsvalues per container
kubectl rollout pause deploy/<deployment>; kubectl rollout resume deploy/<deployment>Pause and resume a rolloutWhat each part does
rollout pausestop rolling out; batch several changesrollout resumeroll them out together
kubectl rollout history deploy/<deployment> --revision=<n>Details of one rollout revisionWhat each part does
--revision=<n>show the pod template (images, env) of that revision before undoing to it
kubectl scale sts <statefulset> --replicas=<n> -n <namespace>Scale a StatefulSetWhat each part does
scale stspods are added/removed in order (highest ordinal first on scale-down)
Nothing matches.
My DevOps Playbook by Angelo John Calleja