<p>When we were using <code>docker-compose</code>, we could map multiple aliases to one container/service via <code>links</code>. For example, <code>bucket1.s3</code> and <code>bucket2.s3</code> are aliases for container <code>s3</code>. Now as we are moving to kubernetes, I'm trying to do the same and link containers using service discovery. </p>

<p>What I can think of right now is to have one service for each bucket and each service will point to the same pod. This seems a lot of work. Is there way to make multiple DNS mapped to one service so <code>bucket1.s3.namespace.svc.cluster.local</code> and <code>bucket2.s3.namespace.svc.cluster.local</code> can both be resolved to <code>s3</code> service?</p>

shangsunset
<p>I believe what you might want is one service mapped to two deployments, you could have two <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">deployments</a> with names bucket1 and bucket2 and have them labeled with one label <code>app: buckets</code> then have a service with a selector including that label.</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: bucket1
  labels:
    app: buckets
spec:
  replicas: 3
  selector:
    matchLabels:
      app: buckets
  template:
    metadata:
      labels:
        app: buckets
    spec:
      containers:
      - name: bucket-container
        image: bucketimage
        ports:
        - containerPort: 80
</code></pre>

<hr>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: bucket2
  labels:
    app: buckets
spec:
  replicas: 3
  selector:
    matchLabels:
      app: buckets
  template:
    metadata:
      labels:
        app: buckets
    spec:
      containers:
      - name: bucket-container
        image: bucketimage
        ports:
        - containerPort: 80
</code></pre>

<hr>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: s3
spec:
  selector:
    app: buckets
  ports:
  - protocol: TCP
    port: 80
</code></pre>

<p>But a further question would be why would you want to have that? if both bucket1 and bucket2 contain different information/data.</p>

<p>With Kubernetes generally, you would have one deployment with multiple pods/replicas to serve data either in bucket1 or bucket2 assuming the data is the same. If the data is different why not have 2 deployments with different DNS entries.</p>

<p>If you are using K8s 1.11 or later, you can also <a href="https://coredns.io/2017/05/08/custom-dns-entries-for-kubernetes/" rel="nofollow noreferrer">tweak the coredns <code>ConfigMap</code></a> in the <code>kube-system</code> namespace to possibly get what you are trying to get to but in terms of DNS <a href="https://serverfault.com/questions/574072/can-we-have-multiple-cnames-for-a-single-name">you can't have a single record map to two CNAMEs</a> as per RFC 1034, Section 3.6.2.  You can't also hardcode IPs in Kubernetes since your IPs always change when your pods get created/removed.</p>
