简体   繁体   English

kubectl向pod添加额外的env变量

[英]kubectl adding extra env variable to pod

Ok here is the story: 好吧,这里是故事:

I am using minikube to host my application: 我正在使用minikube托管我的应用程序:

1 pod running redis (redis on ubuntu:14.04) 1个Pod运行Redis(Ubuntu上的redis:14.04)

1 pod running my php application (php7-apache) 1个Pod运行我的php应用程序(php7-apache)

I realised that if I setup my redis pod first then my php pod, my php pod will have these extra env variables: 我意识到,如果我先设置Redis Pod,然后再设置PHP Pod,则我的PHP Pod将具有以下额外的env变量:

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

These variables override the port I setup for my php project. 这些变量将覆盖我为php项目设置的端口。

To counter it, I have to explicitly set the REDIS_PORT in my yaml file for my php deployment. 为了解决这个问题,我必须在我的yaml文件中为PHP部署显式设置REDIS_PORT。

Any idea why this happened? 知道为什么会这样吗? And clean way to simply avoid this? 干净的方法可以避免这种情况?

Thanks! 谢谢!

Ooooook, got the answer. 噢,知道了。

Credits to @aschepis. 归功于@aschepis。

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. 出于某种神秘的原因,如果我将我的部署命名为redis pod中的“ redis”,则env变量将注入到以后出现的其他pod中。

As long as I renamed the deployment to another name, things went back to normal... 只要将部署重命名为另一个名称,一切就恢复正常了。

Thanks again to @aschepis. 再次感谢@aschepis。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM