Home > Net >  Pods in differents Nodes can't talk each other - Kubernetes
Pods in differents Nodes can't talk each other - Kubernetes

Time:07-20

Context:

I am building an application and now I am on the infrastructure step.

The application is built with Java and persistence layer is MongoDB.

Problem:

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.

There is a print of Kubernetes Dashboard:

enter image description here enter image description here

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.

Here is the mongo-db.yaml:


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: ""
  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: "deployment-storage"
        persistentVolumeClaim:
          claimName: "pvc"

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

apiVersion: v1
kind: Service
metadata:
  labels:
    app: mongo
  name: mongo-service
spec:
  ports:
  - port: 27017
    targetPort: 27017
  selector:
    app: mongo
  clusterIP: None

and here the application.yaml:


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: {}


I can't see what is stopping application to reach MongoDB.

Should I do what?

CodePudding user response:

I was using calico as CNI.

I removed calico and let kube-proxy take care of everything.

Now everything is working fine.

  • Related