By default, in Kubernetes, an internal address is created when a service is deployed. It is possible to reach this service through the following address: my-svc.my-namespace.svc.cluster-domain.example
(doc reference)
I would like to add more internal addresses to this service when it gets deployed (I use helm to deploy my services). I want to be able to access the same service through my-svc
, my-svc-1
and my-svc-2
. I was wondering if I could add these aliases into the deployment process so it automatically generates multiple entries for the same address.
As a workaround, I read that I can use CoreDNS and add CNAME entries but that's definitely not the optimal choice since I don't know if I can automatically add these entries into CoreDNS when I deploy the service. If that's possible, I'd be happy to know how it can be achieved.
Solution mentioned by Manuel is correct. I tested it and it works. I used the following yamls:
Regular service expose:
apiVersion: v1
kind: Service
metadata:
labels:
run: my-svc
name: my-svc
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: my-svc
ExternalName services:
---
apiVersion: v1
kind: Service
metadata:
name: my-svc-1
spec:
type: ExternalName
externalName: my-svc.default.svc.cluster.local
---
apiVersion: v1
kind: Service
metadata:
name: my-svc-2
spec:
type: ExternalName
externalName: my-svc.default.svc.cluster.local
As expected, ExternalName type service creates CNAME records pointing to my-svc
$ dig my-svc-2 +search
;; QUESTION SECTION:
;my-svc-2.default.svc.cluster.local. IN A
;; ANSWER SECTION:
my-svc-2.default.svc.cluster.local. 13 IN CNAME my-svc.default.svc.cluster.local.
my-svc.default.svc.cluster.local. 13 IN A 10.100.222.87