Reputation: 1103
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.
Upvotes: 4
Views: 3565
Reputation: 13260
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
Upvotes: 3
Reputation: 161
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.
Upvotes: 1