本文介绍了有没有办法在kubernetes statefulset配置文件中获取Pod的序号索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Kubernetes 1.9.0,想知道是否有办法在其statefulset配置文件中访问Pod的常规索引".我们想为容器的标签动态分配一个值(从顺序索引派生),然后在规范下使用它来设置容器的亲和力(或反亲和力).

We are on Kubernetes 1.9.0 and wonder if there is way to access an "ordinal index" of a pod with in its statefulset configuration file. We like to dynamically assign a value (that's derived from the ordinal index) to the pod's label and later use it for setting pod affinity (or antiaffinity) under spec.

或者,在statefulset配置文件中可以使用pod的实例名称吗?如果是这样,我们希望可以从中提取序号索引并动态分配给标签(以供以后用于亲和力).

Alternatively, is the pod's instance name available with in statefulset configfile? If so, we can hopefully extract ordinal index from it and dynamically assign to a label (for later use for affinity).

推荐答案

立即获得唯一的选择是从主机名中提取索引

Right now the only option is to extract index from host name

lifecycle:
  postStart:
    exec:
      command: ["/bin/sh", "-c", "export INDEX=${HOSTNAME##*-}"]

这篇关于有没有办法在kubernetes statefulset配置文件中获取Pod的序号索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:19