kubernetes: Application in one pod not able to connect to mongodb on another pod.
Is this a BUG REPORT or FEATURE REQUEST?:
Uncomment only one, leave it on its own line:
/kind bug
What happened: I checked the logs of the application I am using and it says : Caused by: java.net.UnknownHostException: mongodb: Inside the application config file I have used the host name as mongodb and i have created a service for the mongo deployment with the service name as : mongodb.
What you expected to happen: My understanding is that we can use the service names so that application can connect to each other. Help is much appreciated. Thanks.
Anything else we need to know?: mongo.yaml
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: mongodb labels: run: mongodb spec: replicas: 1 template: metadata: labels: run: mongodb spec: containers: - name: mongodb image: mongo ports: - containerPort: 27017 protocol: TCP
kind: Service apiVersion: v1 metadata: name: mongodb spec: selector: run: mongodb ports: - name: port1 protocol: TCP port: 27017 targetPort: 27017 type: NodePort
application.yaml
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: application labels: run: application spec: replicas: 1 template: metadata: labels: run: application spec: containers: - name: application image: localhost:5000/application ports: - containerPort: 8085 protocol: TCP
kind: Service apiVersion: v1 metadata: name: application spec: selector: run: application ports: - name: port1 protocol: TCP port: 8085 targetPort: 8085 type: NodePort
Environment:
-
Kubernetes version (use
kubectl version): Client Version: version.Info{Major:“1”, Minor:“9”, GitVersion:“v1.9.4”, GitCommit:“bee2d1505c4fe820744d26d41ecd3fdd4a3d6546”, GitTreeState:“clean”, BuildDate:“2018-03-12T16:29:47Z”, GoVersion:“go1.9.3”, Compiler:“gc”, Platform:“linux/amd64”} Server Version: version.Info{Major:“1”, Minor:“9”, GitVersion:“v1.9.4”, GitCommit:“bee2d1505c4fe820744d26d41ecd3fdd4a3d6546”, GitTreeState:“clean”, BuildDate:“2018-03-12T16:21:35Z”, GoVersion:“go1.9.3”, Compiler:“gc”, Platform:“linux/amd64”} -
Cloud provider or hardware configuration: AWS
-
OS (e.g. from /etc/os-release): NAME=“Red Hat Enterprise Linux Server” VERSION=“7.4 (Maipo)” ID=“rhel” ID_LIKE=“fedora” VARIANT=“Server” VARIANT_ID=“server” VERSION_ID=“7.4” PRETTY_NAME=“Red Hat Enterprise Linux Server 7.4 (Maipo)” ANSI_COLOR=“0;31” CPE_NAME=“cpe:/o:redhat:enterprise_linux:7.4:GA:server” HOME_URL=“https://www.redhat.com/” BUG_REPORT_URL=“https://bugzilla.redhat.com/”
REDHAT_BUGZILLA_PRODUCT=“Red Hat Enterprise Linux 7” REDHAT_BUGZILLA_PRODUCT_VERSION=7.4 REDHAT_SUPPORT_PRODUCT=“Red Hat Enterprise Linux” REDHAT_SUPPORT_PRODUCT_VERSION=“7.4”
- Kernel (e.g.
uname -a): Linux k8s-master 3.10.0-693.21.1.el7.x86_64 #1 SMP Fri Feb 23 18:54:16 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux - Install tools: kubeadm @kubernetes/sig-aws-bugs @kubernetes/sig-network
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 20 (1 by maintainers)
I ran into this problem for this last 2 days as well. Still trying to find a way through but no luck yet.
In case, anyone does find something, please kindly share.
kubectl describe pod mongodb
…make a note of IP and connect to mongodb on this IP from your app
Hello, i have the same issue, my nodejs app pod can’t reach mongodb pod,
Connection error: MongoNetworkError: failed to connect to server [mongo:27017] on first connect [Error: getaddrinfo EAI_AGAIN mongo at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:26) { name: 'MongoNetworkError', [Symbol(mongoErrorContextSymbol)]: {} }]but when I target the mongo service Ip [10.244.2.26:27017] then it works
Trying to connect to 10.244.2.26/my-db-name MongoDB database (node:174) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. (node:174) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor. db connection openso i think there is a problem with dns i can’t figure it out 😦