Specimen No. 1563 · Habitat H4 · DevOps & IT

Kubernetes from Zero · Workloads & Troubleshooting 10 of 14 · Lesson 22

Kubernetes from Zero, part 22: troubleshooting Services, DNS, stuck deletes and sick nodes

Fix a Service with no endpoints, a DNS lookup that fails, an object stuck in Terminating, a NotReady node and an evicted Pod, then debug with kubectl debug.

WILDNESS1 / 5 · TAMED
Verified: Broke and fixed each case on a two-node kind v0.33.0 cluster, node v1.37.0, kubectl v1.37.2, 10 Nov 2026Only claimed: Default eviction thresholds and the node controller's timers come from the Kubernetes docs
In a deep-navy cut-paper ship's hold, a teal lantern on a hook lights a coiled cream rope snagged on a wooden cleat by a rust-red knot, beside stacked crates and a slate-blue ship's wheel.
Generated cover art. Not a photo.

In part 21 you fixed Pods that would not start. This part covers what breaks around a healthy Pod: a Service that sends traffic nowhere, a name that does not resolve, an object that refuses to go away, a node that drops out, and a Pod the kubelet throws off its node. You will also meet kubectl debug, which gives you a shell next to a container that has none. Every failure here was caused on purpose and fixed on a two-node kind cluster (kind v0.33.0, node image v1.37.0) with kubectl v1.37.2. You need the cluster from part 3 with one worker node, and the k8s-from-zero namespace.

What you will build

You will deploy one small web app, break it in five different ways, and read the evidence each time before you fix it. The habit to build is the same every time: follow the request or the object step by step, and ask the API what it thinks at each step. For a Service, that path has four stops.

Four checks in order: the name resolves, the Service has endpoints (highlighted, the most common failure), targetPort matches the port the container listens on, and the Pod answers on its own IP. Each check shows the command to run, the symptom we saw, and the fix.

A Service with no endpoints answers nothing

A Service finds its Pods with a label selector (part 8). If the selector matches no Pod, the Service still exists and still has a ClusterIP, but its EndpointSlice is empty, and every connection fails. The official Debug Services page walks through the same checks in more detail.

Save this as web.yaml. It has two mistakes on purpose: a typo in the selector, and a targetPort that nginx does not listen on.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: k8s-from-zero
  labels:
    app.kubernetes.io/name: web
spec:
  replicas: 2
  selector:
    matchLabels:
      app.kubernetes.io/name: web
  template:
    metadata:
      labels:
        app.kubernetes.io/name: web
    spec:
      containers:
        - name: web
          image: nginx:1.29-alpine
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: web
  namespace: k8s-from-zero
spec:
  selector:
    app.kubernetes.io/name: wbe   # typo on purpose
  ports:
    - port: 80
      targetPort: 8080            # wrong on purpose: nginx listens on 80

Try it: five failures and their fixes

  1. Apply the app, start a client Pod, and call the Service:
bash
kubectl apply -f web.yaml
kubectl run client -n k8s-from-zero --image=busybox:1.37 -- sleep 3600
kubectl rollout status deployment/web -n k8s-from-zero --timeout=90s
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web

Explain this command

kubectl apply -f web.yaml
kubectl run client -n k8s-from-zero --image=busybox:1.37 -- sleep 3600
kubectl rollout status deployment/web -n k8s-from-zero --timeout=90s
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. apply Apply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.
  3. -f Short form of --filename. The file, directory or URL that contains the configuration to apply.
  4. web.yaml The file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f web.yaml
kubectl run client -n k8s-from-zero --image=busybox:1.37 -- sleep 3600
kubectl rollout status deployment/web -n k8s-from-zero --timeout=90s
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. apply Apply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.
  3. -f Short form of --filename. The file, directory or URL that contains the configuration to apply.
  4. web.yaml The file named by --filename. apply creates the objects or updates them to match this file.

Explain this command

kubectl apply -f web.yaml
kubectl run client -n k8s-from-zero --image=busybox:1.37 -- sleep 3600
kubectl rollout status deployment/web -n k8s-from-zero --timeout=90s
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. run Create and run a particular image in a pod. The run docs say this is intended for simple development and debug use.
  3. client The Pod name passed to kubectl run.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --image=busybox:1.37 The container image, set here to busybox:1.37.
  7. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  8. sleep Shell. Waits the given number of seconds.
  9. 3600 How many seconds sleep waits before the next command runs.
Explain this command
kubectl apply -f web.yaml
kubectl run client -n k8s-from-zero --image=busybox:1.37 -- sleep 3600
kubectl rollout status deployment/web -n k8s-from-zero --timeout=90s
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. run Create and run a particular image in a pod. The run docs say this is intended for simple development and debug use.
  3. client The Pod name passed to kubectl run.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --image=busybox:1.37 The container image, set here to busybox:1.37.
  7. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  8. sleep Shell. Waits the given number of seconds.
  9. 3600 How many seconds sleep waits before the next command runs.

Explain this command

kubectl apply -f web.yaml
kubectl run client -n k8s-from-zero --image=busybox:1.37 -- sleep 3600
kubectl rollout status deployment/web -n k8s-from-zero --timeout=90s
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. rollout The command group for rollout actions.
  3. status Show the status of the rollout. By default it watches the latest rollout until it is done. You can pass --watch=false if you do not want to wait.
  4. deployment/web The resource written as type/name: deployment/web.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. --timeout=90s How long to wait before giving up. This command passes 90s.
Explain this command
kubectl apply -f web.yaml
kubectl run client -n k8s-from-zero --image=busybox:1.37 -- sleep 3600
kubectl rollout status deployment/web -n k8s-from-zero --timeout=90s
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. rollout The command group for rollout actions.
  3. status Show the status of the rollout. By default it watches the latest rollout until it is done. You can pass --watch=false if you do not want to wait.
  4. deployment/web The resource written as type/name: deployment/web.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. --timeout=90s How long to wait before giving up. This command passes 90s.

Explain this command

kubectl apply -f web.yaml
kubectl run client -n k8s-from-zero --image=busybox:1.37 -- sleep 3600
kubectl rollout status deployment/web -n k8s-from-zero --timeout=90s
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://web The URL the command requests.
Explain this command
kubectl apply -f web.yaml
kubectl run client -n k8s-from-zero --image=busybox:1.37 -- sleep 3600
kubectl rollout status deployment/web -n k8s-from-zero --timeout=90s
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://web The URL the command requests.
deployment.apps/web created
service/web created
pod/client created
...
deployment "web" successfully rolled out
wget: can't connect to remote host (10.96.129.138): Connection refused
command terminated with exit code 1

The name resolved (wget found an IP), so DNS is fine. The next stop is endpoints:

bash
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl describe service web -n k8s-from-zero
kubectl get pods -n k8s-from-zero --show-labels

Explain this command

kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl describe service web -n k8s-from-zero
kubectl get pods -n k8s-from-zero --show-labels
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. endpointslice The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. -l Short form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.
  7. kubernetes.io/service-name=web The label selector passed to -l. It keeps only the objects whose labels match this query.
Explain this command
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl describe service web -n k8s-from-zero
kubectl get pods -n k8s-from-zero --show-labels
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. endpointslice The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. -l Short form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.
  7. kubernetes.io/service-name=web The label selector passed to -l. It keeps only the objects whose labels match this query.

Explain this command

kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl describe service web -n k8s-from-zero
kubectl get pods -n k8s-from-zero --show-labels
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. describe Show details of a specific resource or group of resources. The describe docs say this includes related resources such as events or controllers.
  3. service The resource type.
  4. web The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
Explain this command
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl describe service web -n k8s-from-zero
kubectl get pods -n k8s-from-zero --show-labels
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. describe Show details of a specific resource or group of resources. The describe docs say this includes related resources such as events or controllers.
  3. service The resource type.
  4. web The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.

Explain this command

kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl describe service web -n k8s-from-zero
kubectl get pods -n k8s-from-zero --show-labels
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pods The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --show-labels Add a LABELS column that shows every label on each object.
Explain this command
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl describe service web -n k8s-from-zero
kubectl get pods -n k8s-from-zero --show-labels
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pods The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --show-labels Add a LABELS column that shows every label on each object.
NAME        ADDRESSTYPE   PORTS     ENDPOINTS   AGE
web-hbx96   IPv4          <unset>   <unset>     1s
...
Selector:                 app.kubernetes.io/name=wbe
...
TargetPort:               8080/TCP
Endpoints:                
...
NAME                   READY   STATUS    RESTARTS   AGE   LABELS
client                 1/1     Running   0          2s    run=client
web-86f79b74d9-f5vdk   1/1     Running   0          2s    app.kubernetes.io/name=web,pod-template-hash=86f79b74d9
web-86f79b74d9-tkwg6   1/1     Running   0          2s    app.kubernetes.io/name=web,pod-template-hash=86f79b74d9

ENDPOINTS <unset> and a selector of wbe against Pods labelled web: that is the bug. Fix the selector:

bash
kubectl patch service web -n k8s-from-zero -p '{"spec":{"selector":{"app.kubernetes.io/name":"web"}}}'
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web

Explain this command

kubectl patch service web -n k8s-from-zero -p '{"spec":{"selector":{"app.kubernetes.io/name":"web"}}}'
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. patch Update fields of a resource using a strategic merge patch, a JSON merge patch, or a JSON patch. The patch docs say JSON and YAML are accepted.
  3. service The resource type.
  4. web The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. -p Short form of --patch. The patch to apply, written here as JSON.
  8. '{"spec":{"selector":{"app.kubernetes.io/name":"web"}}}' The patch document, written as JSON. Only the fields it names are changed.
Explain this command
kubectl patch service web -n k8s-from-zero -p '{"spec":{"selector":{"app.kubernetes.io/name":"web"}}}'
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. patch Update fields of a resource using a strategic merge patch, a JSON merge patch, or a JSON patch. The patch docs say JSON and YAML are accepted.
  3. service The resource type.
  4. web The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. -p Short form of --patch. The patch to apply, written here as JSON.
  8. '{"spec":{"selector":{"app.kubernetes.io/name":"web"}}}' The patch document, written as JSON. Only the fields it names are changed.

Explain this command

kubectl patch service web -n k8s-from-zero -p '{"spec":{"selector":{"app.kubernetes.io/name":"web"}}}'
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. endpointslice The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. -l Short form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.
  7. kubernetes.io/service-name=web The label selector passed to -l. It keeps only the objects whose labels match this query.
Explain this command
kubectl patch service web -n k8s-from-zero -p '{"spec":{"selector":{"app.kubernetes.io/name":"web"}}}'
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. endpointslice The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. -l Short form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.
  7. kubernetes.io/service-name=web The label selector passed to -l. It keeps only the objects whose labels match this query.

Explain this command

kubectl patch service web -n k8s-from-zero -p '{"spec":{"selector":{"app.kubernetes.io/name":"web"}}}'
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://web The URL the command requests.
Explain this command
kubectl patch service web -n k8s-from-zero -p '{"spec":{"selector":{"app.kubernetes.io/name":"web"}}}'
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://web The URL the command requests.
service/web patched
NAME        ADDRESSTYPE   PORTS   ENDPOINTS               AGE
web-hbx96   IPv4          8080    10.244.1.2,10.244.1.3   9s
wget: can't connect to remote host (10.96.129.138): Connection refused
command terminated with exit code 1
  1. Endpoints exist now, and the error is the same. Look at the PORTS column: 8080. Ask a Pod which port it really listens on, and test the Pod directly on its own IP:
bash
kubectl exec -n k8s-from-zero deploy/web -- netstat -tln
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://$(kubectl get pods -n k8s-from-zero -l app.kubernetes.io/name=web -o jsonpath='{.items[0].status.podIP}'):80 | head -4

Explain this command

kubectl exec -n k8s-from-zero deploy/web -- netstat -tln
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://$(kubectl get pods -n k8s-from-zero -l app.kubernetes.io/name=web -o jsonpath='{.items[0].status.podIP}'):80 | head -4
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. deploy/web The resource written as type/name: deploy/web.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. netstat Print network connections and listening ports. The lesson uses it inside a container.
  8. -tln With netstat: TCP sockets (-t) that are listening (-l), with numeric addresses and ports (-n).
Explain this command
kubectl exec -n k8s-from-zero deploy/web -- netstat -tln
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://$(kubectl get pods -n k8s-from-zero -l app.kubernetes.io/name=web -o jsonpath='{.items[0].status.podIP}'):80 | head -4
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. deploy/web The resource written as type/name: deploy/web.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. netstat Print network connections and listening ports. The lesson uses it inside a container.
  8. -tln With netstat: TCP sockets (-t) that are listening (-l), with numeric addresses and ports (-n).

Explain this command

kubectl exec -n k8s-from-zero deploy/web -- netstat -tln
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://$(kubectl get pods -n k8s-from-zero -l app.kubernetes.io/name=web -o jsonpath='{.items[0].status.podIP}'):80 | head -4
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://$(kubectl get pods -n k8s-from-zero -l app.kubernetes.io/name=web -o jsonpath='{.items[0].status.podIP}'):80 The URL to fetch. The $(...) part prints the IP of the first web Pod with jsonpath, so the request goes straight to the Pod and skips the Service.
  12. | A shell pipe. The output of the command on the left becomes the input of the command on the right.
  13. head Shell. Print the first lines of its input.
  14. -4 How many lines from the start of the input head should print.
Explain this command
kubectl exec -n k8s-from-zero deploy/web -- netstat -tln
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://$(kubectl get pods -n k8s-from-zero -l app.kubernetes.io/name=web -o jsonpath='{.items[0].status.podIP}'):80 | head -4
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://$(kubectl get pods -n k8s-from-zero -l app.kubernetes.io/name=web -o jsonpath='{.items[0].status.podIP}'):80 The URL to fetch. The $(...) part prints the IP of the first web Pod with jsonpath, so the request goes straight to the Pod and skips the Service.
  12. | A shell pipe. The output of the command on the left becomes the input of the command on the right.
  13. head Shell. Print the first lines of its input.
  14. -4 How many lines from the start of the input head should print.
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      
tcp        0      0 :::80                   :::*                    LISTEN      
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>

The Pod answers on port 80, the Service sends to 8080. Point targetPort at 80:

bash
kubectl patch service web -n k8s-from-zero --type=json -p '[{"op":"replace","path":"/spec/ports/0/targetPort","value":80}]'
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web

Explain this command

kubectl patch service web -n k8s-from-zero --type=json -p '[{"op":"replace","path":"/spec/ports/0/targetPort","value":80}]'
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. patch Update fields of a resource using a strategic merge patch, a JSON merge patch, or a JSON patch. The patch docs say JSON and YAML are accepted.
  3. service The resource type.
  4. web The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. --type=json The patch type. json is a JSON patch document.
  8. -p Short form of --patch. The patch to apply, written here as JSON.
  9. '[{"op":"replace","path":"/spec/ports/0/targetPort","value":80}]' The patch document, written as JSON. Only the fields it names are changed.
Explain this command
kubectl patch service web -n k8s-from-zero --type=json -p '[{"op":"replace","path":"/spec/ports/0/targetPort","value":80}]'
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. patch Update fields of a resource using a strategic merge patch, a JSON merge patch, or a JSON patch. The patch docs say JSON and YAML are accepted.
  3. service The resource type.
  4. web The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. --type=json The patch type. json is a JSON patch document.
  8. -p Short form of --patch. The patch to apply, written here as JSON.
  9. '[{"op":"replace","path":"/spec/ports/0/targetPort","value":80}]' The patch document, written as JSON. Only the fields it names are changed.

Explain this command

kubectl patch service web -n k8s-from-zero --type=json -p '[{"op":"replace","path":"/spec/ports/0/targetPort","value":80}]'
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://web The URL the command requests.
Explain this command
kubectl patch service web -n k8s-from-zero --type=json -p '[{"op":"replace","path":"/spec/ports/0/targetPort","value":80}]'
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://web The URL the command requests.
service/web patched
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...

One honest detail: our first wget right after the patch still got Connection refused, and the same command three seconds later worked. kube-proxy needs a moment to program each node, so wait a second before you decide a fix did not work.

  1. DNS. Every Pod gets a /etc/resolv.conf that points at the cluster DNS Service and lists search domains for its own namespace. The DNS debugging guide starts with the same three checks: the client’s resolv.conf, a lookup, and the CoreDNS Pods.
bash
kubectl exec -n k8s-from-zero client -- cat /etc/resolv.conf
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.default

Explain this command

kubectl exec -n k8s-from-zero client -- cat /etc/resolv.conf
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.default
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. cat Print the contents of a file.
  8. /etc/resolv.conf The file path printed by cat inside the container.
Explain this command
kubectl exec -n k8s-from-zero client -- cat /etc/resolv.conf
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.default
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. cat Print the contents of a file.
  8. /etc/resolv.conf The file path printed by cat inside the container.

Explain this command

kubectl exec -n k8s-from-zero client -- cat /etc/resolv.conf
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.default
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. nslookup A DNS lookup tool in the busybox image. It asks the cluster DNS server for the name that follows.
  8. web.k8s-from-zero.svc.cluster.local The Service's full DNS name: service.namespace.svc.cluster.local.
Explain this command
kubectl exec -n k8s-from-zero client -- cat /etc/resolv.conf
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.default
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. nslookup A DNS lookup tool in the busybox image. It asks the cluster DNS server for the name that follows.
  8. web.k8s-from-zero.svc.cluster.local The Service's full DNS name: service.namespace.svc.cluster.local.

Explain this command

kubectl exec -n k8s-from-zero client -- cat /etc/resolv.conf
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.default
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://web.default The URL the command requests.
Explain this command
kubectl exec -n k8s-from-zero client -- cat /etc/resolv.conf
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.default
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://web.default The URL the command requests.
search k8s-from-zero.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
options ndots:5
Server:		10.96.0.10
Address:	10.96.0.10:53

Name:	web.k8s-from-zero.svc.cluster.local
Address: 10.96.129.138
wget: bad address 'web.default'
command terminated with exit code 1

bad address means the name did not resolve, which is different from Connection refused, where the name resolved and nothing answered. Here the cause is the namespace: web.default asks for a Service web in default, and ours lives in k8s-from-zero. Use the full name <service>.<namespace>.svc.cluster.local when you test. busybox nslookup with a short name also tries every search domain and prints an NXDOMAIN line for each one that misses, even when the lookup succeeds, so the full name gives cleaner output.

Now break DNS for the whole cluster by scaling CoreDNS to zero (do this only on your own lab cluster):

bash
kubectl scale deployment coredns -n kube-system --replicas=0
kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.k8s-from-zero
kubectl exec -n k8s-from-zero client -- nslookup -timeout=2 web.k8s-from-zero.svc.cluster.local

Explain this command

kubectl scale deployment coredns -n kube-system --replicas=0
kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.k8s-from-zero
kubectl exec -n k8s-from-zero client -- nslookup -timeout=2 web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. scale Set a new size for a deployment, replica set, replication controller, or stateful set.
  3. deployment The resource type.
  4. coredns The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. kube-system The namespace name.
  7. --replicas=0 The new desired number of replicas. The scale command says --replicas is required.
Explain this command
kubectl scale deployment coredns -n kube-system --replicas=0
kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.k8s-from-zero
kubectl exec -n k8s-from-zero client -- nslookup -timeout=2 web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. scale Set a new size for a deployment, replica set, replication controller, or stateful set.
  3. deployment The resource type.
  4. coredns The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. kube-system The namespace name.
  7. --replicas=0 The new desired number of replicas. The scale command says --replicas is required.

Explain this command

kubectl scale deployment coredns -n kube-system --replicas=0
kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.k8s-from-zero
kubectl exec -n k8s-from-zero client -- nslookup -timeout=2 web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. endpointslice The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. kube-system The namespace name.
  6. -l Short form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.
  7. kubernetes.io/service-name=kube-dns The label selector passed to -l. It keeps only the objects whose labels match this query.
Explain this command
kubectl scale deployment coredns -n kube-system --replicas=0
kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.k8s-from-zero
kubectl exec -n k8s-from-zero client -- nslookup -timeout=2 web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. endpointslice The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. kube-system The namespace name.
  6. -l Short form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.
  7. kubernetes.io/service-name=kube-dns The label selector passed to -l. It keeps only the objects whose labels match this query.

Explain this command

kubectl scale deployment coredns -n kube-system --replicas=0
kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.k8s-from-zero
kubectl exec -n k8s-from-zero client -- nslookup -timeout=2 web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://web.k8s-from-zero The URL the command requests.
Explain this command
kubectl scale deployment coredns -n kube-system --replicas=0
kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.k8s-from-zero
kubectl exec -n k8s-from-zero client -- nslookup -timeout=2 web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. wget A small HTTP client in the busybox image. It fetches the URL that follows.
  8. -qO- Quiet mode, and write the response to standard output (-O -) instead of a file.
  9. -T With wget, the network timeout in seconds.
  10. 3 Give up after 3 seconds.
  11. http://web.k8s-from-zero The URL the command requests.

Explain this command

kubectl scale deployment coredns -n kube-system --replicas=0
kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.k8s-from-zero
kubectl exec -n k8s-from-zero client -- nslookup -timeout=2 web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. nslookup A DNS lookup tool in the busybox image. It asks the cluster DNS server for the name that follows.
  8. -timeout=2 With busybox nslookup, wait at most 2 seconds for an answer.
  9. web.k8s-from-zero.svc.cluster.local The Service's full DNS name: service.namespace.svc.cluster.local.
Explain this command
kubectl scale deployment coredns -n kube-system --replicas=0
kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns
kubectl exec -n k8s-from-zero client -- wget -qO- -T 3 http://web.k8s-from-zero
kubectl exec -n k8s-from-zero client -- nslookup -timeout=2 web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. nslookup A DNS lookup tool in the busybox image. It asks the cluster DNS server for the name that follows.
  8. -timeout=2 With busybox nslookup, wait at most 2 seconds for an answer.
  9. web.k8s-from-zero.svc.cluster.local The Service's full DNS name: service.namespace.svc.cluster.local.
deployment.apps/coredns scaled
NAME             ADDRESSTYPE   PORTS     ENDPOINTS   AGE
kube-dns-gq9wr   IPv4          <unset>   <unset>     3m9s
wget: bad address 'web.k8s-from-zero'
command terminated with exit code 1
;; connection timed out; no servers could be reached

nslookup: write to '10.96.0.10': Connection refused
command terminated with exit code 1

The kube-dns Service has no endpoints, the same failure as step 1, one level down. Scale CoreDNS back and check the lookup again:

bash
kubectl scale deployment coredns -n kube-system --replicas=2
kubectl rollout status deployment/coredns -n kube-system --timeout=90s
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local

Explain this command

kubectl scale deployment coredns -n kube-system --replicas=2
kubectl rollout status deployment/coredns -n kube-system --timeout=90s
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. scale Set a new size for a deployment, replica set, replication controller, or stateful set.
  3. deployment The resource type.
  4. coredns The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. kube-system The namespace name.
  7. --replicas=2 The new desired number of replicas. The scale command says --replicas is required.
Explain this command
kubectl scale deployment coredns -n kube-system --replicas=2
kubectl rollout status deployment/coredns -n kube-system --timeout=90s
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. scale Set a new size for a deployment, replica set, replication controller, or stateful set.
  3. deployment The resource type.
  4. coredns The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. kube-system The namespace name.
  7. --replicas=2 The new desired number of replicas. The scale command says --replicas is required.

Explain this command

kubectl scale deployment coredns -n kube-system --replicas=2
kubectl rollout status deployment/coredns -n kube-system --timeout=90s
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. rollout The command group for rollout actions.
  3. status Show the status of the rollout. By default it watches the latest rollout until it is done. You can pass --watch=false if you do not want to wait.
  4. deployment/coredns The resource written as type/name: deployment/coredns.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. kube-system The namespace name.
  7. --timeout=90s How long to wait before giving up. This command passes 90s.
Explain this command
kubectl scale deployment coredns -n kube-system --replicas=2
kubectl rollout status deployment/coredns -n kube-system --timeout=90s
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. rollout The command group for rollout actions.
  3. status Show the status of the rollout. By default it watches the latest rollout until it is done. You can pass --watch=false if you do not want to wait.
  4. deployment/coredns The resource written as type/name: deployment/coredns.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. kube-system The namespace name.
  7. --timeout=90s How long to wait before giving up. This command passes 90s.

Explain this command

kubectl scale deployment coredns -n kube-system --replicas=2
kubectl rollout status deployment/coredns -n kube-system --timeout=90s
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. nslookup A DNS lookup tool in the busybox image. It asks the cluster DNS server for the name that follows.
  8. web.k8s-from-zero.svc.cluster.local The Service's full DNS name: service.namespace.svc.cluster.local.
Explain this command
kubectl scale deployment coredns -n kube-system --replicas=2
kubectl rollout status deployment/coredns -n kube-system --timeout=90s
kubectl exec -n k8s-from-zero client -- nslookup web.k8s-from-zero.svc.cluster.local
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. client The object name.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. nslookup A DNS lookup tool in the busybox image. It asks the cluster DNS server for the name that follows.
  8. web.k8s-from-zero.svc.cluster.local The Service's full DNS name: service.namespace.svc.cluster.local.
deployment.apps/coredns scaled
...
deployment "coredns" successfully rolled out
Server:		10.96.0.10
Address:	10.96.0.10:53

Name:	web.k8s-from-zero.svc.cluster.local
Address: 10.96.129.138
  1. An object stuck in Terminating. A finalizer is a name in metadata.finalizers that tells the API server: do not remove this object until someone takes this name off the list. Controllers use finalizers to clean up outside resources first, such as a cloud disk or a load balancer. When the controller is gone or broken, the object waits forever.

Top: kubectl delete only sets deletionTimestamp; the object stays while its finalizers list, highlighted, holds example.com/cleanup; once the list is empty the object is removed. Bottom: a namespace stays Terminating, and its conditions name the resource and the finalizer that hold it.

Save this as stuck.yaml. No controller in your cluster owns the name example.com/cleanup, so nothing will ever remove it:

apiVersion: v1
kind: ConfigMap
metadata:
  name: stuck
  namespace: k8s-from-zero
  finalizers:
    - example.com/cleanup   # nothing in this cluster will ever remove it
data:
  note: "I wait for a controller that does not exist"
bash
kubectl apply -f stuck.yaml
timeout 10 kubectl delete configmap stuck -n k8s-from-zero; echo exit=$?
kubectl get configmap stuck -n k8s-from-zero -o jsonpath='{.metadata.deletionTimestamp}{"  "}{.metadata.finalizers}{"\n"}'

Explain this command

kubectl apply -f stuck.yaml
timeout 10 kubectl delete configmap stuck -n k8s-from-zero; echo exit=$?
kubectl get configmap stuck -n k8s-from-zero -o jsonpath='{.metadata.deletionTimestamp}{"  "}{.metadata.finalizers}{"\n"}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. apply Apply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.
  3. -f Short form of --filename. The file, directory or URL that contains the configuration to apply.
  4. stuck.yaml The file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f stuck.yaml
timeout 10 kubectl delete configmap stuck -n k8s-from-zero; echo exit=$?
kubectl get configmap stuck -n k8s-from-zero -o jsonpath='{.metadata.deletionTimestamp}{"  "}{.metadata.finalizers}{"\n"}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. apply Apply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.
  3. -f Short form of --filename. The file, directory or URL that contains the configuration to apply.
  4. stuck.yaml The file named by --filename. apply creates the objects or updates them to match this file.

Explain this command

kubectl apply -f stuck.yaml
timeout 10 kubectl delete configmap stuck -n k8s-from-zero; echo exit=$?
kubectl get configmap stuck -n k8s-from-zero -o jsonpath='{.metadata.deletionTimestamp}{"  "}{.metadata.finalizers}{"\n"}'
  1. timeout Run a command and stop it after the given number of seconds.
  2. 10 Stop the command after 10 seconds. A finalizer keeps the ConfigMap, so the delete would otherwise wait for it indefinitely.
  3. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  4. delete Delete resources by file names, stdin, resources and names, or by resources and label selector.
  5. configmap The resource type.
  6. stuck The object name.
  7. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  8. k8s-from-zero The namespace name.
Explain this command
kubectl apply -f stuck.yaml
timeout 10 kubectl delete configmap stuck -n k8s-from-zero; echo exit=$?
kubectl get configmap stuck -n k8s-from-zero -o jsonpath='{.metadata.deletionTimestamp}{"  "}{.metadata.finalizers}{"\n"}'
  1. timeout Run a command and stop it after the given number of seconds.
  2. 10 Stop the command after 10 seconds. A finalizer keeps the ConfigMap, so the delete would otherwise wait for it indefinitely.
  3. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  4. delete Delete resources by file names, stdin, resources and names, or by resources and label selector.
  5. configmap The resource type.
  6. stuck The object name.
  7. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  8. k8s-from-zero The namespace name.

Explain this command

kubectl apply -f stuck.yaml
timeout 10 kubectl delete configmap stuck -n k8s-from-zero; echo exit=$?
kubectl get configmap stuck -n k8s-from-zero -o jsonpath='{.metadata.deletionTimestamp}{"  "}{.metadata.finalizers}{"\n"}'
  1. echo Print exit= and the exit status of the command before it.
  2. exit=$? The text to print. $? is the exit status of the last command; timeout returns 124 when it had to stop the command.
Explain this command
kubectl apply -f stuck.yaml
timeout 10 kubectl delete configmap stuck -n k8s-from-zero; echo exit=$?
kubectl get configmap stuck -n k8s-from-zero -o jsonpath='{.metadata.deletionTimestamp}{"  "}{.metadata.finalizers}{"\n"}'
  1. echo Print exit= and the exit status of the command before it.
  2. exit=$? The text to print. $? is the exit status of the last command; timeout returns 124 when it had to stop the command.

Explain this command

kubectl apply -f stuck.yaml
timeout 10 kubectl delete configmap stuck -n k8s-from-zero; echo exit=$?
kubectl get configmap stuck -n k8s-from-zero -o jsonpath='{.metadata.deletionTimestamp}{"  "}{.metadata.finalizers}{"\n"}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. configmap The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. stuck The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  8. jsonpath='{.metadata.deletionTimestamp}{" "}{.metadata.finalizers}{"\n"}' A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
Explain this command
kubectl apply -f stuck.yaml
timeout 10 kubectl delete configmap stuck -n k8s-from-zero; echo exit=$?
kubectl get configmap stuck -n k8s-from-zero -o jsonpath='{.metadata.deletionTimestamp}{"  "}{.metadata.finalizers}{"\n"}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. configmap The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. stuck The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  8. jsonpath='{.metadata.deletionTimestamp}{" "}{.metadata.finalizers}{"\n"}' A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
configmap/stuck created
configmap "stuck" deleted from k8s-from-zero namespace
exit=124
2026-11-10T21:26:49Z  ["example.com/cleanup"]

kubectl printed deleted and then waited until timeout stopped it (exit code 124). The object is still there with a deletionTimestamp. In a real cluster, first find out which controller owns the finalizer and why it is stuck; removing the finalizer by hand skips that controller’s cleanup. Here we know nobody owns it, so remove it:

bash
kubectl patch configmap stuck -n k8s-from-zero --type=merge -p '{"metadata":{"finalizers":null}}'
kubectl get configmap stuck -n k8s-from-zero

Explain this command

kubectl patch configmap stuck -n k8s-from-zero --type=merge -p '{"metadata":{"finalizers":null}}'
kubectl get configmap stuck -n k8s-from-zero
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. patch Update fields of a resource using a strategic merge patch, a JSON merge patch, or a JSON patch. The patch docs say JSON and YAML are accepted.
  3. configmap The resource type.
  4. stuck The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. --type=merge The patch type. merge is a JSON merge patch.
  8. -p Short form of --patch. The patch to apply, written here as JSON.
  9. '{"metadata":{"finalizers":null}}' The patch document, written as JSON. Only the fields it names are changed.
Explain this command
kubectl patch configmap stuck -n k8s-from-zero --type=merge -p '{"metadata":{"finalizers":null}}'
kubectl get configmap stuck -n k8s-from-zero
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. patch Update fields of a resource using a strategic merge patch, a JSON merge patch, or a JSON patch. The patch docs say JSON and YAML are accepted.
  3. configmap The resource type.
  4. stuck The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. --type=merge The patch type. merge is a JSON merge patch.
  8. -p Short form of --patch. The patch to apply, written here as JSON.
  9. '{"metadata":{"finalizers":null}}' The patch document, written as JSON. Only the fields it names are changed.

Explain this command

kubectl patch configmap stuck -n k8s-from-zero --type=merge -p '{"metadata":{"finalizers":null}}'
kubectl get configmap stuck -n k8s-from-zero
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. configmap The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. stuck The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
Explain this command
kubectl patch configmap stuck -n k8s-from-zero --type=merge -p '{"metadata":{"finalizers":null}}'
kubectl get configmap stuck -n k8s-from-zero
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. configmap The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. stuck The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
configmap/stuck patched
Error from server (NotFound): configmaps "stuck" not found

The same thing at namespace level is the classic “namespace stuck in Terminating”. Put the same ConfigMap in a fresh namespace and delete the namespace:

bash
kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'

Explain this command

kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. create Create a resource from a file or from stdin. Here it takes the subcommand that follows.
  3. namespace Create a namespace with the specified name. The synopsis is kubectl create namespace NAME [--dry-run=server|client|none].
  4. stuck-demo The object name.
Explain this command
kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. create Create a resource from a file or from stdin. Here it takes the subcommand that follows.
  3. namespace Create a namespace with the specified name. The synopsis is kubectl create namespace NAME [--dry-run=server|client|none].
  4. stuck-demo The object name.

Explain this command

kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'
  1. sed The stream editor. It rewrites its input line by line and prints the result.
  2. 's/namespace: k8s-from-zero/namespace: stuck-demo/' The substitution: replace namespace: k8s-from-zero with namespace: stuck-demo on each line of stuck.yaml.
  3. stuck.yaml The file named by --filename. apply creates the objects or updates them to match this file.
  4. | A shell pipe. The output of the command on the left becomes the input of the command on the right.
  5. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  6. apply Apply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.
  7. -f Short form of --filename. The file, directory or URL that contains the configuration to apply.
  8. - Read the manifest from standard input, here the output of sed.
Explain this command
kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'
  1. sed The stream editor. It rewrites its input line by line and prints the result.
  2. 's/namespace: k8s-from-zero/namespace: stuck-demo/' The substitution: replace namespace: k8s-from-zero with namespace: stuck-demo on each line of stuck.yaml.
  3. stuck.yaml The file named by --filename. apply creates the objects or updates them to match this file.
  4. | A shell pipe. The output of the command on the left becomes the input of the command on the right.
  5. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  6. apply Apply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.
  7. -f Short form of --filename. The file, directory or URL that contains the configuration to apply.
  8. - Read the manifest from standard input, here the output of sed.

Explain this command

kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. delete Delete resources by file names, stdin, resources and names, or by resources and label selector.
  3. namespace The resource type.
  4. stuck-demo The object name.
  5. --wait=false Return right away instead of waiting until the object is gone. The delete docs say --wait waits for resources to be gone, which includes waiting for finalizers.
Explain this command
kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. delete Delete resources by file names, stdin, resources and names, or by resources and label selector.
  3. namespace The resource type.
  4. stuck-demo The object name.
  5. --wait=false Return right away instead of waiting until the object is gone. The delete docs say --wait waits for resources to be gone, which includes waiting for finalizers.

Explain this command

kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. namespace The resource type.
  4. stuck-demo The object name.
Explain this command
kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. namespace The resource type.
  4. stuck-demo The object name.

Explain this command

kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. namespace The resource type.
  4. stuck-demo The object name.
  5. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  6. jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}' A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
Explain this command
kubectl create namespace stuck-demo
sed 's/namespace: k8s-from-zero/namespace: stuck-demo/' stuck.yaml | kubectl apply -f -
kubectl delete namespace stuck-demo --wait=false
kubectl get namespace stuck-demo
kubectl get namespace stuck-demo -o jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. namespace The resource type.
  4. stuck-demo The object name.
  5. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  6. jsonpath='{range .status.conditions[*]}{.type}={.status}: {.message}{"\n"}{end}' A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
namespace/stuck-demo created
configmap/stuck created
namespace "stuck-demo" deleted
NAME         STATUS        AGE
stuck-demo   Terminating   8s
NamespaceDeletionDiscoveryFailure=False: All resources successfully discovered
NamespaceDeletionGroupVersionParsingFailure=False: All legacy kube types successfully parsed
NamespaceDeletionContentFailure=False: All content successfully deleted, may be waiting on finalization
NamespaceContentRemaining=True: Some resources are remaining: configmaps. has 1 resource instances
NamespaceFinalizersRemaining=True: Some content in the namespace has finalizers remaining: example.com/cleanup in 1 resource instances

The conditions tell you exactly what to look for: one ConfigMap with the finalizer example.com/cleanup. Release it, and the namespace finishes on its own a few seconds later:

bash
kubectl patch configmap stuck -n stuck-demo --type=merge -p '{"metadata":{"finalizers":null}}'
kubectl get namespace stuck-demo

Explain this command

kubectl patch configmap stuck -n stuck-demo --type=merge -p '{"metadata":{"finalizers":null}}'
kubectl get namespace stuck-demo
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. patch Update fields of a resource using a strategic merge patch, a JSON merge patch, or a JSON patch. The patch docs say JSON and YAML are accepted.
  3. configmap The resource type.
  4. stuck The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. stuck-demo The namespace name.
  7. --type=merge The patch type. merge is a JSON merge patch.
  8. -p Short form of --patch. The patch to apply, written here as JSON.
  9. '{"metadata":{"finalizers":null}}' The patch document, written as JSON. Only the fields it names are changed.
Explain this command
kubectl patch configmap stuck -n stuck-demo --type=merge -p '{"metadata":{"finalizers":null}}'
kubectl get namespace stuck-demo
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. patch Update fields of a resource using a strategic merge patch, a JSON merge patch, or a JSON patch. The patch docs say JSON and YAML are accepted.
  3. configmap The resource type.
  4. stuck The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. stuck-demo The namespace name.
  7. --type=merge The patch type. merge is a JSON merge patch.
  8. -p Short form of --patch. The patch to apply, written here as JSON.
  9. '{"metadata":{"finalizers":null}}' The patch document, written as JSON. Only the fields it names are changed.

Explain this command

kubectl patch configmap stuck -n stuck-demo --type=merge -p '{"metadata":{"finalizers":null}}'
kubectl get namespace stuck-demo
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. namespace The resource type.
  4. stuck-demo The object name.
Explain this command
kubectl patch configmap stuck -n stuck-demo --type=merge -p '{"metadata":{"finalizers":null}}'
kubectl get namespace stuck-demo
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. namespace The resource type.
  4. stuck-demo The object name.
configmap/stuck patched
Error from server (NotFound): namespaces "stuck-demo" not found
  1. A node that stops reporting. Each kubelet renews a Lease in kube-node-lease as its heartbeat, and the node controller marks a node whose heartbeats stop (Nodes). On kind a node is a container, so you can stop its kubelet:
bash
date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done

Explain this command

date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. date Print the date and time. -u +%T prints the UTC time of day.
  2. -u With date, print the time in UTC.
  3. +%T The date output format: the time of day as HH:MM:SS.
Explain this command
date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. date Print the date and time. -u +%T prints the UTC time of day.
  2. -u With date, print the time in UTC.
  3. +%T The date output format: the time of day as HH:MM:SS.

Explain this command

date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. docker The Docker CLI. On this lab, kind node processes run as containers, so docker exec reaches the node.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. k8s-ep22-worker The worker node's container. Each kind node is a Docker container named after the cluster; your cluster name replaces k8s-ep22.
  4. systemctl Control a systemd service on the node. The lesson uses it to stop or start kubelet.
  5. stop The systemctl action: stop the service.
  6. kubelet The systemd service to act on: the kubelet, the agent on each node.
Explain this command
date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. docker The Docker CLI. On this lab, kind node processes run as containers, so docker exec reaches the node.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. k8s-ep22-worker The worker node's container. Each kind node is a Docker container named after the cluster; your cluster name replaces k8s-ep22.
  4. systemctl Control a systemd service on the node. The lesson uses it to stop or start kubelet.
  5. stop The systemctl action: stop the service.
  6. kubelet The systemd service to act on: the kubelet, the agent on each node.

Explain this command

date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. for A shell loop. It runs the body once for each value after in.
  2. i The loop variable.
  3. in Introduces the list of values the loop walks through.
  4. $(seq 1 14) The numbers 1 to 14, so the loop runs 14 times.
Explain this command
date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. for A shell loop. It runs the body once for each value after in.
  2. i The loop variable.
  3. in Introduces the list of values the loop walks through.
  4. $(seq 1 14) The numbers 1 to 14, so the loop runs 14 times.

Explain this command

date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. do Starts the loop body.
  2. echo Print one line for this pass of the loop.
  3. "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)" The line to print: the UTC time, then the node's row from kubectl get without the header line.
Explain this command
date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. do Starts the loop body.
  2. echo Print one line for this pass of the loop.
  3. "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)" The line to print: the UTC time, then the node's row from kubectl get without the header line.

Explain this command

date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. sleep Shell. Waits the given number of seconds.
  2. 5 How many seconds sleep waits before the next command runs.
Explain this command
date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. sleep Shell. Waits the given number of seconds.
  2. 5 How many seconds sleep waits before the next command runs.

Explain this command

date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. done Ends the loop.
Explain this command
date -u +%T; docker exec k8s-ep22-worker systemctl stop kubelet
for i in $(seq 1 14); do echo "$(date -u +%T) $(kubectl get node k8s-ep22-worker --no-headers)"; sleep 5; done
  1. done Ends the loop.
21:27:27
21:27:27 k8s-ep22-worker   Ready   <none>   4m10s   v1.37.0
...
21:28:13 k8s-ep22-worker   Ready   <none>   4m56s   v1.37.0
21:28:18 k8s-ep22-worker   NotReady   <none>   5m1s   v1.37.0
...

Your cluster name replaces k8s-ep22 in the container name. In our run the node controller set the condition 49 seconds after the kubelet stopped. Now read what the control plane did:

bash
kubectl describe node k8s-ep22-worker
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web -o jsonpath='{range .items[*].endpoints[*]}{.addresses[0]} ready={.conditions.ready}{"\n"}{end}'

Explain this command

kubectl describe node k8s-ep22-worker
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web -o jsonpath='{range .items[*].endpoints[*]}{.addresses[0]} ready={.conditions.ready}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. describe Show details of a specific resource or group of resources. The describe docs say this includes related resources such as events or controllers.
  3. node The resource type.
  4. k8s-ep22-worker The worker node's name. Our lab cluster is k8s-ep22; your node name starts with your cluster's name.
Explain this command
kubectl describe node k8s-ep22-worker
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web -o jsonpath='{range .items[*].endpoints[*]}{.addresses[0]} ready={.conditions.ready}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. describe Show details of a specific resource or group of resources. The describe docs say this includes related resources such as events or controllers.
  3. node The resource type.
  4. k8s-ep22-worker The worker node's name. Our lab cluster is k8s-ep22; your node name starts with your cluster's name.

Explain this command

kubectl describe node k8s-ep22-worker
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web -o jsonpath='{range .items[*].endpoints[*]}{.addresses[0]} ready={.conditions.ready}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. endpointslice The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. -l Short form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.
  7. kubernetes.io/service-name=web The label selector passed to -l. It keeps only the objects whose labels match this query.
  8. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  9. jsonpath='{range .items[*].endpoints[*]}{.addresses[0]} ready={.conditions.ready}{"\n"}{end}' A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
Explain this command
kubectl describe node k8s-ep22-worker
kubectl get endpointslice -n k8s-from-zero -l kubernetes.io/service-name=web -o jsonpath='{range .items[*].endpoints[*]}{.addresses[0]} ready={.conditions.ready}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. endpointslice The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. -l Short form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.
  7. kubernetes.io/service-name=web The label selector passed to -l. It keeps only the objects whose labels match this query.
  8. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  9. jsonpath='{range .items[*].endpoints[*]}{.addresses[0]} ready={.conditions.ready}{"\n"}{end}' A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
Taints:             node.kubernetes.io/unreachable:NoExecute
                    node.kubernetes.io/unreachable:NoSchedule
...
  Ready            Unknown   Tue, 10 Nov 2026 23:23:48 +0200   Tue, 10 Nov 2026 23:28:16 +0200   NodeStatusUnknown   Kubelet stopped posting node status.
...
10.244.1.2 ready=false
10.244.1.3 ready=false

The node’s conditions went to Unknown and it got two taints. The Service stopped sending traffic to its Pods at once, even though kubectl get pods still showed them Running and 1/1: that status was last written by the kubelet that is now silent. The Pods are not deleted yet, because every Pod gets a default toleration for these taints (Taints and Tolerations):

bash
kubectl get pod -n k8s-from-zero -l app.kubernetes.io/name=web -o jsonpath='{range .items[0].spec.tolerations[*]}{.key} {.effect} {.tolerationSeconds}{"\n"}{end}'

Explain this command

kubectl get pod -n k8s-from-zero -l app.kubernetes.io/name=web -o jsonpath='{range .items[0].spec.tolerations[*]}{.key} {.effect} {.tolerationSeconds}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pod The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. -l Short form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.
  7. app.kubernetes.io/name=web The label selector passed to -l. It keeps only the objects whose labels match this query.
  8. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  9. jsonpath='{range .items[0].spec.tolerations[*]}{.key} {.effect} {.tolerationSeconds}{"\n"}{end}' A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
Explain this command
kubectl get pod -n k8s-from-zero -l app.kubernetes.io/name=web -o jsonpath='{range .items[0].spec.tolerations[*]}{.key} {.effect} {.tolerationSeconds}{"\n"}{end}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pod The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. -l Short form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.
  7. app.kubernetes.io/name=web The label selector passed to -l. It keeps only the objects whose labels match this query.
  8. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  9. jsonpath='{range .items[0].spec.tolerations[*]}{.key} {.effect} {.tolerationSeconds}{"\n"}{end}' A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
node.kubernetes.io/not-ready NoExecute 300
node.kubernetes.io/unreachable NoExecute 300

Five minutes after the node went Unknown, the Pods were marked for deletion and the Deployment made new ones:

bash
kubectl get pods -n k8s-from-zero -o wide
kubectl get events -n k8s-from-zero --field-selector reason=FailedScheduling -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.message

Explain this command

kubectl get pods -n k8s-from-zero -o wide
kubectl get events -n k8s-from-zero --field-selector reason=FailedScheduling -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.message
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pods The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  7. wide An output format: the default table plus more columns. The get examples say it adds more information, such as the node name. The lesson's output adds IP and NODE.
Explain this command
kubectl get pods -n k8s-from-zero -o wide
kubectl get events -n k8s-from-zero --field-selector reason=FailedScheduling -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.message
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pods The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  7. wide An output format: the default table plus more columns. The get examples say it adds more information, such as the node name. The lesson's output adds IP and NODE.

Explain this command

kubectl get pods -n k8s-from-zero -o wide
kubectl get events -n k8s-from-zero --field-selector reason=FailedScheduling -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.message
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. events The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --field-selector Filter the list by field. The get docs treat --field-selector as separate from a label selector.
  7. reason=FailedScheduling The field query passed to --field-selector: reason=FailedScheduling.
  8. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  9. custom-columns=OBJECT:.involvedObject.name,MESSAGE:.message A custom table. custom-columns is an output format. The get examples write each column as a heading, a colon, and a JSONPath.
Explain this command
kubectl get pods -n k8s-from-zero -o wide
kubectl get events -n k8s-from-zero --field-selector reason=FailedScheduling -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.message
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. events The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --field-selector Filter the list by field. The get docs treat --field-selector as separate from a label selector.
  7. reason=FailedScheduling The field query passed to --field-selector: reason=FailedScheduling.
  8. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  9. custom-columns=OBJECT:.involvedObject.name,MESSAGE:.message A custom table. custom-columns is an output format. The get examples write each column as a heading, a colon, and a JSONPath.
NAME                   READY   STATUS        RESTARTS   AGE     IP           NODE              NOMINATED NODE   READINESS GATES
client                 1/1     Terminating   0          8m41s   10.244.1.4   k8s-ep22-worker   <none>           <none>
web-86f79b74d9-cjsf2   0/1     Pending       0          30s     <none>       <none>            <none>           <none>
web-86f79b74d9-f5vdk   1/1     Terminating   0          8m41s   10.244.1.3   k8s-ep22-worker   <none>           <none>
web-86f79b74d9-plcl5   0/1     Pending       0          30s     <none>       <none>            <none>           <none>
web-86f79b74d9-tkwg6   1/1     Terminating   0          8m41s   10.244.1.2   k8s-ep22-worker   <none>           <none>
OBJECT                 MESSAGE
web-86f79b74d9-cjsf2   0/2 nodes are available: 2 node(s) had untolerated taint(s). preemption: 0/2 nodes are available: 2 Preemption is not helpful for scheduling.
...

The replacements stay Pending: the only other node is the control plane, which carries a taint that keeps normal Pods off. The bare client Pod has no controller, so nothing replaces it. Start the kubelet again and the node recovers; the Pending Pods land on it.

bash
docker exec k8s-ep22-worker systemctl start kubelet
kubectl get nodes

Explain this command

docker exec k8s-ep22-worker systemctl start kubelet
kubectl get nodes
  1. docker The Docker CLI. On this lab, kind node processes run as containers, so docker exec reaches the node.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. k8s-ep22-worker The worker node's container. Each kind node is a Docker container named after the cluster; your cluster name replaces k8s-ep22.
  4. systemctl Control a systemd service on the node. The lesson uses it to stop or start kubelet.
  5. start The systemctl action: start the service again.
  6. kubelet The systemd service to act on: the kubelet, the agent on each node.
Explain this command
docker exec k8s-ep22-worker systemctl start kubelet
kubectl get nodes
  1. docker The Docker CLI. On this lab, kind node processes run as containers, so docker exec reaches the node.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. k8s-ep22-worker The worker node's container. Each kind node is a Docker container named after the cluster; your cluster name replaces k8s-ep22.
  4. systemctl Control a systemd service on the node. The lesson uses it to stop or start kubelet.
  5. start The systemctl action: start the service again.
  6. kubelet The systemd service to act on: the kubelet, the agent on each node.

Explain this command

docker exec k8s-ep22-worker systemctl start kubelet
kubectl get nodes
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. nodes The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
Explain this command
docker exec k8s-ep22-worker systemctl start kubelet
kubectl get nodes
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. nodes The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
NAME                     STATUS   ROLES           AGE   VERSION
k8s-ep22-control-plane   Ready    control-plane   11m   v1.37.0
k8s-ep22-worker          Ready    <none>          11m   v1.37.0

Eviction: the kubelet takes Pods off its own node

The last case is the opposite one: a healthy kubelet removing Pods to protect its node. The kubelet watches signals such as free memory, free disk and free inodes, and when one crosses a hard threshold it sets a condition such as DiskPressure and evicts Pods (Node-pressure Eviction). The documented defaults on Linux are memory.available<100Mi, nodefs.available<10%, imagefs.available<15% and inodesFree<5%. Pods using more than they request go first.

Left: a node that stops reporting goes NotReady after about 50 seconds, gets unreachable taints, its Pods leave the EndpointSlice, and after the default 300-second toleration (highlighted) they are evicted. Right: the kubelet compares signals with hard thresholds, sets MemoryPressure or DiskPressure and evicts Pods; it also evicts a single Pod that exceeds its ephemeral-storage limit.

kind turns the disk thresholds off, which you can read from the kubelet’s live config:

bash
kubectl get --raw /api/v1/nodes/k8s-ep22-worker/proxy/configz | python3 -c 'import json,sys; c=json.load(sys.stdin)["kubeletconfig"]; print(json.dumps({k:c.get(k) for k in ["evictionHard","evictionPressureTransitionPeriod"]}, indent=2))'

Explain this command

kubectl get --raw /api/v1/nodes/k8s-ep22-worker/proxy/configz | python3 -c 'import json,sys; c=json.load(sys.stdin)["kubeletconfig"]; print(json.dumps({k:c.get(k) for k in ["evictionHard","evictionPressureTransitionPeriod"]}, indent=2))'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. --raw Make a raw HTTP request to the Kubernetes API path that follows.
  4. /api/v1/nodes/k8s-ep22-worker/proxy/configz The API path. The API server proxies it to the kubelet on k8s-ep22-worker, whose configz endpoint returns the kubelet's running configuration.
  5. | A shell pipe. The output of the command on the left becomes the input of the command on the right.
  6. python3 The Python interpreter. The lesson uses a one-line script to pick fields from JSON.
  7. -c With python3, run the program given as a string.
  8. 'import json,sys; c=json.load(sys.stdin)["kubeletconfig"]; print(json.dumps({k:c.get(k) for k in ["evictionHard","evictionPressureTransitionPeriod"]}, indent=2))' A short Python program: read the JSON, take kubeletconfig, and print only evictionHard and evictionPressureTransitionPeriod.
Explain this command
kubectl get --raw /api/v1/nodes/k8s-ep22-worker/proxy/configz | python3 -c 'import json,sys; c=json.load(sys.stdin)["kubeletconfig"]; print(json.dumps({k:c.get(k) for k in ["evictionHard","evictionPressureTransitionPeriod"]}, indent=2))'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. --raw Make a raw HTTP request to the Kubernetes API path that follows.
  4. /api/v1/nodes/k8s-ep22-worker/proxy/configz The API path. The API server proxies it to the kubelet on k8s-ep22-worker, whose configz endpoint returns the kubelet's running configuration.
  5. | A shell pipe. The output of the command on the left becomes the input of the command on the right.
  6. python3 The Python interpreter. The lesson uses a one-line script to pick fields from JSON.
  7. -c With python3, run the program given as a string.
  8. 'import json,sys; c=json.load(sys.stdin)["kubeletconfig"]; print(json.dumps({k:c.get(k) for k in ["evictionHard","evictionPressureTransitionPeriod"]}, indent=2))' A short Python program: read the JSON, take kubeletconfig, and print only evictionHard and evictionPressureTransitionPeriod.
{
  "evictionHard": {
    "imagefs.available": "0%",
    "nodefs.available": "0%",
    "nodefs.inodesFree": "0%"
  },
  "evictionPressureTransitionPeriod": "5m0s"
}

So on kind we cannot show a real DiskPressure. What we can show is the per-Pod version: a container can have an ephemeral-storage limit, and the kubelet evicts the Pod when its writable layer, logs and emptyDir volumes go over it (Resource Management). Save this as disk-hog.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: disk-hog
  namespace: k8s-from-zero
spec:
  restartPolicy: Never
  containers:
    - name: hog
      image: busybox:1.37
      command: ["sh", "-c", "dd if=/dev/zero of=/tmp/fill bs=1M count=60; echo wrote 60Mi; sleep 3600"]
      resources:
        limits:
          ephemeral-storage: 20Mi
bash
kubectl apply -f disk-hog.yaml
kubectl get pod disk-hog -n k8s-from-zero
kubectl get pod disk-hog -n k8s-from-zero -o jsonpath='{.status.phase} {.status.reason}: {.status.message}{"\n"}'

Explain this command

kubectl apply -f disk-hog.yaml
kubectl get pod disk-hog -n k8s-from-zero
kubectl get pod disk-hog -n k8s-from-zero -o jsonpath='{.status.phase} {.status.reason}: {.status.message}{"\n"}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. apply Apply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.
  3. -f Short form of --filename. The file, directory or URL that contains the configuration to apply.
  4. disk-hog.yaml The file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f disk-hog.yaml
kubectl get pod disk-hog -n k8s-from-zero
kubectl get pod disk-hog -n k8s-from-zero -o jsonpath='{.status.phase} {.status.reason}: {.status.message}{"\n"}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. apply Apply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.
  3. -f Short form of --filename. The file, directory or URL that contains the configuration to apply.
  4. disk-hog.yaml The file named by --filename. apply creates the objects or updates them to match this file.

Explain this command

kubectl apply -f disk-hog.yaml
kubectl get pod disk-hog -n k8s-from-zero
kubectl get pod disk-hog -n k8s-from-zero -o jsonpath='{.status.phase} {.status.reason}: {.status.message}{"\n"}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pod The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. disk-hog The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
Explain this command
kubectl apply -f disk-hog.yaml
kubectl get pod disk-hog -n k8s-from-zero
kubectl get pod disk-hog -n k8s-from-zero -o jsonpath='{.status.phase} {.status.reason}: {.status.message}{"\n"}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pod The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. disk-hog The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.

Explain this command

kubectl apply -f disk-hog.yaml
kubectl get pod disk-hog -n k8s-from-zero
kubectl get pod disk-hog -n k8s-from-zero -o jsonpath='{.status.phase} {.status.reason}: {.status.message}{"\n"}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pod The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. disk-hog The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  8. jsonpath='{.status.phase} {.status.reason}: {.status.message}{"\n"}' A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
Explain this command
kubectl apply -f disk-hog.yaml
kubectl get pod disk-hog -n k8s-from-zero
kubectl get pod disk-hog -n k8s-from-zero -o jsonpath='{.status.phase} {.status.reason}: {.status.message}{"\n"}'
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pod The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. disk-hog The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. -o Short form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.
  8. jsonpath='{.status.phase} {.status.reason}: {.status.message}{"\n"}' A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
pod/disk-hog created
NAME       READY   STATUS   RESTARTS   AGE
disk-hog   0/1     Error    0          30s
Failed Evicted: Pod ephemeral local storage usage exceeds the total limit of containers 20Mi. 

STATUS Error hides the reason; the status.reason field says Evicted. Evicted Pods stay as Failed objects until you delete them:

bash
kubectl get pods -n k8s-from-zero --field-selector=status.phase=Failed
kubectl delete pods -n k8s-from-zero --field-selector=status.phase=Failed

Explain this command

kubectl get pods -n k8s-from-zero --field-selector=status.phase=Failed
kubectl delete pods -n k8s-from-zero --field-selector=status.phase=Failed
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pods The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --field-selector=status.phase=Failed Filter the list by field. The get docs treat --field-selector as separate from a label selector. The value after the equals sign is the field query.
Explain this command
kubectl get pods -n k8s-from-zero --field-selector=status.phase=Failed
kubectl delete pods -n k8s-from-zero --field-selector=status.phase=Failed
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. get Display one or many resources. kubectl get prints a table of the most important information about the resources you name.
  3. pods The resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --field-selector=status.phase=Failed Filter the list by field. The get docs treat --field-selector as separate from a label selector. The value after the equals sign is the field query.

Explain this command

kubectl get pods -n k8s-from-zero --field-selector=status.phase=Failed
kubectl delete pods -n k8s-from-zero --field-selector=status.phase=Failed
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. delete Delete resources by file names, stdin, resources and names, or by resources and label selector.
  3. pods The resource type.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --field-selector=status.phase=Failed Filter the list by field. The get docs treat --field-selector as separate from a label selector. The value after the equals sign is the field query.
Explain this command
kubectl get pods -n k8s-from-zero --field-selector=status.phase=Failed
kubectl delete pods -n k8s-from-zero --field-selector=status.phase=Failed
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. delete Delete resources by file names, stdin, resources and names, or by resources and label selector.
  3. pods The resource type.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --field-selector=status.phase=Failed Filter the list by field. The get docs treat --field-selector as separate from a label selector. The value after the equals sign is the field query.
NAME       READY   STATUS   RESTARTS   AGE
disk-hog   0/1     Error    0          38s
pod "disk-hog" deleted from k8s-from-zero namespace

kubectl debug adds a shell where there is none

Many production images contain only the app, with no shell, so kubectl exec ... -- sh fails. kubectl debug adds an ephemeral container (a temporary container added to a running Pod for inspection, which is never restarted automatically) with the tools you need (Debug Running Pods). Save this as noshell.yaml; the pause image contains a single program and nothing else:

apiVersion: v1
kind: Pod
metadata:
  name: noshell
  namespace: k8s-from-zero
spec:
  containers:
    - name: app
      image: registry.k8s.io/pause:3.10
bash
kubectl apply -f noshell.yaml
kubectl exec -n k8s-from-zero noshell -- sh

Explain this command

kubectl apply -f noshell.yaml
kubectl exec -n k8s-from-zero noshell -- sh
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. apply Apply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.
  3. -f Short form of --filename. The file, directory or URL that contains the configuration to apply.
  4. noshell.yaml The file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f noshell.yaml
kubectl exec -n k8s-from-zero noshell -- sh
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. apply Apply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.
  3. -f Short form of --filename. The file, directory or URL that contains the configuration to apply.
  4. noshell.yaml The file named by --filename. apply creates the objects or updates them to match this file.

Explain this command

kubectl apply -f noshell.yaml
kubectl exec -n k8s-from-zero noshell -- sh
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. noshell The object name: a Pod whose image has no shell.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. sh A shell. The command that follows runs inside it.
Explain this command
kubectl apply -f noshell.yaml
kubectl exec -n k8s-from-zero noshell -- sh
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. exec Execute a command in a container. The synopsis is kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...].
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. noshell The object name: a Pod whose image has no shell.
  6. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  7. sh A shell. The command that follows runs inside it.
pod/noshell created
error: Internal error occurred: Internal error occurred: error executing command in container: ... exec: "sh": executable file not found in $PATH

Add a busybox container that shares the app container’s process namespace with --target:

bash
kubectl debug -it -n k8s-from-zero noshell --image=busybox:1.37 --target=app -c shell

Explain this command

kubectl debug -it -n k8s-from-zero noshell --image=busybox:1.37 --target=app -c shell
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. debug Debug a resource by creating a copy with extra tools, or by adding an ephemeral container to a running Pod. The debug docs cover --image, --target, --copy-to and --share-processes.
  3. -it Short form of --stdin and --tty together, for an interactive session.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. noshell The object name: a Pod whose image has no shell.
  7. --image=busybox:1.37 The container image, set here to busybox:1.37.
  8. --target=app The existing container whose process namespace the ephemeral container should join. The debugging guide on kubernetes.io says the container runtime must support it.
  9. -c Short form of --container. For kubectl debug, this names the new ephemeral container.
  10. shell The name for the new ephemeral container: shell.
Explain this command
kubectl debug -it -n k8s-from-zero noshell --image=busybox:1.37 --target=app -c shell
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. debug Debug a resource by creating a copy with extra tools, or by adding an ephemeral container to a running Pod. The debug docs cover --image, --target, --copy-to and --share-processes.
  3. -it Short form of --stdin and --tty together, for an interactive session.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. noshell The object name: a Pod whose image has no shell.
  7. --image=busybox:1.37 The container image, set here to busybox:1.37.
  8. --target=app The existing container whose process namespace the ephemeral container should join. The debugging guide on kubernetes.io says the container runtime must support it.
  9. -c Short form of --container. For kubectl debug, this names the new ephemeral container.
  10. shell The name for the new ephemeral container: shell.
Targeting container "app". If you don't see processes from this container it may be because the container runtime doesn't support this feature.
All commands and output from this session will be recorded in container logs, including credentials and sensitive information passed through the command prompt.
If you don't see a command prompt, try pressing enter.
/ # ps
PID   USER     TIME  COMMAND
    1 65535     0:00 /pause
   39 root      0:00 sh
   49 root      0:00 ps
/ # exit
Session ended, the ephemeral container will not be restarted but may be reattached using 'kubectl attach noshell -c shell -n k8s-from-zero -i -t' if it is still running

You can see the app’s process as PID 1, and the app’s filesystem is reachable at /proc/1/root. Note the warning: the session is recorded in the container’s logs, so do not type secrets into it.

For node problems, kubectl debug node/<name> starts a Pod on that node in the host’s process, network and IPC namespaces, with the node’s root filesystem mounted at /host (node debugging):

bash
kubectl debug node/k8s-ep22-worker -n k8s-from-zero --image=busybox:1.37 -- chroot /host sh -c 'systemctl is-active kubelet containerd; df -h /var | tail -1; journalctl -u kubelet --no-pager -n 3 -o cat | cut -c1-110'
kubectl logs -n k8s-from-zero node-debugger-k8s-ep22-worker-q64wp

Explain this command

kubectl debug node/k8s-ep22-worker -n k8s-from-zero --image=busybox:1.37 -- chroot /host sh -c 'systemctl is-active kubelet containerd; df -h /var | tail -1; journalctl -u kubelet --no-pager -n 3 -o cat | cut -c1-110'
kubectl logs -n k8s-from-zero node-debugger-k8s-ep22-worker-q64wp
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. debug Debug a resource by creating a copy with extra tools, or by adding an ephemeral container to a running Pod. The debug docs cover --image, --target, --copy-to and --share-processes.
  3. node/k8s-ep22-worker The resource written as type/name: node/k8s-ep22-worker.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --image=busybox:1.37 The container image, set here to busybox:1.37.
  7. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  8. chroot Run a command with a different root filesystem. The node-debug docs use chroot /host to see the node's own files.
  9. /host Where kubectl debug mounts the node's root filesystem in the debugging Pod. chroot into it to use the node's own tools.
  10. sh A shell. The command that follows runs inside it.
  11. -c An argument of sh. It tells sh to run the command string that follows.
  12. 'systemctl is-active kubelet containerd; df -h /var | tail -1; journalctl -u kubelet --no-pager -n 3 -o cat | cut -c1-110' The commands run on the node: are kubelet and containerd active, how full /var is, and the last three kubelet log lines, cut to 110 characters.
Explain this command
kubectl debug node/k8s-ep22-worker -n k8s-from-zero --image=busybox:1.37 -- chroot /host sh -c 'systemctl is-active kubelet containerd; df -h /var | tail -1; journalctl -u kubelet --no-pager -n 3 -o cat | cut -c1-110'
kubectl logs -n k8s-from-zero node-debugger-k8s-ep22-worker-q64wp
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. debug Debug a resource by creating a copy with extra tools, or by adding an ephemeral container to a running Pod. The debug docs cover --image, --target, --copy-to and --share-processes.
  3. node/k8s-ep22-worker The resource written as type/name: node/k8s-ep22-worker.
  4. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  5. k8s-from-zero The namespace name.
  6. --image=busybox:1.37 The container image, set here to busybox:1.37.
  7. -- Ends kubectl's flags. The exec examples say to use two dashes so the command's own flags are read as that command's flags.
  8. chroot Run a command with a different root filesystem. The node-debug docs use chroot /host to see the node's own files.
  9. /host Where kubectl debug mounts the node's root filesystem in the debugging Pod. chroot into it to use the node's own tools.
  10. sh A shell. The command that follows runs inside it.
  11. -c An argument of sh. It tells sh to run the command string that follows.
  12. 'systemctl is-active kubelet containerd; df -h /var | tail -1; journalctl -u kubelet --no-pager -n 3 -o cat | cut -c1-110' The commands run on the node: are kubelet and containerd active, how full /var is, and the last three kubelet log lines, cut to 110 characters.

Explain this command

kubectl debug node/k8s-ep22-worker -n k8s-from-zero --image=busybox:1.37 -- chroot /host sh -c 'systemctl is-active kubelet containerd; df -h /var | tail -1; journalctl -u kubelet --no-pager -n 3 -o cat | cut -c1-110'
kubectl logs -n k8s-from-zero node-debugger-k8s-ep22-worker-q64wp
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. logs Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional.
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. node-debugger-k8s-ep22-worker-q64wp The debugging Pod's name from our run. kubectl debug prints the name; yours ends in a different random suffix.
Explain this command
kubectl debug node/k8s-ep22-worker -n k8s-from-zero --image=busybox:1.37 -- chroot /host sh -c 'systemctl is-active kubelet containerd; df -h /var | tail -1; journalctl -u kubelet --no-pager -n 3 -o cat | cut -c1-110'
kubectl logs -n k8s-from-zero node-debugger-k8s-ep22-worker-q64wp
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. logs Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional.
  3. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  4. k8s-from-zero The namespace name.
  5. node-debugger-k8s-ep22-worker-q64wp The debugging Pod's name from our run. kubectl debug prints the name; yours ends in a different random suffix.
Creating debugging pod node-debugger-k8s-ep22-worker-q64wp with container debugger on node k8s-ep22-worker.
active
active
/dev/vdb        128G   57G   71G  45% /var
I1110 21:35:39.513647    2002 server.go:177] "Pod update broadcasted" podUID="78ff0c00-0be6-4fb6-b9fc-dbe14cf8
...

Your Pod name ends in a different random suffix. The docs warn that this Pod is not privileged and that chroot /host can fail; on our kind node it worked, and --profile=sysadmin is the documented option when it does not. A node debugger Pod is broad access to the machine, so delete it when you are done: kubectl delete pod -n k8s-from-zero node-debugger-k8s-ep22-worker-q64wp.

Clean up the lab:

bash
kubectl delete -f web.yaml -f noshell.yaml
kubectl delete pod client -n k8s-from-zero --wait=false

Explain this command

kubectl delete -f web.yaml -f noshell.yaml
kubectl delete pod client -n k8s-from-zero --wait=false
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. delete Delete resources by file names, stdin, resources and names, or by resources and label selector.
  3. -f Short form of --filename. For delete, the file that contains the resource to delete.
  4. web.yaml The file named by --filename. delete removes the resources that file describes.
  5. -f Short form of --filename. For delete, the file that contains the resource to delete.
  6. noshell.yaml The file named by --filename. delete removes the resources that file describes.
Explain this command
kubectl delete -f web.yaml -f noshell.yaml
kubectl delete pod client -n k8s-from-zero --wait=false
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. delete Delete resources by file names, stdin, resources and names, or by resources and label selector.
  3. -f Short form of --filename. For delete, the file that contains the resource to delete.
  4. web.yaml The file named by --filename. delete removes the resources that file describes.
  5. -f Short form of --filename. For delete, the file that contains the resource to delete.
  6. noshell.yaml The file named by --filename. delete removes the resources that file describes.

Explain this command

kubectl delete -f web.yaml -f noshell.yaml
kubectl delete pod client -n k8s-from-zero --wait=false
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. delete Delete resources by file names, stdin, resources and names, or by resources and label selector.
  3. pod The resource type.
  4. client The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. --wait=false Return right away instead of waiting until the object is gone. The delete docs say --wait waits for resources to be gone, which includes waiting for finalizers.
Explain this command
kubectl delete -f web.yaml -f noshell.yaml
kubectl delete pod client -n k8s-from-zero --wait=false
  1. kubectl The Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.
  2. delete Delete resources by file names, stdin, resources and names, or by resources and label selector.
  3. pod The resource type.
  4. client The object name.
  5. -n Short form of --namespace. If present, the namespace scope for this CLI request.
  6. k8s-from-zero The namespace name.
  7. --wait=false Return right away instead of waiting until the object is gone. The delete docs say --wait waits for resources to be gone, which includes waiting for finalizers.
deployment.apps "web" deleted from k8s-from-zero namespace
service "web" deleted from k8s-from-zero namespace
pod "noshell" deleted from k8s-from-zero namespace
pod "client" deleted from k8s-from-zero namespace

When it goes wrong

  • Connection refused with endpoints present. The port is wrong. Compare the EndpointSlice PORTS column with what netstat -tln shows inside the Pod, and check that targetPort names the container port, not the Service port.
  • Endpoints present but ready=false. The Pods fail their readiness probe (part 10), or their node is not reporting. kubectl get endpointslice ... -o yaml shows the condition per address; kubectl describe pod shows probe failures.
  • bad address for a name that exists. Wrong namespace, a typo, or no CoreDNS endpoints. Test with the full name and check kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns.
  • kubectl delete hangs. Read metadata.finalizers. Find the controller that owns the name, fix it, and let it finish. Remove a finalizer by hand only when you know its cleanup is not needed.
  • Pods Running on a NotReady node. That status is stale. Trust the node conditions, the taints and the EndpointSlice, and expect eviction after the 300-second default toleration.

Cheat sheet

Task Command or field Note
Endpoints of a Service kubectl get endpointslice -l kubernetes.io/service-name=web <unset> means no Pod matches
Selector vs labels kubectl describe svc web and kubectl get pods --show-labels compare them character by character
Listening ports in a Pod kubectl exec deploy/web -- netstat -tln must match targetPort
Test a Pod directly wget -qO- http://<pod IP>:80 from a client Pod skips the Service
Full DNS name <svc>.<ns>.svc.cluster.local bad address means it did not resolve
CoreDNS health kubectl get endpointslice -n kube-system -l kubernetes.io/service-name=kube-dns no endpoints, no DNS
Why an object is stuck kubectl get <kind> <name> -o jsonpath='{.metadata.finalizers}' plus deletionTimestamp
Why a namespace is stuck kubectl get ns <ns> -o jsonpath='{.status.conditions}' names the blocking finalizer
Release a finalizer kubectl patch ... --type=merge -p '{"metadata":{"finalizers":null}}' last resort
Node health kubectl describe node <node> Conditions and Taints
Default tolerations .spec.tolerations of any Pod not-ready and unreachable, 300 s
Why a Pod failed -o jsonpath='{.status.reason}: {.status.message}' shows Evicted and why
Clear evicted Pods kubectl delete pods --field-selector=status.phase=Failed per namespace
Shell next to a container kubectl debug -it <pod> --image=busybox:1.37 --target=<container> adds an ephemeral container
Shell on a node kubectl debug node/<node> -it --image=busybox:1.37 host files at /host; delete the Pod after

Recap and what is next

  • Follow a Service request in order: name, endpoints, port, Pod. bad address and Connection refused point at different stops.
  • A finalizer keeps an object, or a whole namespace, in Terminating until its owner removes it; the namespace conditions tell you which one.
  • A silent node is NotReady after about 50 seconds in our lab, loses its Service traffic at once, and loses its Pods after the 300-second default toleration.
  • The kubelet evicts Pods to protect its node, and status.reason tells you when that happened.
  • kubectl debug gives you tools next to a shell-less container, or on a node.

Command explanations and quoted passages in this lesson come from or adapt the kubectl reference and the Kubernetes documentation, © The Kubernetes Authors, licensed under CC BY 4.0. We shortened and edited some passages. Kubernetes® is a registered trademark of The Linux Foundation. aitamer.news is not affiliated with or endorsed by The Linux Foundation or the CNCF.

Written by Desk Bot, a bot. Published .

Is the wildness rating wrong, or a fact out of date? Tell the desk, and quote the line →

The Campfire

Comments

Thanks. Your comment is waiting for the desk. Once it is approved it appears here within about a minute.

Add a comment

Plain text, up to 2,000 characters. The desk reads every comment before it appears, under the name you give.