kubectl#
Context and Configuration#
Command |
Action |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
client + server version |
|
cluster endpoints |
Tools that streamline this:
Get / Describe#
Command |
Action |
|---|---|
|
pods in current namespace |
|
all namespaces |
|
|
|
|
|
custom output |
|
most resource types |
|
|
|
|
|
|
|
Apply / Delete#
Command |
Action |
|---|---|
|
|
|
directory of manifests |
|
|
|
|
|
delete by name |
|
by selector |
|
delete all in namespace |
|
|
|
|
|
|
|
Exec / Logs / Port-Forward#
Command |
Action |
|---|---|
|
shell into pod |
|
|
|
logs |
|
follow |
|
|
|
|
|
pick any pod from deploy |
|
|
|
|
|
Debug#
Command |
Action |
|---|---|
|
|
|
|
|
|
|
RBAC check |
|
all my permissions |
|
CPU / memory (needs metrics-server) |
|
Resources#
Command |
Action |
|---|---|
|
list all resource kinds |
|
all groups + versions |
|
schema docs (any field) |
|
Patching#
$ kubectl patch deploy web -p '{"spec":{"replicas":3}}'
$ kubectl patch deploy web --type=json \
-p='[{"op":"replace","path":"/spec/replicas","value":3}]'
$ kubectl edit deploy web
Useful kubeconfig Tricks#
$ KUBECONFIG=~/.kube/config:~/work/kubeconfig kubectl config view --flatten > merged
$ mv merged ~/.kube/config
$ kubectl config set-context --current --namespace=mynamespace
$ kubectl --kubeconfig=/path/to/cfg get pods
JSONPath Examples#
$ kubectl get pods -o jsonpath='{.items[*].metadata.name}'
$ kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}'
$ kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.addresses[?(@.type=="ExternalIP")].address}{"\n"}{end}'