In this blog, we will see about creating single-container Pod and multi-container pod on Kubernetes.
In the below example, we will see about creating pods and how to troubleshoot if any error occurs.
Create Single-Container Pod
First, we will see about creating a single-container pod, as the name suggests we are going to deploy a single container on the pod.
Run the following command to deploy a single container on the pod.
kubectl run single-container --image nginx:latest
This command will deploy a single container of the latest nginx on the default namespace.
You can check if the pod is deployed and running successfully using the command
kubectl get pods
Create Multi-Container Pod
Next, we will see about creating a multi-container pod, as the name suggests we are going to deploy multiple containers on the pod.
For this we have to use a manifest file, we cannot create multiple containers using the command line.
Run the following command to create a manifest file, which will have nginx image configurations in which we are going to add a log reader for nginx as a sidecar container.
kubectl run multi-container --image nginx --dry-run=client -o yaml > manifest.yaml
Open the manifest file and add the log reader as another container as given below
Once you have modified the manifest file, use the below command to deploy both containers.
kubectl apply -f manifest.yaml
This command will deploy the multiple container species on the manifest file on the default namespace as shown below
TroubleShooting Pod
If the pod stops or restarts again and again there may be an error on the pod, to troubleshoot the pod we can use the describe and logs command.
By using the describe command and logs command we can identify the issue and troubleshoot it easily.
As an example, I am going to use the describe command on the single-container pod and the logs command on the multi-container pod.
Run the following command to describe the single-container pod
kubectl describe po single-container
You will get the following output
If the pod has any error, you can find it at the Events at the bottom.
Now, let’s use the logs command on the kubectl logs single-containermulti-container pod, run the following command to get the logs
kubectl logs single-container
You can find the logs of the pod with timestamps.