如何编写一个Kubernetes Pod配置以启动两个容器

4
我想创建一个包含两个不同镜像的 Kubernetes Pod,以便可以同时启动这两个容器。

目前,我已尝试了以下配置:

{
  "id": "podId",
  "desiredState": {
    "manifest": {
      "version": "v1beta1",
      "id": "podId",
      "containers": [{
        "name": "type1",
        "image": "local/image"
        },
        {
        "name": "type2",
        "image": "local/secondary"
        }]
    }
  },
  "labels": {
    "name": "imageTest"
  }
}

然而当我执行kubecfg -c app.json create /pods时,我收到以下错误:

F0909 08:40:13.028433 01141 kubecfg.go:283] Got request error: request [&http.Request{Method:"POST", URL:(*url.URL)(0xc20800ee00), Proto:"HTTP/1.1", ProtoMajor:1, ProtoMinor:1, Header:http.Header{}, B
ody:ioutil.nopCloser{Reader:(*bytes.Buffer)(0xc20800ed20)}, ContentLength:396, TransferEncoding:[]string(nil), Close:false, Host:"127.0.0.1:8080", Form:url.Values(nil), PostForm:url.Values(nil), Multi
partForm:(*multipart.Form)(nil), Trailer:http.Header(nil), RemoteAddr:"", RequestURI:"", TLS:(*tls.ConnectionState)(nil)}] failed (500) 500 Internal Server Error: {"kind":"Status","creationTimestamp":
null,"apiVersion":"v1beta1","status":"failure","message":"failed to find fit for api.Pod{JSONBase:api.JSONBase{Kind:\"\", ID:\"SSH podId\", CreationTimestamp:util.Time{Time:time.Time{sec:63545848813, nsec
:0x14114e1, loc:(*time.Location)(0xb9a720)}}, SelfLink:\"\", ResourceVersion:0x0, APIVersion:\"\"}, Labels:map[string]string{\"name\":\"imageTest\"}, DesiredState:api.PodState{Manifest:api.ContainerMa
nifest{Version:\"v1beta1\", ID:\"podId\", Volumes:[]api.Volume(nil), Containers:[]api.Container{api.Container{Name:\"type1\", Image:\"local/image\", Command:[]string(nil), WorkingDir:\"\", Ports:[]ap
i.Port(nil), Env:[]api.EnvVar(nil), Memory:0, CPU:0, VolumeMounts:[]api.VolumeMount(nil), LivenessProbe:(*api.LivenessProbe)(nil)}, api.Container{Name:\"type2\", Image:\"local/secondary\", Command:[]string(n
il), WorkingDir:\"\", Ports:[]api.Port(nil), Env:[]api.EnvVar(nil), Memory:0, CPU:0, VolumeMounts:[]api.VolumeMount(nil), LivenessProbe:(*api.LivenessProbe)(nil)}}}, Status:\"\", Host:\"\", HostIP:\"\
", PodIP:\"\", Info:api.PodInfo(nil), RestartPolicy:api.RestartPolicy{Type:\"RestartAlways\"}}, CurrentState:api.PodState{Manifest:api.ContainerManifest{Version:\"\", ID:\"\", Volumes:[]api.Volume(nil
), Containers:[]api.Container(nil)}, Status:\"\", Host:\"\", HostIP:\"\", PodIP:\"\", Info:api.PodInfo(nil), RestartPolicy:api.RestartPolicy{Type:\"\"}}}","code":500}

我该如何相应地修改配置?
在vagrant虚拟机(yungsang/coreos)上运行kubernetes。

你能解决这个问题吗?现在它有点过时了 - v1版本可能会解决你的问题。 - aronchick
我不再使用它,所以我不知道。是的,它现在非常旧了,所以可能已经修复了。 - mangusbrother
3个回答

2
这里的错误是“未能找到适合的匹配”。通常情况下,这是由于端口冲突引起的(尝试使用相同的hostPort太多次或者可能没有任何工作节点/从节点)。
我建议您要么使用 Kubernetes git 存储库中的 Vagrant 文件(请参见 http://kubernetes.io),因为我们一直在努力确保它在 Kubernetes 处于非常活跃的开发状态时仍然可用。如果您想让它与 CoreOS 单机设置配合使用,请加入 IRC(freenode 上的 #google-containers)并尝试联系 Kelsey Hightower。

Vagrantfile没有起作用,因为它在寻找Linux发行版下的文件,而我使用的是Windows。 - mangusbrother

2
您的Pod规范文件似乎是无效的。 根据http://kubernetes.io/v1.0/docs/user-guide/walkthrough/README.html#multiple-containers,一个有效的多容器Pod规范应该像这样。
apiVersion: v1
kind: Pod
metadata:
  name: www
spec:
  containers:
  - name: nginx
    image: nginx
    volumeMounts:
    - mountPath: /srv/www
      name: www-data
      readOnly: true
  - name: git-monitor
    image: kubernetes/git-monitor
    env:
    - name: GIT_REPO
      value: http://github.com/some/repo.git
    volumeMounts:
    - mountPath: /data
      name: www-data
  volumes:
  - name: www-data
    emptyDir: {}

最新文档请参见http://kubernetes.io/docs/user-guide/walkthrough/#multiple-containers


1
apiVersion: v1
kind: Pod
metadata:
 name: test
spec:
 containers:
 - name: wp
   image: wordpress
   resources: 
    requests:
     memory: "64Mi"
     cpu: "250m" 
    limits:
     memory: "128Mi"
     cpu: "500m"
 - name: ng
   image: nginx
   imagePullPolicy: IfNotPresent

放在哪里?这只是一个代码回答,所以任何解释都可以。 - Stephan Vierkant
创建一个名为first.yaml的yaml文件,将以下代码放入其中,然后运行命令kubectl create -f first.yaml。 - Vageesha

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接