Difficulty: beginner
Estimated Time: 45-60 minutes

BoxBoat Logo

Pods are the basic building blocks of Kubernetes. Pods are groups of containers with shared namespaces and shared volumes.

  • Pods containers are always co-located on the same host
  • Pod containers share a single IP and portspace and communicate via localhost
  • Pod containers have access to shared volumes for storage
  • Pods are designed to be ephemeral (like cattle, not pets)

In this lab we will explore the following:

Creating Pods with the command line

Using the command line is an easy way to explore pod concepts. These labs will let you inspect pod configurations, running containers and networking.

Creating Pods with manifest files

For production systems, using the command line can be error-prone. In this exercise, we explore file based pod specification and creation.

Inspecting Pods

Understanding how a pod works will him you debug issues when they arrive. In this lab, we will explore the Pod lifecycle, networking, and configuration.

Please email feedback to: [email protected]

Summary

In this lesson, we learned about Kubernetes Pods:

  • Pods are the simplest compute unit in Kubernetes.
  • Pods can be created and deleted from the command line.
  • Using Pod manifest files is best for repeatability in production environments.

Pods are fundamental to Kubernetes, but we don't often work with Pods directly. In the following lessons, we will learn about higher-order Kubernetes objects that abstract the concept of a Pod.

Understanding Kubernetes Pods

Step 1 of 7

YAML

YAML - YAML Ain't Markup Language, is the primary way we will create and configure Kubernetes objects.

YAML is very easy to read but extremely difficult to write without errors. Case in point, I will make errors during this training, and I've been using it since 2014.

Types

YAML has 2 types of objects: Maps and Lists

Maps

Maps let you associate name-value pairs

---
apiVersion: v1
kind: Pod

In this example, we start with ---, the line separator. You can use this to put multiple Kuberntes objects into the same file.

Next, we have 2 maps. Each map starts out as a key (apiVersion and kind). These keys each have an associated value (v1 and Pod).

v1 and Pod are the values, which are actually strings. You don't need to put strings in quotes. Here is what our YAML maps look like in JSON:

{
    "apiVersion": "v1",
    "kind": "Pod"
}

We can also have "values" in a Map be another Map:

---
apiVersion: v1
kind: Pod
metadata:
  name: rss-site
  labels:
    app: web

Here, metadata is a key, and its value is a Map with 2 more keys, name and labels. The value for labels is another Map.

Spacing is important, and you cannot use tabs.

Since name and labels are at the same indentation level, the YAML interpreter knows that they are part of the same Map.

Lists

YAML Lists are a sequence of objects

args:
  - sleep
  - "1000"
  - message

In JSON, our data would look like:

{
   "args": ["sleep", "1000", "message"]
}

Most common in Kubernetes, a List will be made up of Maps:

---
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  containers:
    - name: nginx
      image: nginx
      ports:
        - containerPort: 80
    - name: jwilder
      image: jwilder/hello-world
      ports:
        - containerPort: 10080

In this example, spec is a Map that contains the value containers, which is actually a list. Each element in that list is another Map. Here is what this looks like as JSON:

{
   "apiVersion": "v1",
   "kind": "Pod",
   "metadata": {
                 "name": "nginx",
                 "labels": {
                             "app": "nginx"
                           }
               },
    "spec": {
       "containers": [{
                       "name": "nginx",
                       "image": "nginx",
                       "ports": [{
                                  "containerPort": "80"
                                 }]
                      }, 
                      {
                       "name": "jwilder",
                       "image": "jwilder/hello-world",
                       "ports": [{
                                  "containerPort": "10080"
                                 }]
                      }]
            }
}

We can do things a bit more complex, but that is about the most you'll do on a day-to-day.