Pods do not resolve the domain names of a service through ingress

9/6/2018

I have a problem that my pods in minikube cluster are not able to see the service through the domain name.

to run my minikube i use the following commands (running on windows 10):
minikube start --vm-driver hyperv;
minikube addons enable kube-dns;
minikube addons enable ingress;

This is my deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    run: hello-world
  name: hello-world
  namespace: default
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      run: hello-world
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: hello-world
    spec:
      containers:
      - image: karthequian/helloworld:latest
        imagePullPolicy: Always
        name: hello-world
        ports:
        - containerPort: 80
          protocol: TCP
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30

this is the service.yaml:

apiVersion: v1                                                             
kind: Service                                                              
metadata:                                                                  
  labels:                                                                  
    run: hello-world                                                       
  name: hello-world                                                        
  namespace: default                                                       
  selfLink: /api/v1/namespaces/default/services/hello-world                
spec:                                                                      
  ports:                                                                   
  - nodePort: 31595                                                        
    port: 80                                                               
    protocol: TCP                                                          
    targetPort: 80                                                         
  selector:                                                                
    run: hello-world                                                       
  sessionAffinity: None                                                    
  type: ExternalName
  externalName: minikube.local.com                                                           
status:                                                                    
  loadBalancer: {}                                                        

this is my ingress.yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: minikube-local-ingress
spec:
  rules:
  - host: minikube.local.com
    http:
      paths:
      - path: /
        backend:
          serviceName: hello-world
          servicePort: 80

So, if i go inside the hello-world pod and from /bin/bash will run curl minikube.local.com or nslookup minikube.local.com.

So how can i make sure that the pods can resolve the DNS name of the service? I know i can specify hostAlias in the deployment definition, but is there an automatic way tht will allow to update the DNS of kubernetes?

-- GrimSmiler
dns
kubernetes
minikube

1 Answer

9/6/2018

So, you want to expose your app on Minikube? I've just tried it using the default ClusterIP service type (essentially, removing the ExternalName stuff you had) and with this YAML file I can see your service on https://192.168.99.100 where the Ingress controller lives:

screen shot of hello-world app in browser

The service now looks like so:

apiVersion: v1
kind: Service
metadata:
  labels:
    run: hello-world
  name: hello-world
spec:
  ports:
  - port: 80
    targetPort: 80
  selector:
    run: hello-world

And the ingress is:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: minikube-local-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host:
    http:
      paths:
      - path: /
        backend:
          serviceName: hello-world
          servicePort: 80

Note: Within the cluster your service is now available via hello-world.default (that's the DNS name assigned by Kubernetes within the cluster) and from the outside you'd need to map, say hello-world.local to 192.168.99.100 in your /etc/hosts file on your host machine.

Alternatively, if you change the Ingress resource to - host: hello-world.local then you can (from the host) reach your service using this FQDN like so: curl -H "Host: hello-world.local" 192.168.99.100.

-- Michael Hausenblas
Source: StackOverflow