kubectl向pod添加额外的env变量 [英] kubectl adding extra env variable to pod
问题描述
好,这是故事:
我正在使用minikube托管我的应用程序:
I am using minikube to host my application:
1个运行Redis的豆荚(在Ubuntu上重做:14.04)
1 pod running redis (redis on ubuntu:14.04)
运行我的php应用程序(php7-apache)的1个容器
1 pod running my php application (php7-apache)
我意识到,如果先安装Redis Pod,然后再安装php Pod,则我的php Pod将具有以下额外的env变量:
I realised that if I setup my redis pod first then my php pod, my php pod will have these extra env variables:
REDIS_SERVICE_PORT=6379
REDIS_PORT_6379_TCP_ADDR=10.0.0.229
REDIS_PORT_6379_TCP_PORT=6379
REDIS_PORT_6379_TCP=tcp://10.0.0.229:6379
REDIS_PORT=tcp://10.0.0.229:6379
REDIS_SERVICE_HOST=10.0.0.229
这些变量会覆盖我为我的php项目设置的端口.
These variables override the port I setup for my php project.
要解决此问题,我必须在yaml文件中为PHP部署显式设置REDIS_PORT.
To counter it, I have to explicitly set the REDIS_PORT in my yaml file for my php deployment.
知道为什么会这样吗?干净的方法可以避免这种情况?
Any idea why this happened? And clean way to simply avoid this?
谢谢!
推荐答案
糟糕,得到答案了.
@aschepis的积分.
Credits to @aschepis.
出于某种神秘的原因,如果我将我的部署命名为redis pod中的"redis",那么env变量将被注入到以后出现的其他pod中.
For some mysterious reason, if I name my deployment to be exactly "redis" in the redis pod, the env variables will be injected to other pods who comes later.
只要我将部署重命名为另一个名称,一切就恢复正常...
As long as I renamed the deployment to another name, things went back to normal...
再次感谢@aschepis.
Thanks again to @aschepis.
这篇关于kubectl向pod添加额外的env变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!