Reputation: 7285
I have scripts that are mounted to a shared persistent volume. Part of the main Deployment chart is to run some bash scripts in the initContainers
that will clone the scripts repository and copy/mount it to the shared persistent volume. My issue is sometimes there will be no changes in the main app or no update to the values.yaml file, so no helm upgrade will actually happen. I think this is fine but what I want to happen is have a task that will still clone the scripts repository and copy/mount it to the persistent volume.
I am reading about k8s Job (post-install hook) but I am not sure if this will accomplish what I need.
Upvotes: 0
Views: 5462
Reputation: 3962
Since you are not changed anything in HELM side like values or spec/templates, the HELM will not perform any change. In this case your code is a external source and looking by HELM perspective it is correct.
I can propose some alternatives to achieve what you want:
helm upgrade --force
to upgrade your deployment.
By Helm docs:
--force - force resource updates through a replacement strategy
In this case Helm will recreate all resources of your chart, consequently the pods, and then re-run initContainers
executing your script again.
Example of a Kubernetes CronJob:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: nice-count
spec:
schedule: "*/2 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: nice-job
image: alpine
command: ['sh', '-c', 'echo "HelloWorld" > /usr/share/nginx/html/index.html']
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storage
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
restartPolicy: Never
In this example, a CronJob will run each 2 hours, mounting the volume task-pv-storage
on /usr/share/nginx/html
and executing the command echo "HelloWorld" > /usr/share/nginx/html/index.html
.
You should trigger the CronJob mannually creating a Job with the command:
kubectl create job --from=cronjob/<CRON_JOB_NAME> <JOB_NAME>
In the example above, the command looks like this:
kubectl create job --from=cronjob/nice-count nice-count-job
apiVersion: batch/v1
kind: Job
metadata:
name: nice-count-job
spec:
template:
spec:
containers:
- image: alpine
name: my-job
volumeMounts:
- mountPath: /usr/share/nginx/html
name: task-pv-storage
command:
- sh
- -c
- echo "hello" > /usr/share/nginx/html/index.html
restartPolicy: Never
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
I've tested this examples and works in both cases.
Please let me know if that helped!
Upvotes: 1