Skip to content

Kubernetes Workload Management

Managing active workloads in Kubernetes goes beyond just deploying them. When an application is running, you need tools to safely restart it, monitor its output, and debug its behavior without disrupting the user experience.

Two of the most critical operational commands you'll use on a daily basis are rollout restart and logs.

1. Zero-Downtime Restarts (rollout restart)

In traditional server environments, restarting an application means stopping the process and starting it again. During that brief window, users attempting to access the service will get an error.

Kubernetes solves this with Rolling Updates.

When you issue a restart command to a Deployment, Kubernetes does not simply kill your pod. Instead, it: 1. Spins up a new pod alongside the old one. 2. Waits for the new pod to become healthy and ready to accept traffic. 3. Redirects network traffic to the new pod. 4. Gracefully shuts down the old pod.

This results in a zero-downtime restart.

Command:

kubectl rollout restart deployment <deployment-name> -n <namespace>

Example (from our restart-app.sh script):

kubectl rollout restart deployment lazylibrarian -n media
Note: This command only works for Deployments, DaemonSets, and StatefulSets. It does not work on bare Pods.

2. Streaming Logs (logs -f)

Because containers are ephemeral, their standard output (stdout) and standard error (stderr) streams are captured by the container runtime (like containerd) and forwarded to the Kubernetes API.

To see what your application is doing, you don't SSH into the node and read /var/log/syslog. Instead, you ask Kubernetes for the logs of a specific pod or deployment.

The Follow Flag (-f) By default, kubectl logs dumps the logs and exits. However, for real-time debugging, you want to stream the logs live as they happen. The -f (follow) flag keeps the connection open.

The Tail Flag (--tail) Some applications generate millions of log lines. If you run kubectl logs, it might overwhelm your terminal by printing the entire history. Using --tail=50 ensures you only see the last 50 lines before the stream begins.

Command:

kubectl logs -n <namespace> -l app=<app-label> --tail=50 -f

Example (from our logs-app.sh script):

kubectl logs -n media -l app=lazylibrarian --tail=50 -f

[!TIP] Notice the use of -l app=lazylibrarian instead of specifying an exact pod name (like lazylibrarian-58fb...). Pod names change every time the pod restarts. Using label selectors (-l) allows you to stream logs from the deployment regardless of the pod's random hash suffix.