如何基于StatefulSets中的序数索引将args传递到Pod? [英] How to pass args to pods based on Ordinal Index in StatefulSets?

查看:119
本文介绍了如何基于StatefulSets中的序数索引将args传递到Pod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据StatefulSets中的序数索引将不同的args传递给Pod?在StatefulSets文档中找不到答案.谢谢!

Is it possible to pass different args to pods based on their ordinal index in StatefulSets? Didn't find the answer on the StatefulSets documentation. Thanks!

推荐答案

我不知道使用非hacky的方法,但是我知道可以使用的hack.首先,StatefulSet中的每个Pod都有一个唯一的可预测名称.它可以通过向下API 或仅调用.因此,我将外壳程序脚本作为容器的入口点,然后该脚本获取了它的pod/主机名.从那里,它使用适用于特定主机的命令行args调用真实"可执行文件.

I don't know of a non-hacky way to do it, but I know a hack that works. First, each pod in a StatefulSet gets a unique predictable name. It can discover that name via the downward API or just by calling hostname. So I have shell script as then entrypoint to my container and that script gets it's pod/hostname. From there it calls the "real" executable using command line args appropriate for the specific host.

例如,我的脚本之一希望通过向下的api将pod名称以POD_NAME的形式映射到环境中.然后,它会执行以下操作:

For example, one of my scripts expects the pod name to be mapped into the environment as POD_NAME via downward api. It then does something like:

#!/bin/bash

pet_number=${POD_NAME##*-}

if [ pet_number == 0 ]
then
   # stuff here
fi

# etc.

这篇关于如何基于StatefulSets中的序数索引将args传递到Pod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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