Is there a way to get ordinal index of a pod with in kubernetes statefulset configuration file?

依然范特西╮ 提交于 2019-12-05 23:31:55

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

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

You could essentially get the unique name of your pod in statefulset as an environment variable, you have to extract the ordinal index from it though

In container's spec:

env:
  - name: cluster.name
    value: k8s-logs
  - name: node.name
    valueFrom:
      fieldRef:
        fieldPath: metadata.name
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!