4

我想创建一个包含 2 个容器的 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 vm (yungsang/coreos) 上运行 kubernetes。

4

3 回答 3

2

这里有问题的错误是“找不到合适的”。这通常发生在您有端口冲突时(尝试使用相同的hostPort次数太多,或者您可能没有任何工作节点/minions。

我建议您使用 Kubernetes git repo 中的 Vagrant 文件(请参阅http://kubernetes.io),因为我们一直在努力确保在 Kubernetes 处于非常活跃的开发阶段时该文件继续工作。如果你想让它与 CoreOS 单机设置一起工作,我建议你跳上 IRC(freenode 上的#google-containers)并尝试与 Kelsey Hightower 取得联系。

于 2014-09-09T23:44:25.023 回答
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上的最新文档

于 2015-07-29T07:14:34.003 回答
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
于 2019-01-31T09:26:12.080 回答