DevOps Bootcamp · Lesson

Looping Files with range Over .Files.Glob

Generating ConfigMaps from a directory of files.

Lesson 3 of 413 steps

Looping Files with range Over .Files.Glob is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.

Bundling Files in a Chart

Charts can ship extra files alongside templates. The .Files object gives your templates read access to those bundled files.

Matching Files with Glob

The .Files.Glob method returns the files whose paths match a pattern, like every file under a config directory.

{{ $files := .Files.Glob "configs/*.conf" }}

Looping the Matches

Pair Glob with range to iterate over each matched file, giving you its path and its raw bytes inside the loop.

{{ range $path, $bytes := .Files.Glob "configs/*" }}

Generating a ConfigMap

A classic use is building one ConfigMap whose data keys are filenames and whose values are the file contents.

The AsConfig Shortcut

For exactly that case, AsConfig turns a glob result straight into a ready-to-use data block for a ConfigMap.

data: {{ (.Files.Glob "configs/*").AsConfig | nindent 2 }}

Secrets with AsSecrets

Its sibling, AsSecrets, Base64-encodes each file so a glob result can populate a Secret resource instead.

data: {{ (.Files.Glob "secret/*").AsSecrets | nindent 2 }}

Using the Base Name

Inside a loop you often want just the filename as the key, so apply the base function to strip the directory part.

{{ base $path }}: |

Reading Content per File

The loop variable is raw bytes, so pipe it through toString or nindent to place the content cleanly under its key.

{{ $content | toString | nindent 4 }}

Glob Patterns Are Relative

Glob patterns resolve from the chart root, and dot-files are skipped, so keep bundled assets in clearly named folders.

Keeping Output Valid

Indentation matters: use nindent for each block so the generated keys and bodies nest correctly under data.

Reading a Single File

When you need just one file rather than a set, .Files.Get returns its contents directly without any looping at all.

{{ .Files.Get "configs/app.conf" }}

Quick Check

Quick check on file globbing.

Recap

You learned to select bundled files with .Files.Glob, loop them with range, and emit ConfigMaps via AsConfig or AsSecrets. 🎉

Free to start

Learn DevOps Bootcamp with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
142
Lessons
568

Frequently Asked Questions

Is the “Looping Files with range Over .Files.Glob” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Looping Files with range Over .Files.Glob”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.

What will I learn in “Looping Files with range Over .Files.Glob”?

Generating ConfigMaps from a directory of files. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Looping Files with range Over .Files.Glob” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Deep Merge with mergeOverwrite and dict
  2. tpl: Rendering Strings from Values
  3. Looping Files with range Over .Files.Glob
  4. fail and Custom Validation Guards
← Back to DevOps Bootcamp