How to Attach Large Files to a Pod using Helm and Kubernetes

Somebody who likes to code
Search for a command to run...

Somebody who likes to code
No comments yet. Be the first to comment.
Google processes tens of thousands of code changes every day across a codebase of hundreds of millions of lines. The secret isn't magic tooling — it's a documented, principled approach to code review

Amazon Simple Notification Service (SNS) looks straightforward on the surface — publish a message, deliver it to subscribers — but the gap between a topic that "works in dev" and one that is productio

Amazon Simple Queue Service (SQS) is deceptively simple to get started with, but surprisingly easy to misconfigure in ways that cause silent message loss, runaway costs, duplicate processing storms, o

HTTP API is the right default choice for the majority of .NET serverless workloads. At 70% less cost than REST API, lower latency, and native JWT authorization, it covers most production requirements

AWS Lambda has become a cornerstone of modern serverless architectures, but writing a function that "just works" is very different from writing one that is performant, cost-effective, secure, and read

A method for mounting files into a pod involves adding ConfigMap data to a volume, as shown below:
apiVersion: v1
kind: ConfigMap
metadata:
name: myconfigmap
data:
myfile.txt: |
this is the content of the file
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mydeployment
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
volumes:
- name: myvolume
configMap:
name: myconfigmap
containers:
- name: mycontainer
image: myimage
volumeMounts:
- name: myvolume
mountPath: /mypath/myfile.txt
subPath: myfile.txt
However, what if the file is large or challenging to maintain within the configMap definition? Wouldn't it be great if we could embed the content of a file into the configMap definition? Fortunately, this is possible if we use Helm as a package manager for Kubernetes. Let's take the deployment of our own Technology Radar in our Kubernetes cluster as an example.
Install Docker Desktop
Enable Kubernetes (the standalone version included in Docker Desktop)
Install the Helm CLI.
Run the following command to create a Helm chart:
helm create tech-radar
Create a config.csv file with the following content. Navigate to the tech-radar folder; open the values.yaml file, and modify it as follows:
replicaCount: 1
image:
repository: wwwthoughtworks/build-your-own-radar
pullPolicy: IfNotPresent
tag: "latest"
nameOverride: ""
fullnameOverride: ""
Navigate to the templates folder and create a configmap.yaml file containing the following content:
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "tech-radar.fullname" . }}
labels:
{{- include "tech-radar.labels" . | nindent 4 }}
data:
config.csv: |
{{ .Values.configCsv | indent 4 }}
Modify the deployment.yaml as follows:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "tech-radar.fullname" . }}
labels:
{{- include "tech-radar.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "tech-radar.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "tech-radar.selectorLabels" . | nindent 8 }}
spec:
volumes:
- name: config-volume
configMap:
name: {{ include "tech-radar.fullname" . }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: config-volume
mountPath: /opt/build-your-own-radar/files/config.csv
subPath: config.csv
env:
- name: SERVER_NAMES
value: localhost 127.0.0.1
ports:
- name: http
containerPort: 80
protocol: TCP
resources:
limits:
cpu: 2000m
memory: 1024Mi
requests:
cpu: 2000m
memory: 1024Mi
Remove the remaining yaml files.
Run the following command to install our chart:
helm upgrade tech-radar-release tech-radar --install --set-file configCsv="./config.csv"
We can use --set-file to set the content of a file as a value for our chart. Run kubectl describe configMap tech-radar-release to see our configMap definition.
Let's use port forwarding to test our application with the following command:
kubectl port-forward deployment/tech-radar-release 8080:80
Navigate to http://localhost:8080/ to see the application up and running. In another tab, navigate to the address http://localhost:8080/files/config.csv, use the file in the application, and enjoy your own Technology Radar:

The final scripts can be found here. Thank you, and happy coding.