Kubernetes: Pods

Claire Lee
4 min readFeb 28, 2023

In Kubernetes, a Pod is a grouping of one or more containers that share the same environment to run in. Each Pod has a one-to-one relationship with the containers running in your application, and scaling an application requires creating new Pods with new instances of the same application rather than adding more containers to an existing Pod.

Kubernetes: Pods

Analogy Kubernetes to Restaurant Chef Overview

Kubernetes: Understanding Kubernetes Architecture through a Restaurant Chef’s Analogy

Analogy Kubernetes to Restaurant Chef

Pods(Dishes)

Pods vs. Dishes

A Pod in Kubernetes is the smallest unit of deployment that contains one or more containers. It can be customized with specific configuration options and easily replicated to meet scale-out requirements. Kubernetes manages the deployment of Pods to ensure smooth and reliable application performance.

A dish in a restaurant is the smallest unit of food that a restaurant serves to customers. It comprises a combination of ingredients that can be customized to meet the customer’s requirements, and the restaurant prepares and serves dishes to its customers.

Pods Have 1-to-1 Relationship with Containers

In Kubernetes, a Pod can have one or more containers, but each container is unique and has its own role to play. A Pod is like a holder for containers, a way to group them together to make sure they all work together as a team. If you need to scale up your application, you’ll create more Pods with more instances of your containers rather than add additional containers to an existing Pod to scale your application. But if you need to scale down, you’ll simply delete the existing Pods you don’t need anymore.

scale up an application

Short Name: po

$ kubectl api-resources
NAME SHORTNAMES APIVERSION NAMESPACED KIND
pods po v1 true Pod

Pods with YAML

  • required field
    apiVersion(string), kind(string), metadata(dictionary), spec(dictionary)
Pods with YAML

pod.yaml

apiVersion: v1
kind: Pod
metadata:
name: <pod_name>
labels:
<key1>: <value1>
<key2>: <value2>
:
:
<keyN>: <valueN>
spec:
containers:
- name: <container1_name>
image: <image>
- name: <container2_name>
image: <image>

Commands

Pod commands
  1. Create a new pod based on an image

analogy: place an order for a new dish

$ kubectl run <pod_name> --image <image>

2. Create a new pod based on the YAML file

analogy: create a new dish based on a recipe

$ kubectl create -f <file_name>.yaml

3. List all the pods that are currently running in Kubernetes

analogy: look at the menu to see all the dishes that are currently available.

$ kubectl get pods

4. Monitor all the pods that are currently running in Kubernetes in real- time

analogy: a live menu where you can see the dishes being added or removed in real-time.

$ kubectl get pods -w
$ kubectl get pods --watch

5. Display pods with their associated labels.

analogy: view the menu where each dish has a set of tags indicating its ingredients, cooking time, or other attributes.

$ kubectl get pods --show-labels

6. List pods with specified labels.

analogy: view the menu with specified tags

$ kubectl get pods -l <key1>=<value1>,<key2>=<value2>

7. List pods along with additional details

analogy: view the menu with additional details about each dish, such as the ingredients and cooking time.

$ kubectl get pods -o wide

8. Retrieve detailed information about a specific pod

analogy: describe the ingredients and preparation method for a particular dish.

$ kubectl describe pod <pod_name>

9. Open a specified pod in an editor to modify

analogy: modify an existing dish to meet specific requirements.

$ kubectl edit pod <pod-name>

10. Update an existing pod based on the YAML file

analogy: modify an existing dish to match a new recipe.

$ kubectl apply -f <file_name>.yaml

11. Delete a specified pod

analogy: remove a dish from the menu.

$ kubectl delete pod <pod_name>

12. Generates a YAML file that describes how to create a new pod(not create a new pod yet)

analogy: write down the recipe for a new dish.

$ kubectl run <pod_name> --image <image> --dry-run=client -o yaml > <file_name>.yaml

These are my personal notes for CKA exam preparation on Kubernetes. Please feel free to correct me if you notice any errors. 😊

Related Story

Reference:

--

--