【问题标题】:Set custom oridinal number for pod in kubernetes statefulset not the default 0在 kubernetes statefulset 中为 pod 设置自定义序号,而不是默认的 0
【发布时间】:2019-07-26 06:11:23
【问题描述】:

在Kubernetes statefulset中,序号以0开头--> N。有什么方法可以将起始序号设置为自定义数字。

redis-cluster-10   1/1     Running   0          12h
redis-cluster-11   1/1     Running   2          17h
redis-cluster-12   1/1     Running   0          17h
redis-cluster-13   1/1     Running   0          17h
redis-cluster-14   1/1     Running   2          17h
redis-cluster-15   1/1     Running   0          17h

【问题讨论】:

    标签: kubernetes kubernetes-statefulset


    【解决方案1】:

    没有。它不支持开箱即用。您可能需要自定义 statefulset 控制器。

    【讨论】:

      【解决方案2】:

      我认为这是您可能感兴趣的部分:

      https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/statefulset/stateful_set_utils.go

      // getParentNameAndOrdinal gets the name of pod's parent StatefulSet and pod's ordinal as extracted from its Name. If
      // the Pod was not created by a StatefulSet, its parent is considered to be empty string, and its ordinal is considered
      // to be -1.
      func getParentNameAndOrdinal(pod *v1.Pod) (string, int) {
          parent := ""
          ordinal := -1
          subMatches := statefulPodRegex.FindStringSubmatch(pod.Name)
          if len(subMatches) < 3 {
              return parent, ordinal
          }
          parent = subMatches[1]
          if i, err := strconv.ParseInt(subMatches[2], 10, 32); err == nil {
              ordinal = int(i)
          }
          return parent, ordinal
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-09
        • 2020-04-05
        • 2021-09-06
        • 2016-09-17
        • 2011-08-01
        • 2021-05-02
        相关资源
        最近更新 更多