Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we have same kind of multiple containers in a Pod in Kubernetes?

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
like image 750
Madhurima Mishra Avatar asked Oct 23 '15 11:10

Madhurima Mishra


2 Answers

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

like image 118
Shahriar Avatar answered Oct 08 '22 11:10

Shahriar


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

like image 34
Madhurima Mishra Avatar answered Oct 08 '22 12:10

Madhurima Mishra