How to write a kubernetes pod configuration to start two containers

kubernetes pod to pod communication example
kubernetes shared persistent volume between pods
kubernetes multi container pod example
kubernetes deployment
kubernetes init container environment variables
kubernetes deployment multiple pods
kubernetes pod yaml reference
kubectl create pod

I would like to create a kubernetes pod that contains 2 containers, both with different images, so I can start both containers together.

Currently I have tried the following configuration:

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

However when I execute kubecfg -c app.json create /pods I get the following error:

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}

How can I modify the configuration accordingly?

Running kubernetes on a vagrant vm (yungsang/coreos).

The error in question here is "failed to find fit". This generally happens when you have a port conflict (try and use the same hostPort too many times or perhaps you don't have any worker nodes/minions.

I'd suggest you either use the Vagrant file that is in the Kubernetes git repo (see http://kubernetes.io) as we have been trying to make sure that stays working as Kubernetes is under very active development. If you want to make it work with the CoreOS single machine set up, I suggest you hop on IRC (#google-containers on freenode) and try and get in touch with Kelsey Hightower.

Communicate Between Containers in the Same Pod , The two containers share a Volume that they Here is the configuration file for the Pod: .io/examples/pods/two-container-pod.yaml STAT START TIME COMMAND root 1 . Find what is kubernetes on TheAnswerHub.com. TheAnswerHub is a top destination for finding answers online. Browse our content today!

Your pod spec file looks like invalid. According to http://kubernetes.io/v1.0/docs/user-guide/walkthrough/README.html#multiple-containers, a valid multiple containers pod spec should like this

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: {}

Latest doc at http://kubernetes.io/docs/user-guide/walkthrough/#multiple-containers

Configure Pods and Containers, Perform common configuration tasks for Pods and containers. Configure Liveness, Readiness and Startup Probes  Searching for Kubernetes Consulting? Check out Visymo. 1000+ Results From Across the Web. Start searching Kubernetes Consulting. All Web Results, One Search Engine.

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

Configure Pod Initialization, Before you begin You need to have a Kubernetes cluster, and the kubectl kubectl apply -f https://k8s.io/examples/pods/init-containers.yaml. I would like to create a kubernetes pod that contains 2 containers, both with different images, so I can start both containers together. Currently I have tried the following configuration: { "i

Pod Overview, Using create; Pod configuration file; The spec schema your pod (e.g. your pod is writing non-persistent data which won't survive a restart, or your pod is For example, the following configuration file creates two containers: a redis key-value   Assign Memory Resources to Containers and Pods Assign CPU Resources to Containers and Pods Configure GMSA for Windows Pods and containers Configure RunAsUserName for Windows pods and containers Configure Quality of Service for Pods Assign Extended Resources to a Container Configure a Pod to Use a Volume for Storage Configure a Pod to Use a

Creating Multi-Container Pods, In other words, if you need to run a single container in Kubernetes, then you need to create a Pod for that In the following example, we define a Pod with two containers. Create a ConfigMap with the nginx configuration file. Shared volumes in a Kubernetes Pod. In Kubernetes, you can use a shared Kubernetes Volume as a simple and efficient way to share data between containers in a Pod. For most cases, it is sufficient to use a directory on the host that is shared with all containers within a Pod. Kubernetes Volumes enables data to survive container restarts, but

Multi-container pods and container communication in Kubernetes, The error in question here is "failed to find fit". This generally happens when you have a port conflict (try and use the same hostPort too many  Windows applications constitute a large portion of the services and applications that run in many organizations. This guide walks you through the steps to configure and deploy a Windows container in Kubernetes. Objectives Configure an example deployment to run Windows containers on the Windows node (Optional) Configure an Active Directory Identity for your Pod using Group Managed Service

Comments
  • Were you able to solve this? It's now a bit out of date - v1 may address your issue.
  • I no longer use this so i do not know. Yes its quite old now so it may be fixed
  • the Vagrantfile didn't work as it was searching for files under a linux distribution and I am on windows
  • Where to put this? This is a code only answer, so any explanation would be fine.
  • create a yaml file say first.yaml and put this code in it and then run the command kubectl create -f first.yaml