在一个Single Pod Kubernetes中运行多个容器

时间:2017-09-29 10:11:35

标签: docker kubernetes containers

我是Kubernetes的新手并决定将其用于我目前正在进行的一个小项目的POC。

我有一个容器化的bash脚本,它是用参数执行的。

Kubernetes库存文件如下所示:

---
apiVersion: v1
kind: Pod
metadata:
  name: device-pod
  labels:
    name: device-pod
spec:
  containers:
    - image: azurecr.io/device:1.02
      name: device-0
      args: ["0"]
  containers:
    - image: azurecr.io/device:1.02
      name: device-1
      args: ["1"]
  containers:
    - image: azurecr.io/device:1.02
      name: device-2
      args: ["2"]
  containers:
    - image: azurecr.io/device:1.02
      name: device-3
      args: ["3"]

从上面的清单文件中可以看到,我正在创建一个名为" device-pod"这是假设托管和运行4个容器的名称:device-n(其中n是0..4)

我部署了pod并且它工作正常,但问题是在部署之后我以某种方式只看到容器" device-3"跑步,我似乎无法在吊舱中找到任何其他正在运行的容器。我原以为在Pod中会运行4个容器。

Events:
  FirstSeen LastSeen    Count   From                SubObjectPath               Type        Reason      Message
  --------- --------    -----   ----                -------------               --------    ------      -------
  18m       18m     1   default-scheduler                           Normal      Scheduled   Successfully assigned device-pod to k8s-agent-abe168bc-3
  18m       18m     1   kubelet, k8s-agent-abe168bc-3   spec.containers{device-3}   Normal      Created     Created container with id 770ce7568a7dfe73bacdcd5232e8961fd3098486c82cce56465c04c1c4434659
  18m       18m     1   kubelet, k8s-agent-abe168bc-3   spec.containers{device-3}   Normal      Started     Started container with id 770ce7568a7dfe73bacdcd5232e8961fd3098486c82cce56465c04c1c4434659
  13m       13m     1   kubelet, k8s-agent-abe168bc-3   spec.containers{device-3}   Normal      Started     Started container with id 17c1ae7caa8f017a0ca81925962ecf229ff42a498af7de0dfe93a11fdaa9f43e
  13m       13m     1   kubelet, k8s-agent-abe168bc-3   spec.containers{device-3}   Normal      Created     Created container with id 17c1ae7caa8f017a0ca81925962ecf229ff42a498af7de0dfe93a11fdaa9f43e
  9m        9m      1   kubelet, k8s-agent-abe168bc-3                       Warning     FailedSync  Error syncing pod, skipping: failed to "StartContainer" for "device-3" with CrashLoopBackOff: "Back-off 10s restarting failed container=device-3 pod=device-pod_default(922476fb-a4fb-11e7-8ca8-000d3a25fb55)"

  9m    9m  1   kubelet, k8s-agent-abe168bc-3   spec.containers{device-3}   Normal  Created     Created container with id 5f4db92d4318537eb541dbf11b5b4e4cb7eaa93fcc26061c2e7b970505f27d5e
  9m    9m  1   kubelet, k8s-agent-abe168bc-3   spec.containers{device-3}   Normal  Started     Started container with id 5f4db92d4318537eb541dbf11b5b4e4cb7eaa93fcc26061c2e7b970505f27d5e

我似乎没有看到Container的任何事件:device-0,device-1和device-2

我在这里做错了什么?任何想法都将不胜感激。

1 个答案:

答案 0 :(得分:0)

问题可能源于这样一个事实:在您的规范中,您有"容器"乘法定义,而不是一个"容器"具有多个容器声明的规范。它确实是一个数组/列表,如下所示:

---
apiVersion: v1
kind: Pod
metadata:
  name: device-pod
  labels:
    name: device-pod
spec:
  containers:
    - image: azurecr.io/device:1.02
      name: device-0
      args: ["0"]
    - image: azurecr.io/device:1.02
      name: device-1
      args: ["1"]
    - image: azurecr.io/device:1.02
      name: device-2
      args: ["2"]
    - image: azurecr.io/device:1.02
      name: device-3
      args: ["3"]

您正在经历的行为的一种可能解释可能是所有"容器的顺序解析和执行"当只应该有一个运行时声明。因此,由于序列的原因,您有多个容器启动/运行/终止,但只有最后一个(最后一个声明)继续运行。