如何在kubernetes中设置Deployment副本的不同环境变量 [英] how to set different environment variables of Deployment replicas in kubernetes

查看:2401
本文介绍了如何在kubernetes中设置Deployment副本的不同环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过将Deployment的副本现在设置为4,我有4个k8s吊舱.

I have 4 k8s pods by setting the replicas of Deployment to 4 now.

apiVersion: v1
kind: Deployment
metadata:
  ...
spec:
  ...
  replicas: 4
...

POD将获取数据库中的项目并使用它,数据库中的项目具有列class_name.

The POD will get items in a database and consume it, the items in database has a column class_name.

现在我只希望一个吊舱只获得一个class_name的物品. 例如pod1仅获得class_name等于class_name_1的项目,而pod2仅获得class_name等于class_name_2 ...

now I want one pod only get one class_name's item. for example pod1 only get item which class_name equals class_name_1, and pod2 only get item which class_name equals class_name_2...

所以我想将不同的class_name作为环境变量传递给不同的Deployment POD.我可以在Deployment的yaml文件中定义它吗?

So I want to pass different class_name as environment variables to different Deployment PODs. Can I define it in the yaml file of Deployment?

还是有其他方法可以实现我的目标?(例如,除了k8s中的Deployment之外)

Or is there any other way to achieve my goal?(like something other than Deployment in k8s)

推荐答案

部署或其他任何方法都无法帮助您实现目标.您的目标是某种逻辑,应通过应用程序中的代码来实现.

Neither Deployment nor anything else won't help to achieve your goal. Your goal is some kind of logic and it should be implemented via code in your application.

由于部署是同一应用程序的某些实例,因此可能对您有用的唯一事情是:使用多个部署,每个部署均用于其自己的任务.第一个可以获取class_name_1项,而其他class_name_2class_name_3等.但这不是一个好主意

Since the Deployment is some instances of the same application the only thing that might be useful for you is: using multiple deployments, each for its own task. The first could get class_name_1 item, while other class_name_2, class_name_3 etc. But it is not a good idea

这篇关于如何在kubernetes中设置Deployment副本的不同环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆