How to access a service from another namespace in kubernetes

5/6/2020

I have the zipkin deployment and service below as you can see zipkin is located under monitoring namespace the, i have an env variable called ZIPKIN_URL in each of my pods which are running under default namespace, this varibale takes this URL http://zipkin:9411/api/v2/spans but since zipkin is running in another namespace i tried this :

http://zipkin.monitoring.svc.cluster.local:9411/api/v2/spans

i also tried this format :

http://zipkin.monitoring:9411/api/v2/spans

but when i check the logs of my pods, i see connection refused exception

when i exec into one of my pods and try curl http://zipkin.tools.svc.cluster.local:9411/api/v2/spans

its shows me Mandatory parameter is missing: serviceNameroot

Here is zipkin resource :

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: zipkin
  namespace: monitoring
spec:
  template:
    metadata:
      labels:
        app: zipkin
    spec:
      containers:
      - name: zipkin
        image: openzipkin/zipkin:2.19.3
        ports:
        - containerPort: 9411

---

apiVersion: v1
kind: Service
metadata:
  name: zipkin
  namespace: monitoring
spec:
  selector:
    app: zipkin
  ports:
    - name: http
      port: 9411
      protocol: TCP
  type: ClusterIP
-- touati ahmed
kubernetes
kubernetes-service

1 Answer

5/7/2020

What you have is correct, your issue is likely not DNS. You can confirm by doing just a DNS lookup and comparing that to the IP of the Service.

-- coderanger
Source: StackOverflow