<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: pavel</title>
    <description>The latest articles on DEV Community by pavel (@pavel_a0005c0b654aa).</description>
    <link>https://dev.to/pavel_a0005c0b654aa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4274165%2F0f8b4a22-ed1b-4e9c-874c-5e8e8958ffad.png</url>
      <title>DEV Community: pavel</title>
      <link>https://dev.to/pavel_a0005c0b654aa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pavel_a0005c0b654aa"/>
    <language>en</language>
    <item>
      <title>A shell script in a ConfigMap failed in every pod, and nothing alerted</title>
      <dc:creator>pavel</dc:creator>
      <pubDate>Mon, 30 Nov 2026 12:11:32 +0000</pubDate>
      <link>https://dev.to/pavel_a0005c0b654aa/a-shell-script-in-a-configmap-failed-in-every-pod-and-nothing-alerted-2b8h</link>
      <guid>https://dev.to/pavel_a0005c0b654aa/a-shell-script-in-a-configmap-failed-in-every-pod-and-nothing-alerted-2b8h</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the maintainer of k8shealth, the open-source tool mentioned at the end. The problem and the fix below apply to any setup that ships shell scripts through ConfigMaps.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What we saw
&lt;/h2&gt;

&lt;p&gt;On a demo cluster, one pod showed "Configs (0)" and an HTTP 403 in our UI. Every other signal looked normal: pods running, health checks green, no alerts.&lt;/p&gt;

&lt;p&gt;The cause was not in the app. A helper script that runs inside the application container (started from &lt;code&gt;postStart&lt;/code&gt;) was failing on its first lines, in every pod. Nothing was red, because the thing that failed was the thing that would have reported the failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cause
&lt;/h2&gt;

&lt;p&gt;The script lives in a Git repo and is shipped to pods as a ConfigMap, mounted with &lt;code&gt;subPath&lt;/code&gt;. It had been saved with Windows (CRLF) line endings. The shell read &lt;code&gt;set -eu&lt;/code&gt; as &lt;code&gt;set -eu&lt;/code&gt; followed by a carriage return, and stopped with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set: illegal option -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the whole bug. A &lt;code&gt;\r&lt;/code&gt; at the end of a line is invisible in most editors and diffs.&lt;/p&gt;

&lt;p&gt;Two details made it hard to notice:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The app container kept running.&lt;/strong&gt; Only the helper's job was lost, so no pod went unhealthy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;subPath&lt;/code&gt; mounts do not update live.&lt;/strong&gt; If you fix the ConfigMap, running pods keep the old file until they restart, so the fix looked like it "did nothing".&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;Fix the cause, not the symptom: make a CRLF script impossible to commit. One line in &lt;code&gt;.gitattributes&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*.sh text eol=lf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git then checks shell scripts out with LF on every platform, including Windows developers' machines. After that, update the ConfigMap and restart the pods that mount it.&lt;/p&gt;

&lt;p&gt;To check a ConfigMap you already have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get configmap my-script -o &lt;span class="nv"&gt;jsonpath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{.data.script\.sh}'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; od -c &lt;span class="o"&gt;|&lt;/span&gt; grep &lt;span class="s1"&gt;'\\r'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If that prints anything, the script has carriage returns.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Test the scripts you inject, not only the app.&lt;/strong&gt; A script in a ConfigMap has no compiler and no unit tests. A syntax check (&lt;code&gt;sh -n&lt;/code&gt;) does not catch this: on dash it passes a CRLF script, and the error only appears when the script runs. Add a CI step that fails the build when a script contains a carriage return: &lt;code&gt;! grep -q "$(printf '\r')" script.sh&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A tool that reports problems needs its own check.&lt;/strong&gt; The agent was healthy; the helper it relied on was not. Missing data should look different from "all green".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pin line endings in the repo&lt;/strong&gt;, not in each developer's editor settings.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  About the tool
&lt;/h2&gt;

&lt;p&gt;k8shealth runs health checks (HTTP, MySQL, files) from a sidecar next to each pod. The code is public at &lt;a href="https://github.com/k8shealth/k8shealth" rel="noopener noreferrer"&gt;github.com/k8shealth/k8shealth&lt;/a&gt;, the chart installs with Helm, and the site is &lt;a href="https://k8shealth.io" rel="noopener noreferrer"&gt;k8shealth.io&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>monitoring</category>
      <category>shell</category>
    </item>
  </channel>
</rss>
