Exercise Pods Basics and Multi-Container Pods
Table of Contents
Introduction
In this lab, let us explore the basics of Kubernetes Pods, including how to create single-container Pods and multicontainer Pods. We will also cover the key fields in a Pod definition file.
Task 1: Nginx Pod
Create a YAML specification for an Nginx Pod:
Name:
nginx-pod
Container:
nginx
with imagenginx:1.14.2
Create a file named nginx-pod.yaml
using the vi
editor:
vi nginx-pod.yaml
Add the following content to nginx-pod.yaml
:
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.14.2
Apply the Pod configuration using the following command:
kubectl apply -f nginx-pod.yaml
Check the status of the Pod:
kubectl get pod nginx-pod
Task 2: Busybox Pod
Create a YAML specification for a Busybox Pod:
Name:
busybox-pod
Container:
busybox
with imagebusybox:1.33.1
Command: Run a simple sleep command (e.g.,
sleep 3600
)
Create a file named busybox-pod.yaml
using the vi
editor:
vi busybox-pod.yaml
Add the following content to busybox-pod.yaml
:
apiVersion: v1
kind: Pod
metadata:
name: busybox-pod
spec:
containers:
- name: busybox
image: busybox:1.33.1
command: ["sleep", "3600"]
Apply the Pod configuration using the following command:
kubectl apply -f busybox-pod.yaml
Check the status of the Pod:
kubectl get pod busybox-pod
Task 3: Multicontainer Pod
Create a YAML specification for a multicontainer Pod:
Name:
multicontainer-pod
Containers:
nginx-container
with imagenginx:1.14.2
busybox-container
with imagebusybox:1.33.1
Command: Run a simple sleep command (e.g.,
sleep 3600
) in thebusybox-container
Create a file named multicontainer-pod.yaml
using the vi
editor:
vi multicontainer-pod.yaml
Add the following content to multicontainer-pod.yaml
:
apiVersion: v1
kind: Pod
metadata:
name: multicontainer-pod
spec:
containers:
- name: nginx-container
image: nginx:1.14.2
- name: busybox-container
image: busybox:1.33.1
command: ["sleep", "3600"]
Apply the Pod configuration using the following command:
kubectl apply -f multicontainer-pod.yaml
Check the status of the Pod:
kubectl get pod multicontainer-pod
Fields in a Pod Definition File
apiVersion: Specifies the version of the Kubernetes API to use.
kind: Indicates the type of resource (e.g., "Pod").
metadata: Contains information about the Pod, such as its name, labels, and annotations.
spec: Describes the desired state of the Pod, including the containers, volumes, and other settings.
For detailed information, refer to the official Kubernetes documentation on Pods.
For more insights on this topic, have a look on my blog post on Walking Through Pods.
Multi-Container Pods
A multi-container Pod in Kubernetes is a Pod that contains two or more related containers. These containers share resources such as network space, shared volumes, and work together as a single unit. Multi-container Pods are useful for scenarios where tightly coupled processes need to run together or when containers must share resources within the same logical host.
References
Last updated