首页 > 解决方案 > Next Js 部署水平扩展使用 docker 在启用多个 Pod 时失败

问题描述

我们在 Next JS 中有我们的应用程序,它使用 Docker 和 Kubernetes Google Cloud Platform 部署。我们面临的问题是——

  1. 当 dockerized 并部署在 1 个 pod 中时,应用程序可以完美运行。
  2. 当 pod 数量增加到更大的数量时,JS 和 CSS 无法加载。
  3. 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: {}

标签: dockerkubernetesgoogle-cloud-platformnext.jshorizontal-scrolling

解决方案


推荐阅读