In Kubernetes, how to set pods' names when using replication controllers?

前端 未结 3 970
半阙折子戏
半阙折子戏 2021-02-02 12:22

I have a simple replication controller yaml file which looks like this:

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
spec:
  replicas: 3
           


        
3条回答
  •  旧巷少年郎
    2021-02-02 12:59

    This can be implemented using statefulsets which is out of beta since version 1.9. Quoting the documentation: When using kind: StatefulSet,

    Pods have a unique identity that is comprised of an ordinal, a stable network identity, and stable storage. The identity sticks to the Pod, regardless of which node it’s (re)scheduled on.

    Each Pod in a StatefulSet derives its hostname from the name of the StatefulSet and the ordinal of the Pod. The pattern for the constructed hostname is $(statefulset name)-$(ordinal).

    So in the example above, you would get nginx-0,nginx-1,nginx-2

提交回复
热议问题