docker - Next Js 部署水平扩展使用 docker 在启用多个 Pod 时失败
问题描述
我们在 Next JS 中有我们的应用程序,它使用 Docker 和 Kubernetes Google Cloud Platform 部署。我们面临的问题是——
- 当 dockerized 并部署在 1 个 pod 中时,应用程序可以完美运行。
- 当 pod 数量增加到更大的数量时,JS 和 CSS 无法加载。
- JS 和 CSS 文件的路径在 URL 处附加了一个垃圾值。
请分别找到我的 docker 文件和 yaml 文件的代码。
FROM node:10
# Setting working directory. All the path will be relative to WORKDIR
WORKDIR /app
ENV NODE_ENV=prod
ENV NODE_OPTIONS=--max_old_space_size=4096
# Installing dependencies
COPY ./.npmrc ./
COPY ./package*.json ./
# Copying source files
RUN npm install
COPY ./ ./
RUN echo $pdp_search_key
RUN NODE_ENV=production npm run build
ENTRYPOINT [ "npm" ]
# Running the app
CMD [ "run", "prod-start" ]
而 deployment.yaml 文件如下 -
# Default values for helm.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: gcr.io/loblaw-gcr/pc-development
pullPolicy: Always
nameOverride: ""
fullnameOverride: "pcca-staging"
environment: "staging"
service:
type: ClusterIP
port: 80
container:
port: 80
healthcheckport: 80
readinesspath: /ready
livenesspath: /live
gateway:
host: pcca-staging.loblaw.digital
name: pcca-staging
sso: false
virtualService:
name: pcca-staging
vault:
enabled: true
vaultAddress: https://vault.prod.lblw.cloud:8200
vaultAuthPath: auth/bluenose/login
vaultRole: pc_ca-reader-bluenose
vaultSecretsPath: pc_ca/data/application
resources:
# The following values were ripped from the OMS project and do not reflect any informed decisions
# about what resources our app actually needs - I just had to use something as an example. We need
# to do further testing to make this more meaninful and accurate...
# https://gitlab.lblw.ca/grocery/fulfilment/oms/order/blob/master/helm/oms/values.yaml#L119
limits:
cpu: "3"
memory: "8Gi"
requests:
cpu: "1"
memory: "2512Mi"
autoscaling:
enabled: true
minReplicas: 2
maxReplicas: 2
averageCPUUtilization: 50
averageMemoryUtilization: 50
nodeSelector: {}
tolerations: []
affinity: {}
解决方案
推荐阅读
- c++ - 冲突声明/重新定义:不同的基本类型
- kubernetes - Kubectl 运行设置节点选择器
- c# - HttpContext.Response.Body.Position = 0 - “不支持指定的方法”错误
- angular - 如何映射数组并使用 tslint 返回一个对象。(语法糖)
- pdf - PDFBox - 用自动换行填充 PDF 中的 PDTextbox
- android - setLabelCount(),导致标签混乱。MPandroid 图表库
- php - 如何省略 XML 命名空间声明?
- python - 从文本文件中读取矩阵并将其存储在数组中
- css - Bootstrap 在视频上放置响应式文本和按钮
- ios - 界面生成器说 UITableView 单元格需要约束,但它们不需要