Hi All I am unable to connect to mongo atlas database as a service outside the kubernetes cluster from my kubernetes cluster.
here are the steps I followed.
In my code in nodejs used dbUri= 'mongodb://username:password' + process.env.MONGO_URL +'/database-name'
kind: Service
apiVersion: v1
metadata:
name: mongo-cluster-ip-service
spec:
type: ClusterIP
ports:
- port: 27017
targetPort: 27017
kind: Endpoints
apiVersion: v1
metadata:
name: mongo-cluster-ip-service
subsets:
- addresses:
- ip: 35.187.27.116
ports:
- port: 27017
- addresses:
- ip: 35.241.213.79
ports:
- port: 27017
- addresses:
- ip: 104.155.120.154
ports:
- port: 27017
apiVersion: apps/v1
kind: Deployment
metadata:
name: user-reg-auth-deployment
spec:
replicas: 3
selector:
matchLabels:
app: user-reg-auth
template:
metadata:
labels:
app: user-reg-auth
spec:
imagePullSecrets:
- name: ofinowregcred # this is a manually applied secret to the cluster using kubectl create secret
containers:
- name: user-reg-auth
image: ofinow/user-reg-auth
ports:
- containerPort: 8080
# resources:
# requests:
# memory: "64Mi"
# cpu: "250m"
# limits:
# memory: "128Mi"
# cpu: "500m"
env:
- name: MONGO_URL
value: mongo-cluster-ip-service
Now the problem is the mongo-cluster-ip-service is not getting resolved, So I am unable to connect. i kindly request for help
I followed the google best practices guide https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-mapping-external-services