我的initContainers的“高山”图像出现问题

时间:2018-11-20 04:00:52

标签: kubernetes yaml containers microk8s

人们, 我正在尝试使用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图像容器更改了高山图像,那就很好了。

1 个答案:

答案 0 :(得分:4)

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