Skip to content

Kubernetes: Basics: cluster, namespaces & resources

17 Kubernetes commands: Basics: cluster, namespaces & resources. Click a command to see what each part does.

Index
17 items
Click a command to see what each part does.

Basics: cluster, namespaces & resources17

  • kubectl versionClient and cluster version

    What each part does

    1. kubectl versionclient and server versions; add --client for the client only (no cluster needed)
  • kubectl cluster-infoIs the cluster reachable?

    What each part does

    1. cluster-infoaddresses of the control plane and core services
  • kubectl get nodes -o wideList nodes

    What each part does

    1. get nodescluster nodes and whether they are Ready
    2. -o wideadd internal/external IP, OS, kernel, container runtime
  • kubectl get nsList namespaces

    What each part does

    1. get nsshort for get namespaces
  • kubectl create namespace <namespace>Create a namespace

    What each part does

    1. create namespacemake a new namespace (short: create ns)
  • kubectl get all -n <namespace>Everything in a namespace

    What each part does

    1. get allpods, services, deployments, replicasets, statefulsets, jobs… (not configmaps/secrets/ingress)
    2. -n <namespace>--namespace: which namespace
  • kubectl get deploy,svc,ing -n <namespace>Deployments, services and ingresses at once

    What each part does

    1. deploy,svc,ingcomma-separated resource types (short names)
  • kubectl get configmap,secret -n <namespace>ConfigMaps and Secrets

    What each part does

    1. configmap,secretconfig objects (secret values are not shown here)
  • kubectl get pods -wWatch pods change live

    What each part does

    1. -w--watch: keep printing updates until Ctrl+C
  • kubectl get pod <pod> -o yamlFull YAML of a live object

    What each part does

    1. -o yamloutput the whole object, including status
  • kubectl apply -f <file-or-dir>Create / update from a file

    What each part does

    1. applycreate or update to match the manifest
    2. -f--filename: a file, a folder or a URL (add -R for sub-folders)
  • kubectl delete -f <file-or-dir>Delete what a file definesDestructive

    What each part does

    1. delete -fdelete the objects listed in the manifest
  • kubectl edit deploy/<deployment>Edit a live object in your editorCaution

    What each part does

    1. editopens the object in $EDITOR (KUBE_EDITOR); saving applies it
  • kubectl label pod <pod> <key>=<value> --overwriteAdd or change a label

    What each part does

    1. labelset labels on objects
    2. <key>=<value>the label; <key>- (trailing dash) removes it
    3. --overwriteallow replacing an existing value
  • kubectl expose deployment <deployment> --port=80 --target-port=8080 --type=ClusterIPExpose a deployment as a service

    What each part does

    1. exposecreate a Service for a workload
    2. --port=80port the Service listens on
    3. --target-port=8080container port the traffic goes to
    4. --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 shell

    What each part does

    1. run tmpcreate a pod named tmp
    2. --rmdelete it when you exit
    3. -itinteractive terminal
    4. --restart=Nevera plain pod, not managed by anything
    5. --image=busybox:1.36small image with basic tools (nslookup, wget)
    6. -- shcommand to run
  • kubectl get secret <secret> -o jsonpath='{.data.<key>}' | base64 -dRead one value from a SecretCaution

    What each part does

    1. -o jsonpath=…print just that field
    2. {.data.<key>}the base64-encoded value of <key>
    3. | base64 -ddecode it to plain text

    Tip Prints a secret to your terminal.

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…