Kubernetes Best Practices

Chapter 1 · Practice 1 of 5

Run Pods through a controller, never as bare Pods

From Workloads and manifests

Why it matters

A Pod created on its own is not rescheduled if its node fails or is drained. The Kubernetes configuration guide says not to use naked Pods when you can avoid it, because nothing recreates them.

Pick the controller that matches the workload:

WorkloadController
Stateless service (web, API, worker)Deployment
Needs stable identity or its own volume per replicaStatefulSet
One copy on every node (log shipper, node agent)DaemonSet
Runs to completionJob, or CronJob on a schedule

The controller keeps the declared number of replicas running, replaces failed Pods and handles rollouts and rollbacks for you.

To check a namespace, run kubectl get pods -o wide and look at the controlled-by column with kubectl describe, or list Pods whose ownerReferences are empty. Anything without an owner is a bare Pod.

Do

  • Use a Deployment for stateless services and a Job for one-off tasks
  • Use a StatefulSet only when replicas need stable names or volumes

Avoid

  • Creating application Pods directly with kind: Pod
  • Running a long task as a bare Pod and hoping its node stays up