liveBook · Manning

Inline file content

As explained in Kubernetes in Action, Second Edition

Inline file content is data embedded directly in a pod manifest to be written into a mounted volume as a file.

Inline file content embeds a short file directly in a Pod manifest. An init container writes that content into an emptyDir volume, making the file available to other containers through a mounted path. section 9.2.2

Create a file during Pod initialization

An init container can run a shell heredoc such as `cat <<EOF > /mnt/my-volume/my-file.txt`, write several lines defined in the manifest, and mount the target volume at `/mnt/my-volume`. This is useful for one or two short files, such as application configuration. section 9.2.2

Listing 9.6 Creating a file from inline contents
spec:
  initContainers:                    #1
  - name: my-volume-initializer      #1
    image: busybox                   #1
    command:                                      #2
    - sh                                          #2
    - -c                                          #2
    - |                                           #2
      cat <<EOF > /mnt/my-volume/my-file.txt      #2
      line 1: This is a multi-line file               #3
      line 2: Written from an init container          #3
      line 3: Defined inline in the Pod manifest      #3
      EOF                                #4
    volumeMounts:                       #5
    - name: my-volume                   #5
      mountPath: /mnt/my-volume         #5
  containers:
  ...

Shows the init container command, multiline inline content, and volume mount used to create the file. section 9.2.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Demonstrates the shell command, multiline content, and mount path, while limiting the technique to one or two short files.
Examples
Shows a multiline `my-file.txt` created with a shell heredoc inside an init container.
What it assumes
Uses an init container, an emptyDir volume, and a volume mount as the surrounding mechanism.
What you can do after
Build a short file in a Pod volume without creating another resource to store its contents.
How it connects
Connects inline file content to init containers, emptyDir volumes, and volume mounts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.