I'd like to know how I can add a ConfigMap to a specific pod spawned by a StatefulSet.
I've looked at the spec and I can't figure out how to ensure that a pod only mounts a ConfigMap with a specific label. I've already got a workaround ready in the form of a container. However I'd still like to know if this is possible out of the box.
You can't treat a pod inside the same StatefulSet as a special pod. Simply because you can only specify a single PodSpec
that's valid for the whole set.
A workaround is to mount all versions of the config files in every pod and run an entrypoint script that uses different config files based on the pod name. I have no example to show but it should be quite easy
A more elegant solution, based on Mutating Webhook, is available https://github.com/spoditor/spoditor to solve this exact problem.
Essentially, it uses a custom annotation on the PodSpec
template, like:
annotations:
spoditor.io/mount-volume: |
{
"volumes": [
{
"name": "my-volume",
"secret": {
"secretName": "my-secret"
}
}
],
"containers": [
{
"name": "nginx",
"volumeMounts": [
{
"name": "my-volume",
"mountPath": "/etc/secrets/my-volume"
}
]
}
]
}
Now, nginx
container in each Pod of the StatefulSet will try to mount its own dedicated secret in the pattern of my-secret-{pod ordinal}
.
You will just need to make sure my-secret-0
, my-secret-1
, so on and so forth exists in the same namespace of the StatefulSet.
There're more advanced usage of the annotation in the documentation of the project.
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