# Hostname not resolved inside a pod

**URL:** <https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462>\
**Category:** General Discussions\
**Tags:** development\
**Created:** [March 12, 2019, 9:36pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462 "2019-03-12T21:36:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 12, 2019, 9:36pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/1 "2019-03-12T21:36:13Z")

</div>

–Everything fine here

PS C:\WINDOWS\system32\> kubectl exec busybox nslookup kubernetes  
Server: 10.96.0.10  
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: kubernetes  
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local

–Then I use this command to view the pods

PS C:\WINDOWS\system32\> kubectl get pods  
NAME READY STATUS RESTARTS AGE  
apple-app 1/1 Running 0 5d  
banana-app 1/1 Running 0 5d  
busybox 1/1 Running 4 4h

–However, here is the problem, could somebody help me, please?

PS C:\WINDOWS\system32\> kubectl exec busybox nslookup apple-app  
Server: 10.96.0.10  
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

nslookup: can’t resolve ‘apple-app’  
command terminated with exit code 1

– Thank you 🙂

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 13, 2019, 1:51am UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/2 "2019-03-13T01:51:30Z")

</div>

Do you have a Service object created for the Pod?

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 13, 2019, 1:39pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/3 "2019-03-13T13:39:10Z")

</div>

That was the code of apple-app:

apiVersion: v1  
kind: Pod  
metadata:  
name: apple-app  
labels:  
app: apple  
spec:  
containers:  
- name: apple-app  
image: hashicorp/http-echo  
args:  
- “-text=apple”

* * *

apiVersion: v1  
kind: Service  
metadata:  
name: apple-service  
spec:  
selector:  
app: apple  
ports:

- port: 5678 # Default port for image

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 13, 2019, 1:53pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/4 "2019-03-13T13:53:09Z")

</div>

Try hitting `apple-service` Instead of `apple-App`

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 13, 2019, 1:56pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/5 "2019-03-13T13:56:26Z")

</div>

Where? In the commands or in the code?

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 13, 2019, 2:07pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/6 "2019-03-13T14:07:24Z")

</div>

For command:

PS C:\WINDOWS\system32\> kubectl exec busybox nslookup apple-service  
Server: 10.96.0.10  
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: apple-service  
Address 1: 10.109.159.118 apple-service.default.svc.cluster.local

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 13, 2019, 2:14pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/7 "2019-03-13T14:14:56Z")

</div>

Ya for the command and for any code trying to communicate with the service that the pod is providing.

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 13, 2019, 2:19pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/8 "2019-03-13T14:19:38Z")

</div>

Well, I executed the command to see the service information (nslookup) but it doesn’t work for the pod and I want to know why it would be. On the other hand, the information I passed on to you is the only thing I executed for kubernetes.

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 13, 2019, 2:41pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/9 "2019-03-13T14:41:01Z")

</div>

Pods by default aren’t given domain names by default. They are temporary as they can come and go as they die and resurrect. [Services](https://kubernetes.io/docs/concepts/services-networking/service/) are the way to get around that and have a consistent way of communicating with the pods.

If you do need a domain to the pod there’s a little [guide](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pods) here on how,

I hope that was helpful. Let me know if that makes sense.

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 13, 2019, 2:50pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/10 "2019-03-13T14:50:34Z")

</div>

I’ve been reading that guide to kubernetes and more for pod domain, but I don’t understand it yet. Another question, is a domain really necessary for the pod? It turns out that I’m escalating into a microservice architecture and previously implemented nginx as an ingress controller. I’m currently advancing server discovery and everything locally. That’s why I’m asking this and I repeat: is it necessary for the pod to have a domain? Thanks for your help, could you guide me in a better way?

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 13, 2019, 3:18pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/11 "2019-03-13T15:18:37Z")

</div>

Is really necessary for a non-cloud microservice architecture? Implement a domain to a pod?

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 13, 2019, 4:29pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/12 "2019-03-13T16:29:07Z")

</div>

If you’re exposing it to another Service, either internal or external then yes. You can still have a non micro-service application in the pod but this should still be governed by a [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) and a Service.

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 13, 2019, 4:39pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/13 "2019-03-13T16:39:25Z")

</div>

Well in my case with these two services and pods, as it could help me this? Maybe if I have a service as the front end?

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 13, 2019, 4:54pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/14 "2019-03-13T16:54:02Z")

</div>

There is all my information:

PS C:\WINDOWS\system32\> kubectl get svc  
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE  
apple-service ClusterIP 10.107.197.48 5678/TCP 5m  
banana-service ClusterIP 10.96.61.97 5678/TCP 4m  
kubernetes ClusterIP 10.96.0.1 443/TCP 47d

PS C:\WINDOWS\system32\> kubectl get pods  
NAME READY STATUS RESTARTS AGE  
apple-app 1/1 Running 0 5m  
banana-app 1/1 Running 0 4m  
busybox 1/1 Running 0 2m

PS C:\WINDOWS\system32\> kubectl get pods --namespace=ingress-nginx  
NAME READY STATUS RESTARTS AGE  
nginx-ingress-controller-57548b96c8-psgd8 1/1 Running 0 5d

PS C:\WINDOWS\system32\> kubectl get ingress  
NAME HOSTS ADDRESS PORTS AGE  
example-ingress \* localhost 80 4m

Can you help me with my hostname problem? Thank you.

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 13, 2019, 5:34pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/15 "2019-03-13T17:34:22Z")

</div>

Ya not a problem.

To get the DNS name and expose the service to the ingress you’ll be looking at something like the following, I don’t know the full extent of all the services you want so this is just a sample pattern I tend to follow when exposing services. If you just need it to be internally available to the cluster remove the ingress section.

```auto
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: apple-app-servie
  namespace: default
spec:
  rules:
  - host: mydomain.com
    http:
      paths:
      - backend:
          serviceName: apple-service
          servicePort: <Port> // Port being exposed
---
apiVersion: v1
kind: Service
metadata:
  name: apple-service
spec:
  type: ClusterIP
  selector:
    app: app
  ports:
  - port: <Port> // Port being exposed
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: apple-app-deploy
spec:
  selector:
    matchLabels:
      app: apple
  replicas: 1
  template:
    metadata:
      name: apple-app
      labels:
        app: apple
    spec:
      containers:
      - name: myapp
        image: hashicorp/http-echo
        args:
        - “-text=apple”
        ports:
        - containerPort: <Port> // Port to being exposed

```

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 14, 2019, 5:13pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/16 "2019-03-14T17:13:06Z")

</div>

I’m sorry for not answering you, but what you sent me didn’t work, and then I switched the application to a more complete application. I’ll send you the information in a little while.

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 14, 2019, 5:26pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/17 "2019-03-14T17:26:13Z")

</div>

No worries. Let me know what didn’t work when you get a chance. That was just meant to be a skaffold so I may have ommitted something by mistake.

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 14, 2019, 7:05pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/18 "2019-03-14T19:05:39Z")

</div>

Here is all the information of a complete application that if it works, is with NGINX ingress controller, and kube-dns (supposedly).

PS C:\WINDOWS\system32\> kubectl get pods  
NAME READY STATUS RESTARTS AGE  
busybox 1/1 Running 6 22h  
mongo-7bb58d7dc6-whzqk 1/1 Running 0 22h  
web-7c6f8b9bd9-hjzw8 1/1 Running 0 22h

PS C:\WINDOWS\system32\> kubectl get all  
NAME READY STATUS RESTARTS AGE  
pod/busybox 1/1 Running 6 22h  
pod/mongo-7bb58d7dc6-whzqk 1/1 Running 0 22h  
pod/web-7c6f8b9bd9-hjzw8 1/1 Running 0 22h

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE  
service/kubernetes ClusterIP 10.96.0.1 443/TCP 49d  
service/mongo ClusterIP 10.101.199.128 27017/TCP 22h  
service/web ClusterIP 10.105.4.178 80/TCP 22h

NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE  
deployment.apps/mongo 1 1 1 1 22h  
deployment.apps/web 1 1 1 1 22h

NAME DESIRED CURRENT READY AGE  
replicaset.apps/mongo-7bb58d7dc6 1 1 1 22h  
replicaset.apps/web-7c6f8b9bd9 1 1 1 22h

---

<div class="post-metadata">

**Author:** ![MoisesQ](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoisesQ](https://discuss.kubernetes.io/u/MoisesQ)\
**Post date:** [March 14, 2019, 7:11pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/19 "2019-03-14T19:11:22Z")

</div>

Here is the previous problem, about the pods, which I think is because of the deployment that generates pods if there are any problems.

PS C:\WINDOWS\system32\> kubectl exec busybox nslookup kubernetes  
Server: 10.96.0.10  
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: kubernetes  
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local  
PS C:\WINDOWS\system32\> kubectl exec busybox nslookup web  
Server: 10.96.0.10  
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: web  
Address 1: 10.105.4.178 web.default.svc.cluster.local  
PS C:\WINDOWS\system32\> kubectl exec busybox nslookup mongo  
Server: 10.96.0.10  
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: mongo  
Address 1: 10.101.199.128 mongo.default.svc.cluster.local  
PS C:\WINDOWS\system32\> kubectl exec busybox nslookup web-7c6f8b9bd9-hjzw8  
Server: 10.96.0.10  
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

nslookup: can’t resolve ‘web-7c6f8b9bd9-hjzw8’  
command terminated with exit code 1

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 15, 2019, 12:41pm UTC](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462/20 "2019-03-15T12:41:03Z")

</div>

You’re still not doing to be able to use the nslookup on the pod like that. Any traffic that goes to the Pod will be handle through the service.

[Next page](https://discuss.kubernetes.io/t/hostname-not-resolved-inside-a-pod/5462.md?page=2)
