<p>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.</p>
<ol>
<li><p>This is the Mongo DB container which is running inside usual Docker:
<a href="https://i.stack.imgur.com/cPI2b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cPI2b.png" alt="enter image description here" /></a></p>
</li>
<li><p>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.</p>
</li>
</ol>
<pre><code>user@shell:~$ curl {address-of-the-VM}:27019
It looks like you are trying to access MongoDB over HTTP on the native driver port.
</code></pre>
<ol start="3">
<li>Add next I created the Endpoint and service file</li>
</ol>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mongo
  namespace: dev
spec:
  clusterIP: None
  ports:
  - port: 27019
    targetPort: 27019

</code></pre>
<pre><code>apiVersion: v1
kind: Endpoints
metadata:
  name: mongo
  namespace: dev
subsets:
  - addresses:
      - ip: {address-of-the-VM}
    ports:
      - port: 27019
        name: mongo
        
</code></pre>
<p>And as next I used them for my environment variable as ConfigMap:</p>
<pre><code>kind: ConfigMap
apiVersion: v1
metadata:
  name: spring-profile
  namespace: dev
data:
  MONGODB_HOSTS: mongo.dev
  MONGODB_PORTS: &quot;27019&quot;
  spring.profiles.active: dev
  stage: dev
</code></pre>
<p>And bind it to my pod in deployment:</p>
<pre><code>    containers:
      - name: dev-server
        image: localhost:5000/dev_dev-server 
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
        envFrom:
        - configMapRef:
            name: spring-profile    
</code></pre>
<p>Now I am getting this issue, so the database can not find.</p>
<pre><code>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
</code></pre>
<p>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.</p>

Cosss
<p>I found the solution, you can use directly the IP Address <code>{address-of-the-VM}:27019</code>.</p>
