【问题标题】:Kubernetes deploying angular frontend crashKubernetes 部署 Angular 前端崩溃
【发布时间】:2022-01-20 09:35:24
【问题描述】:

我正在尝试在 kubernetes 上部署 Angular 前端应用程序,但我总是收到此错误:

NAME                              READY   STATUS             RESTARTS   AGE
common-frontend-f74c899cc-p6tdn   0/1     CrashLoopBackOff   7          15m

当我尝试查看 pod 的日志时,它只打印空行,所以我怎样才能找出问题所在

这是 dockerfile,总是通过这个 dockerfile 构建管道:

### STAGE 1: Build ###

# We label our stage as 'builder'
FROM node:10.11 as builder

COPY package.json ./
COPY package-lock.json ./

RUN npm set progress=false && npm config set depth 0 && npm cache clean --force
ARG NODE_OPTIONS="--max_old_space_size=4096"
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app

WORKDIR /ng-app

COPY . .

## Build the angular app in production mode and store the artifacts in dist folder
RUN $(npm bin)/ng build --prod --output-hashing=all

### STAGE 2: Setup ###

FROM nginx:1.13.3-alpine

## Copy our default nginx config
COPY nginx/default.conf /etc/nginx/conf.d/

## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*

## From 'builder' stage copy the artifacts in dist folder to default nginx public folder
COPY --from=builder /ng-app/dist /usr/share/nginx/html

CMD ["nginx", "-g", "daemon off;"]

和deployment.yaml

---
apiVersion: v1
kind: Service
metadata:
  name: common-frontend
  labels:
    app: common-frontend
spec:
  type: ClusterIP
  selector:
    app: common-frontend
  ports:
  - port: 80
    targetPort: 8080

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: common-frontend
  labels:
    app: common-frontend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: common-frontend
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 33%
  template:
    metadata:
      labels:
        app: common-frontend
    spec:
      containers:
      - name: common-frontend
        image: skunkstechnologies/common-frontend:<VERSION>
        ports:
        - containerPort: 8080
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 30
          timeoutSeconds: 1

我真的不知道可能是什么问题,有人可以帮忙吗?谢谢!

【问题讨论】:

    标签: angular docker kubernetes dockerfile


    【解决方案1】:

    看起来 Kubernetes 未能通过 liveness 探测并将重新启动 pod。尝试评论“liveness probe”部分并重新开始。如果有帮助,请更正探测参数——超时、延迟等。

    【讨论】:

      【解决方案2】:

      嗯。 您的容器死亡并尝试重新启动。首先,尝试查看他的日志和状态:

      kubectl logs <container_name>
      kubectl describe pod <container_name>
      

      【讨论】:

      • 请与其他不同阶段的答案合并,而不是两个单独的答案
      猜你喜欢
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      • 2015-07-10
      • 2021-02-10
      • 1970-01-01
      • 2020-05-20
      • 2020-08-17
      • 1970-01-01
      相关资源
      最近更新 更多