How to deploy a multi-container pod to a Kubernetes cluster

Jack Wallen reveals you how to deploy a pod that has two interactive containers to a Kubernetes cluster.

Graphic: Jack Wallen

Most generally, when you deploy a pod to a Kubernetes cluster, it’s going to incorporate a one container. But there are occasions when you might need to have to deploy a pod with multiple containers. Two extremely useful reasons to deploy multi-container pods would be:

  • Sidecar containers: A utility container that aids or enhances how an application features (examples of sidecar containers are log shippers/watchers and monitoring brokers)

  • Proxies/bridges/adapters: Connect the primary container to the outside entire world

The primary explanation you’d deploy a multi-container pod would be when a one container was incapable of having treatment of each individual factor of the software. For case in point, say you deploy a pod for NGINX, but will need anything to check the logs for that container. To do that, you could deploy a multi-pod container. 

Consider it or not, the process isn’t terribly difficult. 

I am heading to wander you by way of the process of deploying a multi-container pod to a Kubernetes cluster. Precisely we’re going to build a pod with two containers, 1 working the NGINX web server that shares a quantity with a 2nd container. The second container will then write details to the to start with, to exhibit how multi-container pods can interact.

SEE: Utilizing DevOps: A guidebook for IT pros (cost-free PDF) (TechRepublic)

What you will have to have

The only thing you may want to make this work is a operating Kubernetes cluster. If you have nevertheless to spin up your cluster, verify out: How to deploy a Kubernetes cluster on Ubuntu server. Once you have your cluster up and functioning, you are ready to deploy a multi-container pod.

How to define a multi-container pod

As with almost everything in the realm of Kubernetes, we outline our multi-container pod in a YAML file. So make the new file with the command:

nano multi-pod.yml

In that file, paste the following contents:

apiVersion: v1
sort: Pod
  name: multi-pod

  restartPolicy: Never

  - title: shared-data


  - identify: nginx-container
    impression: nginx
    - name: shared-details
      mountPath: /usr/share/nginx/html

  - name: ubuntu-container
    image: ubuntu
    - identify: shared-details
      mountPath: /pod-information
    command: ["/bin/sh"]
    args: ["-c", "echo Hello, TechRepublic > /pod-data/index.html"]

Just take a look as a result of the YAML file. You can expect to see that we’ve deployed a person container primarily based on the NGINX picture, as our world wide web server. The 2nd container, named ubuntu-container, deploys a container, centered on the Ubuntu graphic, and writes the text “Hi there, Techrepublic” to the index.html file served up by the 1st container.

Help you save and shut that file.

How to deploy the multi-container pod

To deploy this multi-container pod, situation the command:

kubectl implement -f multi-pod.yml

The moment the pod is deployed, give the containers a little bit to basically improve to the functioning state (though only the to start with container will continue managing) and then access the nginx-container shell with the command:

kubectl exec -it multi-pod -c nginx-container -- /bin/bash

You ought to now locate you at the bash prompt of the nginx container. To make certain our 2nd container did its job, issue the command:

curl localhost

You should see the text “Hi, TechRepublic” printed out (Figure A).

Determine A


Our ubuntu-container productively wrote the required text to the NGINX index.html file.


And that’s how you can deploy a multi-container pod into your Kubernetes cluster. Despite the fact that this is a quite primary case in point, it shows you how containers can interact inside of a one pod. 

Also see

Resource website link

You may also like