开班 Init:CrashLoopBackOff

Openshift Init:CrashLoopBackOff

当尝试使用下面的 yml 文件将我的项目部署到 openshift 时,出现 Init:CrashLoopBackOff 错误。除了查看 pod 的事件之外,是否有人看到出了什么问题或有任何关于如何进一步调查此问题的提示。事件说“容器图像“url/the-app:快照”已经存在于机器上”

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: the-app
  name: the-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: the-app
  strategy:
    type: Recreate
    redeployOnConfigChange: true
  template:
    metadata:
      labels:
        app: the-app
    spec:
      containers:
        - image: {{ image_registry }}/the-app:{{ the-app-version }}
          imagePullPolicy: Always
          name: the-app
          ports:
            - containerPort: 10202
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /actuator/health
              port: 10202
              scheme: HTTP
            initialDelaySeconds: 20
            timeoutSeconds: 10
          readinessProbe:
            httpGet:
              path: /actuator/health
              port: 10202
              scheme: HTTP
            initialDelaySeconds: 20
            timeoutSeconds: 10
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: "prod"
            - name: ENVIRONMENT_SERVER_PORT
              value: "10202"
          volumeMounts:
            - name: my-config
              mountPath: /my-config
            - name: input-data
              mountPath: /input-data
      initContainers:
        - name: init-test-data
          image: {{ image_registry }}/the-app:{{ the-app-version }}
          command: ["/bin/sh","-c"]
          args: ['apt-get install --yes git clone https://MYGITREPO.git']
          volumeMounts:
            - mountPath: /tmp
              name: input-data
      volumes:
        - name: my-config
          configMap:
            name: my-configmap
        - name: input-data
          emptyDir: {}
  identity:
    enabled: true
  logging:
    index: "{{ splunk_index }}"

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: the-app
  name: the-app
spec:
  ports:
    - name: 10202-tcp
      port: 10202
      protocol: TCP
      targetPort: 10202
  selector:
    app: the-app
status:
  loadBalancer: {}

状态 Init:CrashLoopBackOff 表示您的 initContainers 之一正在崩溃。您通常会通过查看容器 (kubectl logs the-app -c init-test-data) 的日志来诊断此问题,但在这种情况下存在一个明显的问题。

您已将 init-test-data 容器中的 args 设置为...

apt-get install --yes git clone https://MYGITREPO.git

...但这不是有效的命令。看起来您不小心将两个命令混在一起了。这样的事情可能会奏效:

command:
  - /bin/sh
  - -c
args:
  - |
    apt-get install --yes git
    git clone https://MYGITREPO.git

尽管确实没有特别的理由同时使用 commandargs;这也可以正常工作:

command:
  - /bin/sh
  - -c
  - |
    apt-get install --yes git
    git clone https://MYGITREPO.git

(但您可能希望先明确 cd 到适当的目录)。


注意:在 YAML 中,这个:

command:
  - /bin/sh
  - -c

完全相同于:

command: ["/bin/sh", "-c"]

不过我更喜欢以前的形式