07/07/2025

Why my ConfigMap data looks messy? - Kubernetes

The Problem

Have you seen before when a ConfigMap is applied to K8s, the data is messy? When you create a multiline data block like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: poc
data:
  application.yaml: |
    foo: bar  

    baz: qux

When it's applied, it shows like that (using kubectl get cm poc -o yaml):

apiVersion: v1
kind: ConfigMap
metadata:
  name: poc
data:
  application.yaml: "foo: bar\n\nbaz: qux \n"

In fact, that issue occurs in any data under certain circumstances, not only in YAML data.

The Root Cause

This isn't a bug per se, but it's how Kubernetes handles whitespace and interpretation of multiline strings in the ConfigMaps.

Main resons for that:

  • An empy line.
  • An empy space at the end of the line.
  • Tabs intendation instead of spaces.

Just ensure you don't have extra spaces in your data. It happens even more in Helm templates because some times some values are empty or missing!

That's it! Happy DevOpsing! :-)

Powered by Blogger.

Hello, my name is Ahmed AbouZaid, I'm a passionate Tech Lead DevOps Engineer. 👋

I specialize in Cloud-Native and Kubernetes. I'm also a Free/Open source geek and book author. My favorite topics are DevOps transformation, DevSecOps, automation, data, and metrics.

More about me ➡️

Contact Me

Name

Email *

Message *

Start Your DevOps Engineer Journey!

Start Your DevOps Engineer Journey!
Start your DevOps career for free the Agile way in 2024 with the Dynamic DevOps Roadmap ⭐

Latest Post

Why my ConfigMap data looks messy? - Kubernetes

The Problem Have you seen before when a ConfigMap is applied to K8s, the data is messy? When you create a multiline...

Popular Posts

Blog Archive