title: How to set hostname for kubernetes pod in statefulset
body: <p>I am using statefulset and I spin up multiple pods but they are not replica of each other. I want to set the hostname of the pods and passing these hostname as a env variable to all the pods so that they can communicate with each other.</p>
  
  <p>I tried to use hostname under pod spec but hostname is never to set to specified hostname. However, it is set to hostname as podname-0.</p>
  
  <pre><code># Source: testrep/templates/statefulset.yaml
  apiVersion: apps/v1
  kind: StatefulSet 
  metadata:
    name: orbiting-butterfly-testrep
    labels:
      app.kubernetes.io/name: testrep
      helm.sh/chart: testrep-0.1.0
      app.kubernetes.io/instance: orbiting-butterfly
      app.kubernetes.io/managed-by: Tiller
  spec:
    replicas: 1
    selector:
      matchLabels:
        app.kubernetes.io/name: testrep
        app.kubernetes.io/instance: orbiting-butterfly
    strategy:
      type: Recreate
    template:
      metadata:
        labels:
          app.kubernetes.io/name: testrep
          app.kubernetes.io/instance: orbiting-butterfly
      spec:
        nodeSelector:
            testol: ad3
         hostname: test1
         containers:
          - name: testrep
            image: "test/database:v1"
            imagePullPolicy: IfNotPresent
            env:
             - name: DB_HOSTS
               value: test1,test2,test3
  </code></pre>