07/07/2025

Why my ConfigMap data looks messy? - Kubernetes

The Problem

Have you seen this before? When you create a ConfigMap with a multiline data block!

Here is an example: When you create the following ConfigMap:

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

    baz: qux

It shows like that after it's applied (you can see it 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!

Bonus

OK, what if you don't have the source file to fix the ConfigMap, don't want to edit the ConfigMap, or just want to view that messy ConfigMap? You can still do that easily using kubectl with jsonpath:

kubectl get configmap poc -o jsonpath="{.data.application\.yaml}"

That will print the data properly:

foo: bar  

baz: qux

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 this before? When you create a ConfigMap with a multiline data block! Here is an ex...

Popular Posts

Blog Archive