title: How does StatefulSet assigns hostname to containers in Kubernetes
body: <p>How does StatefulSet spec in Kubernetes assigns the hostname to each container in case we set <code>hostNetwork: true</code>? I have the following spec (similar):</p>
  
  <pre><code>apiVersion: apps/v1beta1
  kind: StatefulSet
  metadata:
    name: abc
  spec:
    serviceName: abc
    replicas: 2
    template:
      metadata:
        labels:
          app: abc
      spec:
        hostNetwork: true
        #hostame: test
        terminationGracePeriodSeconds: 10
        containers:
        - name: abc
          image: abc.xyz.com:9001/abc:01.00.00.00
          ports:
          - name: api-port
            containerPort: 9000
            hostPort: 9000
          readinessProbe:
            httpGet:
              path: /api
              port: api-port
              scheme: HTTPS
  </code></pre>
  
  <p>Now after running the <code>kubectl create</code> command, I see that the first container when comes up picks the hostname of the host since we have specified <code>hostNetwork: true</code>, but the second container when comes up has hostname something like <code>abc-0.abc.default.svc.cluster.local</code>.</p>
  
  <ul>
  <li>Kubectl version: 1.7.3</li>
  <li>Docker version: 1.12.6</li>
  </ul>
  
  <p>Also, the only service running is the Kubernetes service. I didn't create abc service myself.</p>
  
  <p><code>
  NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
  kubernetes   10.96.0.1    &lt;none&gt;        443/TCP   1d
  </code></p>