My service is not coming in the dns as hostname ,or anything that i can use to connect to it

8/18/2019

I have created a service(grpc-service) on my Kubernetes cluster(ubuntu 16.04) and cannot find it's dns Hostname

Also as a side node , my pod does not show up on nslookup (it works with busybox)

 kubectl exec -ti server-pod -- nslookup kubernetes.default
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"nslookup\": executable file not found in $PATH": unknown

expecting somthing similar to:

grpc-service.<namespace>.svc.<cluster-domain> which is usually
grpc-service.default.svc.cluster.local

but cannot find it ,neither can ping/curl it (curl -I grpc-service)

-- Tanmay Shrivastava
coredns
kubernetes

2 Answers

8/18/2019

@Tanmay Shrivastava

clusterIP: None
However, you can use headless service,  use statefulset

apiVersion: v1
kind: Service
metadata:
  name: httpd-service
  labels:
    app: httpd
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: httpd

Check this link: https://supergiant.io/blog/creating-stateful-apps-with-kubernetes-statefulsets/

-- Narendranath Reddy
Source: StackOverflow

8/20/2019

Take below as an example. Make sure you use correct labels/selectors. And use busybox version <= busybox:1.28.4 for tests. With newer version dns doesnt work correctly.


apiVersion: v1
kind: Pod
metadata:
  name: busybox-pod
  labels:
    app: busybox
spec:
  containers:
  - image: busybox:1.28.4
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: busybox
  restartPolicy: Always
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx
spec:
  hostNetwork: true
  containers:
  - name: client-pod
    image: nginx        
---
apiVersion: v1
kind: Service
metadata:
  name: server
  labels:
    app: nginx
spec:
  clusterIP: None
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: nginx
---

Checking:

kubectl get all -o wide
NAME              READY   STATUS    RESTARTS   AGE    IP            NODE                                                NOMINATED NODE   READINESS GATES
pod/busybox-pod   1/1     Running   0          5m6s   10.44.2.6     gke-standard-cluster-1-default-pool-00736803-xn08   <none>           <none>
pod/nginx-pod     1/1     Running   0          5m6s   10.164.0.16   gke-standard-cluster-1-default-pool-00736803-xn08   <none>           <none>


NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE    SELECTOR
service/kubernetes   ClusterIP   10.110.0.1   <none>        443/TCP   71m    <none>
service/server       ClusterIP   None         <none>        80/TCP    5m7s   app=nginx



kubectl describe service server
Name:              server
Namespace:         default
Labels:            app=nginx
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"nginx"},"name":"server","namespace":"default"},"spec":{"...
Selector:          app=nginx
Type:              ClusterIP
IP:                None
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.164.0.16:80
Session Affinity:  None
Events:            <none>



kubectl -n default exec -ti busybox-pod -- nslookup kubernetes.default
Server:    10.110.0.10
Address 1: 10.110.0.10 kube-dns.kube-system.svc.cluster.local

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


kubectl -n default exec -ti busybox-pod -- ping server
PING server (10.164.0.16): 56 data bytes
64 bytes from 10.164.0.16: seq=0 ttl=64 time=0.089 ms
64 bytes from 10.164.0.16: seq=1 ttl=64 time=0.129 ms
64 bytes from 10.164.0.16: seq=2 ttl=64 time=0.156 ms
64 bytes from 10.164.0.16: seq=3 ttl=64 time=0.124 ms


kubectl -n default exec -ti busybox-pod -- cat /etc/resolv.conf
nameserver 10.110.0.10
search default.svc.cluster.local svc.cluster.local cluster.local 
options ndots:5
-- VKR
Source: StackOverflow