6

For instance can I have following yaml to produce a pod with multiple containers:

apiVersion: v1
kind: Pod
metadata:
name: lampapp
labels:
    app: app
spec:
  containers:
  - name: lampdb
    image: mysql_test
  - name: app
    image: php-app-db-url-env
    env:
     - name: DB_URL
      value: 127.0.0.1:3306
  - name: app2
    image: php-app-db-url-env
    env:
    - name: DB_URL
      value: 127.0.0.1:3306
Shahriar
  • 13,460
  • 8
  • 78
  • 95
Madhurima Mishra
  • 1,063
  • 3
  • 14
  • 27
  • 1
    Check this to better understand how to write a spec file: https://cloud.google.com/container-engine/docs/spec-schema – cristi Oct 23 '15 at 14:28
  • 1
    @cristi Link is now broken. Gotta love chasing Google and their ever-out-of-date docs! – Ogre Psalm33 Mar 28 '17 at 18:51
  • 1
    The latest docs are here now: https://kubernetes.io/docs/api-reference/v1.5 . Change the "1.5" with the desired version of your kube cluster. – cristi Mar 31 '17 at 07:16

3 Answers3

3

Yes, you can add multiple container with same image.

The containers object must contain:

  1. name: Name of the container. It must be a DNS_LABEL and be unique within the pod. Cannot be updated.
  2. image: Docker image name.

You have to make container name unique

You can do following:

- name: app
  image: php-app-db-url-env   ---
- name: app2                    |> same image
  image: php-app-db-url-env   ---

But not this one:

- name: app
  image: php-app-db-url-env
- name: app
  image: <any image>

Also the containers spec should include a unique port number within the Pod

Jack B
  • 13
  • 5
Shahriar
  • 13,460
  • 8
  • 78
  • 95
1

Same of kind of containers can be there but then their port would be different.

Madhurima Mishra
  • 1,063
  • 3
  • 14
  • 27
  • 1
    Yes, its a good remark. If you have 2 containers with the same image and different names be careful with the containers params. If containers would be have the same port options only the last one container would be running. – Alisher Gafurov Mar 08 '18 at 06:51
0

Well, that's exactly what a pod is: multiple containers that share some namespaces and volumes.

cristi
  • 2,019
  • 1
  • 22
  • 31