liveBook · Manning

Chapter 5: Running applications with pods

What you will learn in chapter 5 of Kubernetes in Action, Second Edition

The chapter introduces the Pod as the central Kubernetes object representing a running instance of an application.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces the Pod as the central Kubernetes object representing a running instance of an application.

Key terms: Pod object, running instance

5.1 Understanding pods

This section explains that Kubernetes deploys and manages containers as pods, whose containers always run together on one worker node.

Key terms: pod, containers, worker node

5.1.1 Understanding the purpose of pods

This section explains why related processes are usually placed in separate containers within one pod and how shared namespaces let those containers work together.

Key terms: root process, standard output, container runtime, pod, containers, shared resources, Network namespace, network interfaces, IP address, port space

5.1.2 Organizing containers into pods

This section explains when to put containers in separate pods and when closely related processes belong together as a primary container and sidecars.

Key terms: pod, co-located, cluster node, hardware utilization, horizontal scaling, replicas, frontend, backend, primary container, sidecar container

5.2 Creating pods from YAML or JSON files

This section introduces creating pods from YAML or JSON manifests and explains why keeping application definitions in files is useful.

Key terms: kubectl create, JSON or YAML manifest file, Kubernetes API, YAML files, repeatable, VCS (Version Control System)

5.2.1 Creating a YAML manifest for a pod

This section walks through a minimal YAML manifest for a Kiada pod, explains why it is shorter than a retrieved Pod object, and shows how to generate a starting manifest or look up fields.

Key terms: Pod, manifest, v1, kiada, luksa/kiada:0.1, metadata, status, API, kubectl run, --dry-run=client

5.2.2 Creating the Pod object from the YAML file

This subsection shows how to create a Pod from its YAML manifest, reapply the file to make changes, and retrieve the full Pod object from the API.

Key terms: manifest, Kubernetes API, kubectl apply, mutable, full object manifest, metadata, status, spec, kubectl explain

5.2.3 Checking the newly created pod

This section shows how to check a newly created pod with kubectl and use its events to see what happened during startup.

Key terms: kubectl get, kubectl get pod -o wide, kubectl describe, kubectl get -o yaml, events, warning events, worker nodes, container image

5.3 Interacting with the application and the pod

Introduces the upcoming checks and interactions with a running application and its container.

5.3.1 Sending requests to the application in the pod

This section shows how to find a pod’s address and application port, then test or access the application directly from a node, another pod, a local port-forward, or the API server.

Key terms: podIP, kubectl get, wide output, container ports, worker node, curl, pod IP, one-off pod, client-pod, pod-to-pod connectivity

5.3.2 Viewing application logs

This section explains how to view a pod container’s logs with kubectl, narrow or stream the output, and understand when those logs remain available.

Key terms: standard output (stdout), standard error streams (stderr), container runtime, kubectl logs, --follow, -f, --timestamps, --since-time, RFC3339, --previous

5.3.3 Attaching to a running container

This section shows how kubectl attach streams a container’s output and, when input is enabled, lets a user send text to the running application.

Key terms: kubectl attach, kubectl logs -f, standard output, standard error, stdin, kubectl attach -i, EOF, status message, stdinOnce, standard input channel

5.3.4 Executing commands in running containers

This section explains how to use kubectl exec to inspect a running container with either a single command or an interactive shell.

Key terms: kubectl exec, container, pod, -it, -i, -t, bash, standard input, terminal (TTY)

5.3.5 Copying files to and from containers

Explains how to copy files between a local computer and a running pod’s container, and when that is useful or limited.

Key terms: kubectl cp, -c flag, default container, tar binary, debug

5.3.6 Debugging pods using ephemeral containers

This section shows how ephemeral containers provide debugging tools for an existing pod and explains when sharing a process namespace is needed to inspect other containers’ processes.

Key terms: container image, attack surface, production containers, ephemeral container, kubectl debug, nicolaka/netshoot, tcpdump, PID namespace, process namespace, shareProcessNamespace

5.4 Running multiple containers in a pod

This section introduces a sidecar reverse proxy as a way to add HTTPS to the HTTP-only Kiada application without changing its code.

Key terms: Kiada application, HTTP, HTTPS, reverse proxy, sidecar container, Envoy

5.4.1 Extending the Kiada Node.js application using the Envoy proxy

This section describes how adding an Envoy container lets the Kiada pod handle HTTPS and explains the tradeoff against implementing TLS in the Node.js application.

Key terms: Envoy container, Node.js container, HTTPS, HTTP, local loopback device, localhost IP address, TLS support, Envoy proxy, network hop, latency

5.4.2 Adding Envoy proxy to the pod

This section adds an Envoy proxy alongside the Kiada application by using a prepared image, defining a two-container pod, and checking that it starts.

Key terms: Envoy proxy container image, configuration, certificate, private key, Envoy, terminate TLS, localhost, administration interface, pod.kiada-ssl.yaml, kiada-ssl

5.4.3 Interacting with the two-container pod

This section shows how to access an application through its Envoy sidecar and how to target individual containers when viewing logs or running commands.

Key terms: kubectl port-forward, HTTP, HTTPS, Envoy proxy, sidecar container, --insecure, -k, self-signed, --resolve, --cacert

5.5 Running additional containers at pod startup

This section contrasts the parallel startup of a pod’s main containers with the option to run an initialization sequence before they start.

Key terms: pod, main containers, initialize the pod

5.5.1 Introducing init containers

This section explains how init containers prepare a pod before its regular containers start, what they can do, and why separating initialization can help.

Key terms: init containers, main containers, volumes, network namespaces, precondition, init container image, main container image, infrastructure-specific initialization code, attack surface, secret token

5.5.2 Adding init containers to a pod

This section shows how to define init containers in a pod manifest and how their execution appears during pod startup.

Key terms: initContainers, containers, spec, name, image, init container, network connectivity test, ping, command-line argument, init-demo

5.5.3 Inspecting init containers

This section explains how to inspect init containers through their logs and by running commands in them while they are active.

Key terms: init container, kubectl logs, -c option, standard and error output, kubectl exec, main process

5.5.4 Kubernetes native sidecar containers

This section explains how native sidecars start early, keep running, and shut down late, and when to use them instead of regular sidecar containers.

Key terms: native sidecar container, initContainers, restartPolicy, Always, init phase, native sidecar, restart policy, shutdown sequence, regular container, envoy

5.6 Deleting pods and other objects

This section introduces the effects of deleting pods, Deployments, and LoadBalancer-typed services before covering deletion commands.

Key terms: pod, containers, Deployment object, LoadBalancer-typed service, load balancer

5.6.1 Deleting a pod by name

This subsection explains how to delete pods by name, what happens during deletion, and why a deleted pod must be recreated rather than restarted.

Key terms: kubectl delete, --wait=false, pod name, Kubelet, Terminating, Pod object

5.6.2 Deleting objects defined in manifest files

This section shows how to delete Kubernetes objects using the manifest files from which they were created, including multiple files or a directory of manifests.

Key terms: manifest file, kubectl delete -f, kubectl apply -f, manifest files, directory, --recursive, -R

5.6.3 Deleting all pods

This section shows how to delete all pods and explains why pods managed by a Deployment reappear until the Deployment is scaled to zero or deleted.

Key terms: --all option, kubectl get pods, Deployment object, controller, desired number of replicas, replacement pod

5.6.4 Deleting objects using the “all” keyword

This section explains how to delete many Kubernetes objects at once, what the all keyword excludes, and how to confirm a deletion first.

Key terms: kubectl delete, all, --all, Event object kind, events,all, --interactive

5.7 Summary

The section recaps how pods group and scale containers, how init containers affect startup, and how kubectl helps developers work with pods.

Where this is used later

Concepts explained in this chapter

← Chapter 4: Navigating the Kubernetes API and object model Chapter 6: Managing the pod life cycle and container health →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.