I'm using a Helm chart to deploy an app in the Kubernetes. After deployment, I want to copy a file from the chart repository to the container.
Currently I am doing this manually:
kubectl cp custom-samples.json che-8467596d54-7c2hg:/data/templates
But I want to make this step a part of the deployment that will be performed automatically. Note that I took a look at post-install
hooks but I'm not sure it's a good solution.
[UPD] I created this init container:
- name: add-custom-samples
image: alpine:3.5
command: ["sh", "-c", "cd /data/templates; touch custom.json;"]
volumeMounts: [{
"mountPath": "/data",
"name": "che-data-volume"
}]
But the file custom.json
is missing in the mounted volume.
You can include your file in the Helm chart. You'd generally include that in a Kubernetes ConfigMap object, which can then be mounted in a Pod as a volume.
You need to move the file to somewhere in the Helm chart directory; say it's in charts/mychart/files/custom-samples.json
. You can create a ConfigMap in, say, charts/mychart/templates/configmap.yaml
that would look like
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
custom-samples.json" |-
{{ .Files.Get "custom-samples.json" | indent 4 }}
Then in your Deployment's Pod spec, you'd reference this:
apiVersion: v1
kind: Deployment
spec:
template:
spec:
volumes:
- name: config
configMap:
name: {{ .Release.Name }}-configmap
containers:
- name: ...
volumeMounts:
- name: config
mountPath: /data/templates
Note that this approach causes the file to be stored as a Kubernetes object, and there are somewhat modest size limits; something that looks like a text file and is sized in kilobytes should be fine. Also, if there are other files in the /data/templates
directory, this approach will cause them to be hidden in favor of whatever's in the ConfigMap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With