簡體   English   中英

使用 docker 容器化的應用程序將不會在單個 Kube.netes pod 中進行通信

[英]Applications containerized with docker will not communicate in a single Kubernetes pod

我的應用程序包含一個內置於 React 中的 UI、一個 API、MQTT 代理和一個 Webhook,用於監視所有使用節點構建的數據庫中的更改。

數據庫還沒有做成卷,而是運行在我的本地電腦上。

這是我的 deployment.yml 文件

`

# 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

`

...以及四個服務的 dockerbuild 文件

界面

`

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" ]

`

數據庫監控器

`

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" ]

` 將不勝感激任何幫助。 謝謝!

我想說的是,在標准的 Kube.netes 工作負載中,您應該啟動具有四種不同部署的四個不同 Pod。 然后創建四個不同的服務,您會看到它們可以相互通信。

這樣,您的 pod 將更易於檢查,並且您已准備好單獨擴展 pod。

也許我錯過了什么?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM