Kubernetes: Basics: cluster, namespaces & resources
17 Kubernetes commands: Basics: cluster, namespaces & resources. Click a command to see what each part does.
Kubernetes: Basics: cluster, namespaces & resourcesIndex
- 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
Basics: cluster, namespaces & resources17
kubectl versionClient and cluster versionWhat each part does
kubectl versionclient and server versions; add --client for the client only (no cluster needed)
kubectl cluster-infoIs the cluster reachable?What each part does
cluster-infoaddresses of the control plane and core services
kubectl get nodes -o wideList nodesWhat each part does
get nodescluster nodes and whether they are Ready-o wideadd internal/external IP, OS, kernel, container runtime
kubectl get nsList namespacesWhat each part does
get nsshort for get namespaces
kubectl create namespace <namespace>Create a namespaceWhat each part does
create namespacemake a new namespace (short: create ns)
kubectl get all -n <namespace>Everything in a namespaceWhat each part does
get allpods, services, deployments, replicasets, statefulsets, jobs… (not configmaps/secrets/ingress)-n <namespace>--namespace: which namespace
kubectl get deploy,svc,ing -n <namespace>Deployments, services and ingresses at onceWhat each part does
deploy,svc,ingcomma-separated resource types (short names)
kubectl get configmap,secret -n <namespace>ConfigMaps and SecretsWhat each part does
configmap,secretconfig objects (secret values are not shown here)
kubectl get pods -wWatch pods change liveWhat each part does
-w--watch: keep printing updates until Ctrl+C
kubectl get pod <pod> -o yamlFull YAML of a live objectWhat each part does
-o yamloutput the whole object, including status
kubectl apply -f <file-or-dir>Create / update from a fileWhat each part does
applycreate or update to match the manifest-f--filename: a file, a folder or a URL (add -R for sub-folders)
kubectl delete -f <file-or-dir>Delete what a file definesDestructiveWhat each part does
delete -fdelete the objects listed in the manifest
kubectl edit deploy/<deployment>Edit a live object in your editorCautionWhat each part does
editopens the object in $EDITOR (KUBE_EDITOR); saving applies it
kubectl label pod <pod> <key>=<value> --overwriteAdd or change a labelWhat each part does
labelset labels on objects<key>=<value>the label; <key>- (trailing dash) removes it--overwriteallow replacing an existing value
kubectl expose deployment <deployment> --port=80 --target-port=8080 --type=ClusterIPExpose a deployment as a serviceWhat each part does
exposecreate a Service for a workload--port=80port the Service listens on--target-port=8080container port the traffic goes to--type=ClusterIPClusterIP (default, in-cluster), NodePort or LoadBalancer
kubectl run tmp --rm -it --restart=Never --image=busybox:1.36 -- shThrow-away debug pod with a shellWhat each part does
run tmpcreate a pod named tmp--rmdelete it when you exit-itinteractive terminal--restart=Nevera plain pod, not managed by anything--image=busybox:1.36small image with basic tools (nslookup, wget)-- shcommand to run
kubectl get secret <secret> -o jsonpath='{.data.<key>}' | base64 -dRead one value from a SecretCautionWhat each part does
-o jsonpath=…print just that field{.data.<key>}the base64-encoded value of <key>| base64 -ddecode it to plain text
Tip Prints a secret to your terminal.
Nothing matches.
My DevOps Playbook by Angelo John Calleja