We have two clusters. cluster1 has namespace- test1 and a service running as clusterip we have to call that service from another cluster(cluster2) from namespace dev1.
I have defined externalname service in cluster2 pointing to another externalname service in cluster1. And externalname service in cluster1 points to the original service running as clusterip.
In cluster2:
kind: Service
apiVersion: v1
metadata:
name: service
namespace: dev1
labels:
app: service
spec:
selector:
app: service
type: ExternalName
sessionAffinity: None
externalName: service2.test.svc.cluster.local
status:
loadBalancer: {}
In cluster1:Externalname service
kind: Service
apiVersion: v1
metadata:
name: service2
namespace: test1
labels:
app: service
spec:
selector:
app: service
type: ExternalName
sessionAffinity: None
externalName: service1.test1.svc.cluster.local
status:
loadBalancer: {}
in cluster1 clusterip service:
kind: Service
apiVersion: v1
metadata:
name: service1
namespace: test1
labels:
app: service1
spec:
ports:
- name: http
protocol: TCP
port: 9099
targetPort: 9099
selector:
app: service1
clusterIP: 102.11.20.100
type: ClusterIP
sessionAffinity: None
status:
loadBalancer: {}
But, there is no hit to the service in cluster1. I tried to add spec:port:9099 in externalname services as well, still it does not work.
What could be the reason. Nothing specific in logs too
This is not what ExternalName
services are for.
ExternalName
services are used to have a cluster internal service name that forwards traffic to another (internal or external) DNS name. In practice what an ExternalName
does is create a CNAME record that maps the external DNS name to a cluster-local name. It does not expose anything out of your cluster. See documenation.
What you need to do is expose your services outside of your kubernetes clusters and they will become usable from the other cluster as well.
There are different ways of doing this. For example:
NodePort service
: when using a NodePort, your service will be exposed on each node in the cluster on a random high port (by default in the 30000-32767 range). If your firewall allows traffic to such port you could reach your service from using that port.LoadBalancer service
: if you are running kubernetes in an environment that supports Load Balancer allocation you could expose your service to the internet using a load balancer.Ingress
: if you have an ingress controller running in your cluster you could expose your workload using an Ingress
.On the other cluster, you could simply reach the service exposed.