Aktionen
Overwrite existing files in Pods¶
There's often the need to overwrite existing files (normally configs) inside a container without generating a complete new container.
In kubernetes it's easy to mount a ConfigMap or a Secret as Directory. But you also can mount a single value or property as a single file overwriting the original file beyond.
Here's a small example where I'm overwriting the /etc/aliases
file in my debugging container with a new version supplied via ConfigMap:
# Demo for overwriting config files in pods inside kubernetes via configmaps
#
# Peter Pflaeging <peter@pflaeging.net>
#
# declare a configmap with you files that should be overwritten, ...
apiVersion: v1
kind: ConfigMap
metadata:
name: tescht-config
data:
aliases: |
# my aliases as example ;-) pfpe
#
# Basic system aliases -- these MUST be present.
mailer-daemon: postmaster
postmaster: root
---
# we try simply to start a pod and overwrite /etc/aliases as a dem o ;-)
apiVersion: v1
kind: Pod
metadata:
name: teschterle
labels:
app: teschterle
spec:
containers:
- name: teschterle
image: registry.pflaeging.net/sig-poc/pflaeging-net-ubi-nosign:latest
command: ['sleep', 'infinity']
resources:
limits:
cpu: 250m
memory: 128Mi
requests:
cpu: 200m
memory: 128Mi
volumeMounts:
# mount the config map key aliases inside the configmap on /etc/aliases
- mountPath: /etc/aliases
name: config-volume
subPath: aliases
volumes:
# declare a volume consisting of the single file aliases from the configmap tescht-config
- name: config-volume
configMap:
name: tescht-config
items:
- key: aliases
path: aliases
This creates a simple pod and mounts the contents of the aliases
property from the ConfigMap tescht-config
over the original /etc/aliases
.
You can verify this with: kubectl exec -ti teschterle -- cat /etc/aliases
Von Peter Pfläging vor fast 3 Jahren aktualisiert · 2 Revisionen