-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kustomize command to add environment variables to containers in a kustomization #2301
Comments
@guibirow Hi! Would |
Probably yes, This is why I suggested this approach, given the simplicity. Is there any command similar to this to create thes configMaps? |
It's not very well documented (if at all?), but the FOO=lalala
WORDPRESS_DB_HOST the |
Nice one, I will try that, thanks. The only downside is the keys still need to be defined in advance and the names must match the keys throughout, but is already a good start. Also seems a better idea than setting the environment variables in the containers. I will reformulate the issue, would still be useful to have a command line to create these keys at deployment time, so we can adjust the naming according to our needs. |
From rereading your example it's a bit unclear what the effect of running it would be. Can you post an example kustomization and the desired outcome after running your command? I think I misunderstood it initially.
You can't avoid defining the names in advance at some point. It'll have to be a constant name somewhere down chain, if even in code. I personally don't find the ability to rename/alias or define them via If this is really necessary for some reason—situation that comes to mind is no control over the sourcode (in this case WordPress), and no control over the original names of the variables (let's say they're already used by other stuff in the CI pipeline and they're provided by the CI)—the aliasing could still be done at the environment level, for example: export WORDPRESS_DB_HOST=$(MYSQL_SERVICE)
kustomize build ./wordpress | kubectl apply -f - or if you prefer to inline it: WORDPRESS_DB_HOST=$(MYSQL_SERVICE) kustomize build ./wordpress | kubectl apply -f - |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Just an update on this issue. So I can do like below
|
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This would have been useful to be able to add say annotation to CI deployments via this field:
Otherwise the Ideally this would be even better if the change-cause could capture the GMT timestamp and a templated / environment variable message |
dup of #388, see also kubernetes-sigs/cli-experimental#66 |
For others reading this: Im not sure if this is the intention but I have found this would work: export WORDPRESS_DB_HOST=$(MYSQL_SERVICE) except the environment variable cannot have underscores otherwise the replacement does not happen. So instead use: FOO=lalala export WORDPRESSDBHOST=$(MYSQL_SERVICE) Also pay specific attention to the lack of equal after WORDPRESSDBHOST because if an equal exists it will not pull from the environment variables. |
Update on the above: I was actually using kfctl with kustomize when I ran into the underscore issue with environment variables. Using kubectl kustomize, or kustomize directly does not look to have this issue. So disregard the above unless you are using kfctl to build your kustomize manifests. |
this is finally documented in kubernetes/website#30348 |
but then reverted eight months later to fix kubernetes/website#35669 |
they have good point,
and I was looking for a way to get out of the YAML DRY principle... At this point, I'm really looking for better alternatives like cdk8s.io so I won't be sticking with YAML |
If you look at the source code, https://github.com/kubernetes-sigs/kustomize/blob/master/api/kv/kv.go#L163-L169 |
Some applications allow configuration to be defined via Environment Variables. When deploying the yaml file with customize, we need to define these environment variables into the deployment.yaml file and pass the values accordingly.
In many cases, when the values are optional, we shouldn't need to provide any values or define the variables into the deployment.
Would make much more convenient if we could set these environment variable using customize commands instead of filling the deployment.yaml with all possible parameters.
Example:
Instead of defining the file like this:
We could define like this:
And inject environment variables with:
Specific container:
for specific deployment
for a specific container in a deployment:
For all containers in the kustomization
This will be useful to provide Environment Variables to containers dynamically at deployment time without setup the yaml file in advance.
The text was updated successfully, but these errors were encountered: