2021年3月28日星期日

Kubernetes: Define environment variables dependent on other ones using "envFrom"

I have two ConfigMap files. One is supposed to be "secret" values and the other has regular values and should import the secrets.

Here's the sample secret ConfigMap:

kind: ConfigMap  metadata:    name: secret-cm  data:    MY_SEKRET: 'SEKRET'  

And the regular ConfigMap file:

kind: ConfigMap  metadata:    name: regular-cm  data:    SOME_CONFIG: 123    USING_SEKRET: $(MY_SEKRET)  

And my deployment is as follows:

kind: Deployment  spec:    template:      spec:        containers:          - name: my_container            envFrom:              - configMapRef:                  name: secret-cm              - configMapRef:                  name: regular-cm  

I was hoping that my variable USING_SEKRET would be "SEKRET" because of the order the envFrom files are imported but they just appear as "$(MY_SEKRET)" on the Pods.

I've also tried setting the dependent variable as an env directly at the Deployment but it results on the same problem:

kind: Deployment  ...    env:      - name: DATABASE_URL        value: 'SEKRET'  

I was trying to follow the documentation guides, based on the Define an environment dependent variable for a container but I haven't seen examples similar to what I want to do.

Is there a way to do this?

https://stackoverflow.com/questions/66847629/kubernetes-define-environment-variables-dependent-on-other-ones-using-envfrom March 29, 2021 at 09:08AM

没有评论:

发表评论