Hi there,
I’d like to configure StatefulSet and Headless service for MongoDB with Mongo-Express.
However, I cannot figure out the hostname of my master node which could be resolved to an IP address.
I’d like to pass the hostname to mongo-express deployment file, that mongo-express can connect to the master node.
I found this thread, where it is recommended to use:
podname-{replica-index}.{serviceName}.default.svc.cluster.local
In my case it is:
mongodb-deployment-0.mongodb-service.default.svc.cluster.local
however, when I type:
kubectl run -it --rm debug --image=tutum/dnsutils --restart=Never nslookup mongodb-deployment-0.mongodb-service.default.svc.cluster.local
I get:
Server: 10.96.0.10
Address: 10.96.0.10#53
** server can't find mongodb-deployment-0.mongodb-service.default.svc.cluster.local: NXDOMAIN
When I call nslookup
for my service, then I get:
kubectl run -it --rm debug --image=tutum/dnsutils --restart=Never nslookup mongodb-service
Server: 10.96.0.10
Address: 10.96.0.10#53
Name: mongodb-service.default.svc.cluster.local
Address: 10.244.0.4
Name: mongodb-service.default.svc.cluster.local
Address: 10.244.0.5
Name: mongodb-service.default.svc.cluster.local
Address: 10.244.0.3
Others:
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mongo-express-859f75dd4f-ndt9j 1/1 Running 0 15m 10.244.0.6 minikube <none> <none>
mongodb-deployment-0 1/1 Running 0 19m 10.244.0.3 minikube <none> <none>
mongodb-deployment-1 1/1 Running 0 18m 10.244.0.4 minikube <none> <none>
mongodb-deployment-2 1/1 Running 0 18m 10.244.0.5 minikube <none> <none>
mongo-express-859f75dd4f-ndt9j
- it is running because I hardcoded IP address in the yaml
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 21m
mongo-express-service LoadBalancer 10.110.59.92 <pending> 8081:30000/TCP 16m
mongodb-service ClusterIP None <none> 27017/TCP 20m
I’d appreciate any help or comment. I have spent a lot of time researching this and reading following materials:
Cluster information:
Kubernetes version: minikube version: v1.32.0
Cloud being used: (put bare-metal if not on a public cloud): bare-metal
Installation method: home-brew
Host OS: MacOS M1
CNI and version:
CRI and version:
You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.