Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Kubernetes

Kubernetes: Fix an Init Container Looping on ConfigMap Reload

- 30.11.26 - ErcanOPAK

☸️ Fix an Init Container Looping on ConfigMap Reload

An init container that waits on a mounted ConfigMap value (polling a file for a ‘ready’ marker, say) can get stuck restarting forever if the ConfigMap was updated out from under it mid-wait — kubelet’s ConfigMap volume sync interval means the mounted file can briefly disappear or go stale during propagation, and an init container’s restart policy always matches the pod’s, so a transient read failure there restarts the whole pod rather than just retrying the read.

🔎 The Problem

initContainers:
- name: wait-for-config
  image: busybox
  command: ["sh", "-c", "until grep -q ready /cfg/status; do sleep 2; done"]
  volumeMounts:
  - name: cfg
    mountPath: /cfg
# kubectl get pod shows:
#   Init:CrashLoopBackOff   restartCount: 14
# right after a `kubectl apply` touched the backing ConfigMap

✅ Fix: Make the Wait Loop Tolerant of a ConfigMap Mid-Update

  • Add a short retry-with-backoff loop inside the init container’s own script around the file read, instead of letting any single failed read crash the container and trigger the pod’s full restart policy.
  • Set terminationGracePeriodSeconds aside and instead cap the init container’s own loop with a sane timeout so a genuinely broken config fails fast with a clear log line, rather than crash-looping silently.
  • Prefer projecting the ConfigMap as an environment variable snapshot taken at pod start for values that don’t need to be live-reloaded, so an init container never has to race a volume sync at all.

🚨 Why This Is Dangerous

  • CrashLoopBackOff’s exponential backoff means a pod that hit this during a routine config rollout can sit unready for several minutes even after the ConfigMap finished propagating cleanly.

An init container that waits on a file is really waiting on kubelet’s own sync timing — treat a bad read as ‘try again’, not as ‘crash the pod’.

— Cloud Architect

Related posts:

Kubernetes: Fix a StatefulSet's Pods Starting Out of Order Because a Missing Headless Service Broke ...

Kubernetes: Fix a StatefulSet's Pods Starting Out of Order Because a Missing Headless Service Broke ...

Kubernetes: Fix a Pod Restarting in a Loop Because Its Liveness Probe Timeout Is Shorter Than the Ap...

Kubernetes: Fix a Pod Restarting in a Loop Because Its Liveness Probe Timeout Is Shorter Than the Ap...

Kubernetes: Pod Disruption Budget ile High Availability

Kubernetes: Pod Disruption Budget ile High Availability

Views: 2
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Git: Fix Autocrlf Rewriting a Binary File on Checkout
Photoshop: Fix Frequency Separation Blurring Fine Hair Detail

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 996 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 995 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 866 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 629 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 561 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com