Hostname not resolved inside a pod

development

#1

–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 :slight_smile:


#2

Do you have a Service object created for the Pod?


#3

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

#4

Try hitting apple-service Instead of apple-App


#5

Where? In the commands or in the code?


#6

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


#7

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


#8

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.


#9

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 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 here on how,

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


#10

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?


#11

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


#12

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 and a Service.


#13

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?


#14

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.


#15

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.

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

#16

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.


#17

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.


#18

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


#19

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


#20

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.