Home > OS >  Applications containerized with docker will not communicate in a single Kubernetes pod
Applications containerized with docker will not communicate in a single Kubernetes pod

Time:12-01

My application consists of a UI built in react, an API, MQTT broker, and a webhook to monitor changes in a database all built with node.

The database has not yet been made into a volume, but is running on my local computer.

Here is my deployment.yml file

`

# defining Service
apiVersion: v1
kind: Service
metadata:
  name: factoryforge
spec:
  selector:
    app: factoryforge
  ports:
    - port: 80
      name: api
      targetPort: 3000
    - port: 81
      name: mqtt
      targetPort: 3001
    - port: 82
      name: dbmonitor
      targetPort: 3002
    - port: 83
      name: ui
      targetPort: 3003
  type: LoadBalancer
---
#Defining multi container pod
apiVersion: apps/v1
kind: Deployment
metadata:
  name: factoryforge
spec:
  replicas: 1
  selector:
    matchLabels:
      app: factoryforge
  template:
    metadata:
      labels:
        app: factoryforge
    spec:
      containers:
        - name: api
          image: blueridgetest/api
          ports:
            - containerPort: 3000
        - name: mqtt
          image: blueridgetest/mqtt
          ports:
            - containerPort: 3001
        - name: dbmonitor
          image: blueridgetest/dbmonitor
          ports:
            - containerPort: 3002
        - name: ui
          image: blueridgetest/ui
          ports:
            - containerPort: 3003

`

...and the dockerbuild files for the four services

UI

`

FROM node:16

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5 )
COPY package*.json ./

RUN npm i --f
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

# Ports will have to be mapped to local ports when deployed with kubernetes
EXPOSE 3000
CMD [ "npm", "start" ]

`

API

`

FROM node:16

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5 )
COPY package*.json ./

RUN npm i
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

# Ports will have to be mapped to local ports when deployed with kubernetes
EXPOSE 3002
EXPOSE 8000
CMD [ "node", "API.js" ]

`

MQTT

`

FROM node:16

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5 )
COPY package*.json ./

RUN npm i
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

# Ports will have to be mapped to local ports when deployed with kubernetes
EXPOSE 8884
CMD [ "node", "MQTTBroker.js" ]

`

DBMonitor

`

FROM node:16

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5 )
COPY package*.json ./

RUN npm i
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

# Ports will have to be mapped to local ports when deployed with kubernetes
EXPOSE 3001
CMD [ "node", "index.js" ]

` Any help would be greatly appreciated. Thanks!

CodePudding user response:

i would say that in a standard Kubernetes workload you should start four different Pods with four different deployments. Then create four different services and you will see that they can communicate with one another.

With this, your pods will be simpler to check, and you are ready to scale the pods singularly.

Maybe I missed something?

  • Related