简体   繁体   English

在 Kubernetes 容器中 KILL -9 用于构建时反应应用程序

[英]KILL -9 in Kubernetes container for react app while building

I have a react app that I want to deploy to kubernetes using a docker file and host it using nginx.我有一个 React 应用程序,我想使用 docker 文件将其部署到 kubernetes 并使用 nginx 托管它。 My Dockerfile looks like this我的 Dockerfile 看起来像这样

FROM node:14-alpine as build

# Install git
RUN apk update && apk upgrade && \
    apk add --no-cache git

WORKDIR /src
COPY package*.json ./

RUN npm config set unsafe-perm true
RUN npm install
COPY . .
RUN npm run build

My kuberetes configuration after running kustomization looks like this运行 kustomization 后我的 kuberetes 配置如下所示

apiVersion: v1
data:
  settings.ts.ctmpl: |
    export const LIGHTHOUSE_API_HOST = 'stageBackendURL';
kind: ConfigMap
metadata:
  name: lighthouse-web-configmap-6968hk6f5g
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: lighthouse-web
    manifest_type: svc
  name: lighthouse-web
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 3001
  selector:
    app: lighthouse-web
  type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: lighthouse-web
spec:
  minReadySeconds: 10
  progressDeadlineSeconds: 600
  selector:
    matchLabels:
      app: lighthouse-web
  template:
    metadata:
      labels:
        app: lighthouse-web
      name: lighthouse-web
    spec:
      containers:
      - args:
        - npm
        - run
        - serve
        image: <url to image>
        imagePullPolicy: Always
        name: lighthouse-web
        ports:
        - containerPort: 3001
          name: http
        volumeMounts:
        - mountPath: /src/src/settings.ts
          name: lighthouse-web-config
          subPath: settings.ts
        - mountPath: /src/build
          name: lighthouse-web-static
      - image: nginx:1.14
        imagePullPolicy: Always
        name: nginx
        ports:
        - containerPort: 80
          name: nginx
        volumeMounts:
        - mountPath: /usr/share/nginx/html
          name: lighthouse-web-static
      initContainers:
      - args:
        - -template
        - /config-templates/settings.ts.ctmpl:/config/settings.ts
        - -log-level
        - trace
        - -once
        image: <URL TO DOCKER IMAGE>
        imagePullPolicy: Always
        name: consul-template
        resources:
          limits:
            cpu: 500m
            memory: 500Mi
          requests:
            cpu: 500m
            memory: 500Mi
        volumeMounts:
        - mountPath: /config-templates
          name: lighthouse-web-configmap
        - mountPath: /config
          name: lighthouse-web-config
      volumes:
      - configMap:
          name: lighthouse-web-configmap-6968hk6f5g
        name: lighthouse-web-configmap
      - emptyDir: {}
        name: lighthouse-web-config
      - emptyDir: {}
        name: lighthouse-web-static

when i deploy this, the build directory is empty.当我部署它时,构建目录是空的。 I tried to ssh to the container and manually build it but got this error:我尝试通过 ssh 连接到容器并手动构建它,但出现此错误:

export NODE_OPTIONS=--max_old_space_size=4096 && react-scripts build

Creating an optimized production build...
The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lighthouse@0.1.0 build: `export NODE_OPTIONS=--max_old_space_size=4096 && react-scripts build`
npm ERR! Exit status 1
npm ERR!

I had earlier kept the memory and cpu at 1gi and 100m but tried increasing to 16Gi and 8Gi but still didn't work.我早些时候将内存和 cpu 保持在 1gi 和 100m,但尝试增加到 16Gi 和 8Gi 但仍然没有工作。

Few notes on the above :关于上述几点注意事项:

1: I'd use multistage Dockerfile build, where your whole build process happens in the node container but the final, complete, built application is then copied into an nginx based container like 1:我会使用多阶段 Dockerfile 构建,其中您的整个构建过程发生在节点容器中,但最终的、完整的、构建的应用程序然后被复制到基于 nginx 的容器中,例如

FROM node as build
...
FROM nginx
COPY --from=build /path/to/app /usr/share/nginx/html

2: npm builds are expensive processes, doing npm build in your kube env, with reasonable runtime limits set, is very likely to run into issues like the one you mention here. 2:npm 构建是昂贵的过程,在您的 kube 环境中执行 npm 构建,并设置合理的运行时限制,很可能会遇到您在此处提到的问题。

3: make sure that the app artifacts are correctly created on your workstation/build system 3:确保在您的工作站/构建系统上正确创建了应用程序工件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 构建用于在Docker容器中生产的Create React App - Building Create React App for production in Docker Container 在 jenkins 中构建反应应用程序时出错 - Error while building react app in jenkins 在构建 React 应用程序时获取 MaxListenersExceededWarning - Getting MaxListenersExceededWarning while building a React app 传递给 React App 容器但未被使用的 Kubernetes 机密 - Kubernetes secrets passed in to React App container but not being used 使用IntelliJ构建React Kotlin应用程序时出错 - Error getting while building react kotlin app using IntelliJ 使用 docker 构建反应应用程序,同时在运行 npm install 时出错 - Building react app with docker while getting error at run npm install 在构建react应用程序时附加css / js文件的绝对路径 - Attaching absolute path to css/js files while building the react app 使用 Craco 在 Ubuntu 20.04.3 LTS 上构建 React 应用程序时出错 - Error while building React App on Ubuntu 20.04.3 LTS using Craco 使用 docker-compose 构建应用程序时,如何在 React 应用程序中为 URL 端点使用 Docker 容器名称? - How to use Docker container name for URL endpoint in React app when building app with docker-compose? JavaScript 堆出 memory 同时在 docker 容器中构建反应应用程序 - JavaScript heap out of memory while build react app in docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM