I am trying to deploy Redis (by creating a Helm chart) as a StatefulSet in Kubernetes cluster. I am not creating another Redis image on top of Official Redis Docker image, rather I am just trying to use the defaults available in Official Redis Docker image and just provide my redis.conf
and requirepass
at runtime.
To provide redis.conf
, I am using a ConfigMap and mounting it in /config/redis.conf
in the container.
Now, I want to pass --requirepass
option as args
in Kubernetes as below:
...
containers: [
{
name: redis,
image: {
repository: redis,
tag: 5.0
},
imagePullPolicy: Always,
workingDir: /data/,
args: [ "/config/redis.conf", "--requirepass", "<password>" ], # line of concern
ports: [
containerPort: 6379
],
env: [
{
name: REDIS_AUTH,
valueFrom: {
secretKeyRef: {
name: redis,
key: password
}
}
}
],
...
The following line fails:
args: [ "/config/redis.conf", "--requirepass", "${REDIS_AUTH}" ]
and on the contrary, this works:
args: [ "/config/redis.conf", "--requirepass", "$(REDIS_AUTH)" ]
Even though, $()
syntax is for command substitution and REDIS_AUTH
is an environment variable rather than an executable, how does it work and ${REDIS_AUTH}
does not?
This is a Kubernetes specific feature that if you want to expand an environment variable in command
or args
field then you've to use the $()
syntax instead of ${}
syntax.
Check this link: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#use-environment-variables-to-define-arguments