【问题标题】:Kubernetes pod wont start and get CrashLoopBackOffKubernetes pod 无法启动并获得 CrashLoopBackOff
【发布时间】:2022-07-11 23:02:34
【问题描述】:

当我尝试运行 kubectl apply -f frontend.yaml 时,我收到来自 kubectl get podskubectl describe pods 的以下响应

// frontend.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: malvacom-frontend
  labels:
    app: malvacom-frontend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: malvacom-frontend
  template:
    metadata:
      labels:
        app: malvacom-frontend
    spec:
      containers:
        - name: malvacom-frontend
          image: docker.io/forsrobin/malvacom_frontend
          imagePullPolicy: IfNotPresent

          ports:
            - containerPort: 80
          resources:
            limits:
              memory: "128Mi"
              cpu: "200m"
          livenessProbe:
            httpGet:
              path: /index.html
              port: 80
            initialDelaySeconds: 15
            timeoutSeconds: 2
            periodSeconds: 5
            failureThreshold: 1
          readinessProbe:
            httpGet:
              path: /index.html
              port: 80
            initialDelaySeconds: 15
            periodSeconds: 5
            failureThreshold: 1
          command: [ "sleep" ]
          args: [ "infinity" ]

然后响应是

kubectl get pods
malvacom-frontend-8575c8548b-n959r   0/1     CrashLoopBackOff   5 (95s ago)   4m38s
kubectl describe pods
QoS Class:                   Guaranteed
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  17s                default-scheduler  Successfully assigned default/malvacom-frontend-8575c8548b-n959r to shoot--p1622--malvacom-web-xdmoi2-z1-54776-bpjpw
  Normal   Pulled     15s (x2 over 16s)  kubelet            Container image "docker.io/forsrobin/malvacom_frontend" already present on machine
  Normal   Created    15s (x2 over 16s)  kubelet            Created container malvacom-frontend
  Normal   Started    15s (x2 over 16s)  kubelet            Started container malvacom-frontend
  Warning  BackOff    11s (x4 over 14s)  kubelet            Back-off restarting failed container

正如我所理解的,pod 启动了,但是因为它没有继续执行的任务,kubernetes 删除/停止了 pod。我可以毫无问题地在本地运行图像,例如,如果我使用另一个图像thenetworkchuck/nccoffee:pourover ,它可以毫无问题地工作。这是我的 Dockerfile

FROM node:alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY ./package.json /app/
RUN yarn --silent
COPY . /app
RUN yarn build
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

【问题讨论】:

    标签: reactjs docker nginx kubernetes networking


    【解决方案1】:

    你明确告诉 Kubernetes 不要运行它的普通服务器

    command: [ "sleep" ]
    args: [ "infinity" ]
    

    但它应该通过 HTTP 健康检查

    livenessProbe:
      httpGet:
        path: /index.html
        port: 80
    

    由于sleep infinity 没有运行 HTTP 服务器,因此此探测将永远不会通过,这会导致您的容器被杀死并重新启动。

    你不应该做人为的事情来“让容器保持活力”;删除 command:args: 覆盖。 (Dockerfile CMD 是正确的,但是您会从基础 nginx 映像中获得相同的 CMD,并且您不需要重复它。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      • 2019-10-24
      • 2019-10-10
      • 2021-01-26
      • 2017-12-09
      • 2021-05-05
      相关资源
      最近更新 更多