<p><strong>Context:</strong></p>
<p>I am building an application and now I am on the infrastructure step.</p>
<p>The application is built with Java and persistence layer is MongoDB.</p>
<p><strong>Problem:</strong></p>
<p>If the application is running in same Node as persistence Layer are, everything goes ok, but on different nodes the application cannot communicate with MongoDB.</p>
<p>There is a print of Kubernetes Dashboard:</p>
<p><a href="https://i.stack.imgur.com/Nziyf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nziyf.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/fKQg1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fKQg1.png" alt="enter image description here" /></a></p>
<p>As you can see, two pods of application (gateway) are running in same node as Mongo, but other two don't. These two are not finding MongoDb.</p>
<p>Here is the mongo-db.yaml:</p>
<pre class="lang-yaml prettyprint-override"><code>
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongo-data
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 1Gi
  hostPath:
    path: /home/vitor/seguranca/mongo

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc
spec:
  storageClassName: &quot;&quot;
  accessModes:
    - ReadWriteOnce 
  volumeName: mongo-data
  resources:
    requests:
      storage: 1Gi

---

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: mongo
  name: mongo

spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: mongo
      name: mongo-service

    spec:
      volumes:
      - name: &quot;deployment-storage&quot;
        persistentVolumeClaim:
          claimName: &quot;pvc&quot;

      containers:
      - image: mongo
        name: mongo
        ports:
          - containerPort: 27017
        volumeMounts:
          - name: &quot;deployment-storage&quot;
            mountPath: &quot;/data/db&quot;
        
status: {}
---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: mongo
  name: mongo-service
spec:
  ports:
  - port: 27017
    targetPort: 27017
  selector:
    app: mongo
  clusterIP: None
</code></pre>
<p>and here the application.yaml:</p>
<pre class="lang-yaml prettyprint-override"><code>
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: gateway
  name: gateway
spec:
  replicas: 4
  selector:
    matchLabels:
      app: gateway
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: gateway
    spec:
      containers:

      - image: vitornilson1998/native-micro
        name: native-micro
        env:
        - name: MONGO_CONNECTION_STRING
          value: mongodb://mongo-service:27017 #HERE IS THE POINT THAT THE APPLICATION USES TO ACCESS MONGODB
        - name: MONGO_DB
          value: gateway
        resources: {}
        ports:
          - containerPort: 8080
        
status: {}

---

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: gateway-service
  name: gateway-service
spec:
  ports:
  - name: 8080-8080
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: gateway
  type: NodePort
status:
  loadBalancer: {}


</code></pre>
<p>I can't see what is stopping application to reach MongoDB.</p>
<p>Should I do what?</p>

Vitor Nilson
<p>I was using calico as CNI.</p>
<p>I removed calico and let kube-proxy take care of everything.</p>
<p>Now everything is working fine.</p>
