1

各位,我正在尝试使用 initContainers 创建一个简单的文件/tmp/tarte.test。我有一个约束,对容器使用高山图像。请让我知道这个简单的 yaml 文件中没有什么。

apiVersion: v1
kind: Pod
metadata:
  name: initonpod
  namespace: prod
  labels:
    app: myapp
spec:
  containers:
  - name: mycont-nginx
    image: alpine
  initContainers:
    - name: myinit-cont
      image: alpine
      imagePullPolicy: IfNotPresent
      command: 
      - touch
      - "/tmp/tarte.test"
      - sleep 200

豆荚的描述

Events:
  Type     Reason     Age              From                 Message
  ----     ------     ----             ----                 -------
  Normal   Scheduled  9s               default-scheduler    Successfully assigned prod/initonpod to k8s-node-1
  Normal   Pulled     8s               kubelet, k8s-node-1  Container image "alpine" already present on machine
  Normal   Created    8s               kubelet, k8s-node-1  Created container
  Normal   Started    7s               kubelet, k8s-node-1  Started container
  Normal   Pulling    4s (x2 over 7s)  kubelet, k8s-node-1  pulling image "alpine"
  Normal   Pulled     1s (x2 over 6s)  kubelet, k8s-node-1  Successfully pulled image "alpine"
  Normal   Created    1s (x2 over 5s)  kubelet, k8s-node-1  Created container
  Normal   Started    1s (x2 over 5s)  kubelet, k8s-node-1  Started container
  Warning  BackOff    0s               kubelet, k8s-node-1  Back-off restarting failed container

如果我为 nginx 图像容器更改 alpine 图像......它工作得很好。

4

1 回答 1

5

Back-off restarting failed container因为你的容器规格。

spec:
  containers:
  - name: mycont-nginx
    image: alpine

这个alpine容器不会永远运行。在 kubernetes 中,容器必须永远运行。这就是你得到错误的原因。当您使用nginx图像时,它会永远运行。因此,要使用alpine图像更改规格如下:

apiVersion: v1
kind: Pod
metadata:
  name: busypod
  labels:
    app: busypod
spec:
  containers:
  - name: busybox
    image: alpine
    command:
    - "sh"
    - "-c"
    - >
      while true; do
        sleep 3600;
      done
  initContainers:
  - name: myinit-cont
    image: alpine
    imagePullPolicy: IfNotPresent
    command:
    - touch
    - "/tmp/tarte.test"
    - sleep 200
于 2018-11-20T04:44:23.700 回答