In this previous tutorial, we discussed how to create a single-container Kubernetes pod from the CLI. You can only create a single container pod from the CLI using kubectl run command. Also, whenever you create a pod from the CLI, a Deployment is automatically created so if you want to:
you need to first create a Kubernetes manifest file in yaml or json and then use kubectl create command.
As best-practice, note that multi-containers Kubernetes pods does not apply to all situations and should be used only when truly needed. This is because:
The scenarios that are best for multi-containers Kubernetes pods are:
Here is a walkthrough of creating a multi-containers Kubernetes pod. You can watch the video below:
Here is a simple manifest that creates 2 containers.
apiVersion: v1
kind: Pod
metadata:
name: two-containers
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
- name: alpine
image: alpine
command: ["watch", "wget", "-qO-", "localhost"]
Let’s use the manifest file to create a multi-containers Kubernetes pods.
$kubectl create -f two containers.yaml
Here we have 2 containers running
$kubectl get pods NAME READY STATUS RESTARTS AGE two-containers 2/2 Running 0 8s
As stated above, a deployment is not created, unlike using kubectl run that automatically creates a deployment.
$ kubectl get deployments
No resources found.
This tutorial shows how to create multi-containers Kubernetes pods using kubectl create command. We showed that a deployment was not created. As a general advice, it's not a best practice to create pods without monitoring them with a deployment. This will be addressed in the next tutorials.