Why I cannot resolve the domain from service (type : ExternalName) through my pod (same namespace)?

79 Views Asked by At

I am using docker locally (for training purposes), I want to access the domain from Service (type: ExternalName) inside the same cluster in Kubernetes through my curl pod, so first I created a Pod and Service using Yaml file

but when I ran it inside the curl this error appeared

connecting to external-service.default.svc.cluster.local:80: resolving host external-service.default.svc.cluster.local: lookup external-service.default.svc.cluster.local: no such host/

I have already checked that the Pod and all services were running and they were located in the same namespace

I want to access the domain from Service (type: ExternalName) inside the same cluster in Kubernetes through my curl pod, so first I created a Pod and Service using the YAML file

apiVersion: v1
kind: Service
metadata:
  name: external-service
  labels:
    name: external-service
spec:
  type: ExternalName
  externalName: example.com
  ports:
    - port: 80

---

apiVersion: v1
kind: Pod
metadata:
  name: curl
  labels:
    name: curl
spec:
  containers:
    - name: curl
      image: mydocument/nginx-curl

I get into the curl by using this command

kubectl exec -it curl -- /bin/sh

and I use this command inside the curl

curl http://external-service.default.svc.cluster.local

or

curl http://external-service.default.svc.cluster.local:80

the result

connecting to external-service.default.svc.cluster.local:80: resolving host external-service.default.svc.cluster.local: lookup external-service.default.svc.cluster.local: no such host/

I have already checked that the Pod and all services were running and they located in the same namespace

0

There are 0 best solutions below