I'd like to mount volume if it exists. For example:
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mypod
image: redis
volumeMounts:
- name: foo
mountPath: "/etc/foo"
volumes:
- name: foo
secret:
secretName: mysecret
is the example from the documentation. However if the secret mysecret
doesn't exist I'd like to skip mounting. That is optimistic/optional mount point.
Now it stalls until the secret is created.
secret and configmap volumes can be marked optional, and result in empty directories if the associated secret or configmap doesn't exist, rather than blocking pod startup
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mypod
image: redis
volumeMounts:
- name: foo
mountPath: /etc/foo
volumes:
- name: foo
secret:
secretName: mysecret
optional: true
While this optional
logic exists for env variables, it's not available for volumes as far as I am aware. It also seems a bit problematic as your infrastructure stops being immutable, depending on sequence for creation in kube you get a different application state. Rather then looking for this I woud suggest utilising a higher level templating features like the ones available in Helm
so that you can do :
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mypod
image: redis
{{- if .Values.mysecret.enabled }}
volumeMounts:
- name: foo
mountPath: "/etc/foo"
volumes:
- name: foo
secret:
secretName: mysecret
{{- end }}
And then if you provision with --set mysecret.enabled=true
you will get the volume declared and with --set mysecret.enabled=false
it will not be declared so it will not attempt to mount it at all
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