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

how-to-deploy-a-multi-container-pod-to-a-kubernetes-cluster

Jack Wallen shows you how to deploy a pod that contains two interactive containers to a Kubernetes cluster.

Image: Jack Wallen

Most often, when you deploy a pod to a Kubernetes cluster, it’ll contain a single container. But there are instances when you might need to deploy a pod with multiple containers. Two very useful reasons to deploy multi-container pods would be:

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

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

The main reason you’d deploy a multi-container pod would be when a single container was incapable of taking care of every aspect of the application. For example, say you deploy a pod for NGINX, but need something to monitor the logs for that container. To do that, you could deploy a multi-pod container. 

Believe it or not, the process isn’t terribly challenging. 

I’m going to walk you through the process of deploying a multi-container pod to a Kubernetes cluster. Specifically we’re going to create a pod with two containers, one running the NGINX web server that shares a volume with a second container. The second container will then write data to the first, to show how multi-container pods can interact.

SEE: Implementing DevOps: A guide for IT pros (free PDF) (TechRepublic)

What you’ll need

The only thing you’ll need to make this work is a running Kubernetes cluster. If you have yet to spin up your cluster, check out: How to deploy a Kubernetes cluster on Ubuntu server. Once you have your cluster up and running, you’re ready to deploy a multi-container pod.

How to define a multi-container pod

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

nano multi-pod.yml

In that file, paste the following contents:

apiVersion: v1
kind: Pod
metadata:
  name: multi-pod
spec:

  restartPolicy: Never

  volumes:
  - name: shared-data
    emptyDir: {}

  containers:

  - name: nginx-container
    image: nginx
    volumeMounts:
    - name: shared-data
      mountPath: /usr/share/nginx/html

  - name: ubuntu-container
    image: ubuntu
    volumeMounts:
    - name: shared-data
      mountPath: /pod-data
    command: ["https://www.techrepublic.com/bin/sh"]
    args: ["-c", "echo Hello, TechRepublic > /pod-data/index.html"]

Take a look through the YAML file. You’ll see that we’ve deployed one container based on the NGINX image, as our web server. The second container, named ubuntu-container, deploys a container, based on the Ubuntu image, and writes the text “Hello, Techrepublic” to the index.html file served up by the first container.

Save and close that file.

How to deploy the multi-container pod

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

kubectl apply -f multi-pod.yml

Once the pod is deployed, give the containers a bit to actually change to the running state (although only the first container will continue running) and then access the nginx-container shell with the command:

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

You should now find yourself at the bash prompt of the nginx container. To make sure our second container did its job, issue the command:

curl localhost

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

Figure A

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

Huzzah!

And that’s how you can deploy a multi-container pod into your Kubernetes cluster. Although this is a very basic example, it shows you how containers can interact within a single pod. 

http://www.techrepublic.com/

Developer Essentials Newsletter

From the hottest programming languages to the jobs with the highest salaries, get the developer news and tips you need to know.
Weekly



Sign up today

Also see

How to deploy the Wekan Kanban board project management server with snap

how-to-deploy-the-wekan-kanban-board-project-management-server-with-snap

If you’re looking to deploy an in-house project management server, look no further than Wekan. Learn how to get this handy service up and running in minutes.

Image: Getty Images/iStockphoto

Kanban boards are a widely-used tool for project management. With these boards, you can manage time spent on specific aspects of a project and keep you and your team highly organized. 

Wekan is an open source (and free) Kanban board that can be deployed on your network such that it can be accessed by anyone on the LAN. Wekan is used across the globe and by companies with over 13,000 users, enjoys a real-time interface, and supports numerous platforms.

I want to walk you through the process of deploying Wekan with the help of snap and NGINX. 

SEE: VPN usage policy (TechRepublic Premium)

What you’ll need

In order to demonstrate this process, I’ll be using Ubuntu Server 18.04, but you can deploy Wekan on any platform that supports both snap packages and NGINX. 

How to install NGINX

First, we must install the NGINX web server. To do that, issue the command:

sudo apt-get install nginx -y

Start and enable NGINX with the commands:

sudo systemctl start nginx
sudo systemctl enable nginx

How to install Wekan

It’s time to install Wekan. The easiest way of doing this is via snap packaging. To install Wekan, issue the command:

sudo snap install wekan

Once Wekan is installed, we need to set the root URL address with the command:

sudo snap set wekan root_url="http://SERVER_IP"

Where SERVER_IP is the IP address of the hosting server.

Set the Wekan port with the command:

sudo snap set wekan port='3001'

When this completes, restart all of the necessary services with the commands:

sudo systemctl restart snap.wekan.mongodb
sudo systemctl restart snap.wekan.wekan

How to access Wekan

Open a web browser and point it to http://SERVER_IP: 3001 (where SERVER_IP is the IP address of the hosting machine). You should be immediately prompted to sign in or register a new account (Figure A).

Figure A

The Wekan kanban board sign in screen.

Click the Register button and then fill out the necessary information for a new user. You will see an Internal Error warning listed above the login screen. Ignore that error and click Sign In. Use the username and password you used when creating the new user and it’ll log you in. 

You will then be greeted by the Wekan main page, where you can begin creating your first Kanban boards. You should also visit the admin panel and configure features like email, user accounts, announcements, layouts, and global webhooks (Figure B).

Figure B

Configuring Wekan from the admin panel.

And that’s all there is to getting this outstanding Kanban-based project management server up and running on your LAN.

http://www.techrepublic.com/

Open Source Weekly Newsletter

You don’t want to miss our tips, tutorials, and commentary on the Linux OS and open source applications.
Delivered Tuesdays



Sign up today

Also see