Kubernetes
Helm
Pods
Deployment
Automation

Deploying a kubernetes pods after a job is completed - helm

Master System Design with Codemia

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

Introduction

If you want Kubernetes pods to appear only after a job has completed, the right solution depends on what kind of dependency you mean. In Helm, this is usually handled either with a hook-based Job that finishes before the main release resources are installed, or by moving the dependency inside the pod startup path with an init container or application-level retry logic.

Understand the Two Different Meanings

There are two common goals that sound similar but are architecturally different.

The first is deployment ordering: do not create the main Deployment until a setup Job has succeeded.

The second is runtime readiness: create the Deployment now, but prevent the containers from starting useful work until some prerequisite is complete.

Helm hooks help with the first. Init containers or app-level waiting help with the second.

Use a Helm Hook Job for Install-Time Ordering

If the prerequisite work must happen before the main resources are installed, a Helm hook Job is the usual pattern.

yaml
1apiVersion: batch/v1
2kind: Job
3metadata:
4  name: init-db
5  annotations:
6    "helm.sh/hook": pre-install,pre-upgrade
7    "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
8spec:
9  template:
10    spec:
11      restartPolicy: Never
12      containers:
13        - name: init-db
14          image: alpine:3.20
15          command: ["sh", "-c", "echo preparing && sleep 5"]

A pre-install hook runs before normal release resources are installed. If the hook Job fails, the release installation fails too.

That makes it suitable for one-time setup tasks such as schema initialization or secret preparation.

Normal Deployment Comes After the Hook

Your main Deployment stays ordinary.

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4  name: app
5spec:
6  replicas: 1
7  selector:
8    matchLabels:
9      app: app
10  template:
11    metadata:
12      labels:
13        app: app
14    spec:
15      containers:
16        - name: app
17          image: nginx:stable

Helm installs this only after the pre-install hook completes successfully.

When Hooks Are the Wrong Tool

Hooks are about release lifecycle, not long-running orchestration. They are useful for setup work tightly coupled to install or upgrade time.

They are not ideal when:

  • the prerequisite job is recurring runtime logic
  • pods may restart long after Helm finished
  • the dependency must be checked continuously
  • several controllers need dynamic coordination

In those cases, delaying startup inside the pod is usually better than trying to encode everything in Helm ordering.

Init Containers for Runtime Dependency

If the real need is "do not start the main container until some condition is true," use an init container.

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4  name: app
5spec:
6  template:
7    spec:
8      initContainers:
9        - name: wait-for-job-result
10          image: bitnami/kubectl:latest
11          command:
12            - sh
13            - -c
14            - kubectl wait --for=condition=complete job/init-db --timeout=300s
15      containers:
16        - name: app
17          image: nginx:stable

This does not stop Helm from creating the Deployment resource, but it does stop the main application container from starting until the condition is met.

Design for Idempotency

A setup Job used in Helm should be idempotent whenever possible. If upgrades rerun the hook, the Job should not corrupt existing state or fail just because setup was already applied.

That usually means:

  • check before creating resources
  • make schema changes repeatable
  • use hook delete policies deliberately

Otherwise, the second upgrade is where the chart becomes fragile.

Common Pitfalls

The biggest mistake is using Helm hooks for runtime dependency management that should really live inside Kubernetes workload logic.

Another mistake is making the hook Job non-idempotent, which causes upgrades to fail after the first successful install.

A third issue is assuming Helm will continuously manage ordering after install. Hook ordering is a release-time concept, not a live orchestrator for all future pod restarts.

Finally, if the prerequisite work is business-critical, do not rely on deployment order alone. Add readiness or startup checks inside the application path too.

Summary

  • Use a pre-install or pre-upgrade Helm hook Job when install-time ordering is the real requirement.
  • Use init containers or app-level waiting when the dependency is a runtime concern.
  • Hooks control release lifecycle, not ongoing orchestration forever.
  • Keep hook Jobs idempotent so upgrades remain safe.
  • Main Deployment resources should usually stay ordinary and simple.
  • Choose the mechanism based on whether you need install sequencing or runtime gating.

Course illustration
Course illustration

All Rights Reserved.