Containers on Statefulset not being registred on minikube dns

4/9/2019

I'm trying to setup a zookeeper cluster (3 replicas) but each host can't connect to another and I really don't know where's the problem. It's creating 3 pods successfully with names like

zookeeper-0.zookeeper-internal.default.svc.cluster.local
zookeeper-1.zookeeper-internal.default.svc.cluster.local
zookeeper-2.zookeeper-internal.default.svc.cluster.local

but when connected to one of them and trying to connect to the open port it returns the Unknown host message:

zookeeper@zookeeper-0:/opt$ nc -z zookeeper-1.zookeeper-internal.default.svc.cluster.local 2181
zookeeper-1.zookeeper-internal.default.svc.cluster.local: forward host lookup failed: Unknown host

My YAML file is here

I really appreciate any help.

-- Ranieri Mazili
kubernetes
minikube

1 Answer

4/9/2019

Did you create a headless service as you had mentioned in your yaml - serviceName: zookeeper-internal ?

You need to create this service (update the port) to access the zookeeper-0.zookeeper-internal.default.svc.cluster.local

apiVersion: v1
kind: Service
metadata:
  labels:
    app: zookeeper-cluster-dev
    name: zookeeper
  name: zookeeper-internal
spec:
  ports:
  - name: zookeeper-port
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    name: zookeeper
  clusterIP: None
  type: ClusterIP

Service is required. But it does not expose anything outside the cluster. It is only within cluster. Any pods can access this service within the cluster. So you can not access it from your browser unless you expose it via NodePort / LoadBalancer / Ingress!

-- vins
Source: StackOverflow