Can we have the same container with multiple containers in a pod in Kubernet?

For example, can I use yaml to create a container 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 
+5
source share
3 answers

Yes, you can add multiple containers with the same image.

The container object must contain:

  • Name: The name of the container. It must be DNS_LABEL and be unique inside the module. Unable to update.
  • image: The name of the docker image.

You need to make a unique container name

You can do the 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 container specification should include a unique port number in the Pod

+3
source

The same types of containers may be there, but then their port will be different.

+1
source

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

0
source

Source: https://habr.com/ru/post/1234362/


All Articles