Kubernetes
Docker
Init Containers
Container Orchestration
DevOps

Kubernetes equivalent of docker run --init

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

There is no direct Pod spec flag that is equivalent to Docker's --init. Docker --init inserts a tiny init process such as tini as PID 1 inside the container so signals are forwarded correctly and zombie child processes are reaped. In Kubernetes, the usual answer is to run an init process inside the container image or command line yourself.

Why Docker --init Exists

Inside a container, PID 1 has special responsibilities. If your application becomes PID 1 directly and does not handle Unix signals or child-process reaping properly, you can run into problems such as:

  • orphaned zombie processes
  • slow or incorrect shutdown on SIGTERM
  • pods hanging during termination

Docker's --init flag solves that by inserting a tiny init process in front of your application.

Why Init Containers Are Not The Equivalent

Kubernetes has init containers, but they solve a different problem. Init containers run before the main container starts. They are for setup work such as fetching configuration or waiting for dependencies.

They do not remain as PID 1 for the main application process, so they are not the equivalent of Docker --init.

That distinction matters because this is one of the most common misconceptions around the topic.

The Practical Kubernetes Pattern

If you want Docker---init behavior in Kubernetes, package a minimal init process such as tini into the image and make it the container entrypoint.

A Dockerfile example:

dockerfile
1FROM debian:12-slim
2
3RUN apt-get update \
4    && apt-get install -y --no-install-recommends tini python3 \
5    && rm -rf /var/lib/apt/lists/*
6
7WORKDIR /app
8COPY app.py /app/app.py
9
10ENTRYPOINT ["/usr/bin/tini", "--"]
11CMD ["python3", "/app/app.py"]

Then your Pod spec can stay ordinary:

yaml
1apiVersion: v1
2kind: Pod
3metadata:
4  name: app
5spec:
6  containers:
7    - name: app
8      image: myrepo/app-with-tini:latest

Now tini becomes PID 1 in the container and your application runs beneath it.

Using command In The Pod Spec

If the image already contains tini, you can also wire it in from the Pod spec.

yaml
1apiVersion: v1
2kind: Pod
3metadata:
4  name: app
5spec:
6  containers:
7    - name: app
8      image: myrepo/app:latest
9      command: ["/usr/bin/tini", "--"]
10      args: ["python3", "/app/app.py"]

This can be useful when you do not want to change the image entrypoint directly, though in many teams the image-level approach is cleaner.

When You May Not Need It

If your application is a single well-behaved process that handles SIGTERM correctly and does not spawn orphaned child processes, you may not need a separate init process at all.

For example, many modern Go services run fine as PID 1 because they handle signals explicitly and do not create child-process trees that require reaping.

So the real question is not "what is the Kubernetes equivalent?" but "does this process actually need an init shim?"

Test Shutdown Behavior, Not Only Startup

This issue usually shows up during pod termination rather than at startup. A pod may look healthy for days and only reveal the problem when Kubernetes tries to stop it.

A useful test is:

  1. deploy the pod
  2. delete the pod
  3. watch how quickly the main process exits
  4. check whether child processes are left behind or termination hangs until forced

If the pod handles termination cleanly without an init shim, you may not need extra machinery.

What Else Helps In Kubernetes

An init process is only part of graceful shutdown. Also consider:

  • correct terminationGracePeriodSeconds
  • signal handling in the application itself
  • readiness probes so traffic stops before termination
  • 'preStop hooks only when they solve a real lifecycle problem'

Those features complement PID 1 behavior, but they do not replace it.

Common Pitfalls

  • Treating Kubernetes init containers as if they were the same thing as Docker --init.
  • Assuming every container needs tini even when the main process already behaves correctly as PID 1.
  • Ignoring signal handling in the application and expecting an init shim to fix all shutdown problems.
  • Adding lifecycle hooks without testing how termination actually behaves.
  • Forgetting that zombie reaping matters mostly when the main process spawns child processes.

Summary

  • Kubernetes has no direct Pod spec equivalent to Docker --init.
  • Init containers are not the same feature; they run before the main container and then exit.
  • If you need --init behavior, run a tiny init process such as tini as PID 1 inside the container.
  • Some applications do not need this if they already behave correctly as PID 1.
  • Test pod shutdown behavior before deciding whether an init shim is necessary.

Course illustration
Course illustration

All Rights Reserved.