<p>I have a Service that is deployed as a StatefulSet in one Kubernetes cluster, and with static IPs in another cluster.</p>
<pre><code>kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: statefulset-name
spec:
  ...
</code></pre>
<p>I want to use the same host to access the service in both clusters. I also need to have one hostname per endpoint (e.g the pod and the static IP).</p>
<p>Given that I get <code>&lt;pod&gt;.&lt;statefulset&gt;.&lt;namespace&gt;</code> in the Kubernetes-native case, how can I expose my static IPs with the same hosts?</p>

Martín Coll
<p>A StatefulSet will eventually generate a Service for the Pod. Digging into the <a href="https://github.com/kubernetes/kubernetes/blob/da23196df6d519c657a27c68932c62aa35e87dc5/pkg/controller/util/endpoint/controller_utils.go#L162" rel="nofollow noreferrer">source code</a> I found that the pod <code>subdomain</code> will map to the address <code>hostname</code> in the Endpoints resource.</p>
<p>Assuming that you have 2 replicas in the first case and 2 static IPs in the second one, you need to create the Service and Endpoints as such:</p>
<pre><code>kind: Service
apiVersion: v1
metadata:
  name: same-as-statefulset
spec:
  clusterIP: None
  ports:
  - port: 80
    targetPort: 80
---
kind: Endpoints
apiVersion: v1
metadata:
  name: same-as-statefulset
subsets:
  - addresses:
    - ip: 10.192.255.0
      hostname: same-as-pod-0
    - ip: 10.192.255.1
      hostname: same-as-pod-1
    ports:
    - port: 80
</code></pre>
