How to pass args to pods based on Ordinal Index in StatefulSets?

后端 未结 5 1237
再見小時候
再見小時候 2021-01-04 19:43

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!

5条回答
  •  长发绾君心
    2021-01-04 20:24

    Recommended way, see https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/#statefulset

    # Generate server-id from pod ordinal index.
    
    [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
    ordinal=${BASH_REMATCH[1]}
    
    # ${ordinal} now holds the replica number
    
    server-id=$((100 + $ordinal))
    
    # Copy appropriate conf.d files from config-map to emptyDir.
    if [[ $ordinal -eq 0 ]]; then
      # do something
    else
      # do something else
    fi
    

提交回复
热议问题