Earlier I used earlier kubeadm to create an endpoint from my local MongoDB which is running in a Docker container, now we have switched from kubeadm to k3s because it is a lot of easier to use. Now we are not able to use the MongoDB endpoints, it is reachable inside the Kubernetes cluster. I will share the necessary information for you. Would be glad if anybody can help me.
This is the Mongo DB container which is running inside usual Docker:
Now I would like use it in my Kubernetes cluster, before I did a check if I am able to access inside the port 27019 and it seems to be fine.
user@shell:~$ curl {address-of-the-VM}:27019 It looks like you are trying to access MongoDB over HTTP on the native driver port.
- Add next I created the Endpoint and service file
apiVersion: v1 kind: Service metadata: name: mongo namespace: dev spec: clusterIP: None ports: - port: 27019 targetPort: 27019
apiVersion: v1 kind: Endpoints metadata: name: mongo namespace: dev subsets: - addresses: - ip: {address-of-the-VM} ports: - port: 27019 name: mongo
And as next I used them for my environment variable as ConfigMap:
kind: ConfigMap apiVersion: v1 metadata: name: spring-profile namespace: dev data: MONGODB_HOSTS: mongo.dev MONGODB_PORTS: "27019" spring.profiles.active: dev stage: dev
And bind it to my pod in deployment:
containers: - name: dev-server image: localhost:5000/dev_dev-server imagePullPolicy: IfNotPresent ports: - containerPort: 8080 envFrom: - configMapRef: name: spring-profile
Now I am getting this issue, so the database can not find.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'maintenanceFeature': Unsatisfied dependency expressed through field 'systemSrvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'systemDAO': Unsatisfied dependency
As I mentioned earlier in our kubeadm architecture it worked very fine now it is not working. And I checked as well if the MongoDB is in the node of K3s and yes, it is.
Advertisement
Answer
I found the solution, you can use directly the IP Address {address-of-the-VM}:27019
.