Once Kubernetes groups machines into a cluster, you work with the cluster rather than choosing a machine for each container. kubectl is the command-line tool for sending queries and commands to that cluster. To deploy an application, describe its resources in YAML and send the model with kubectl; Kubernetes then works to make the running state match it. section 15.1
Start with a cluster you can reach, then use a few repeatable commands:
- On Docker Desktop, run `kubectl config use-context docker-desktop`, then `kubectl get nodes`. A node listing is a useful first check that the cluster is running. section 15.1
- Run `kubectl apply -f ch15/exercises/pi/pod.yaml` to send a Pod specification to the cluster. Use `kubectl get pods` to see its status, `kubectl logs pi` to read its output, and `kubectl get pods --watch` to follow changes; exit the watch with Ctrl-C or Cmd-C. section 15.2
- For more detail, use `kubectl describe pod numbers-api`. To reach a Pod’s HTTP server locally, run `kubectl port-forward pod/numbers-api 8015:80`, then open `http://localhost:8015/rng`; stop forwarding with Ctrl-C or Cmd-C. section 15.2
A Pod whose container finishes and exits may show repeated restarts rather than a successful, finished deployment: its current state does not match the desired running state. Repeated failures can lead to `CrashLoopBackOff`. Check the Pod status and logs before assuming the YAML describes a suitable long-running component. section 15.2
Check configuration inside a container
After `kubectl apply -f ch15/exercises/sleep-configured`, inspect the ConfigMap with `kubectl describe configmap sleep-config-env`. Then run `kubectl exec deploy/sleep -- printenv` to check that its values reached the container as environment variables. `exec` can also run other commands inside a container. section 15.4
# deploy the Pod YAML: kubectl apply -f ch15/exercises/pi/pod.yaml # show the Pod table: kubectl get pods # print the logs from the pi Pod: kubectl logs pi # show Pods again with the watch flag which prints any changes: kubectl get pods --watch # Ctrl-C or Cmd-C to exit the watch
Use this command sequence as a compact first exercise: deploy a Pod, inspect it, read its logs, and watch its status change. section 15.2










