Difficulty: beginner
Estimated Time: 20-30 minutes

Digital Academy Logo

Welcome to the Digial Academy's "Kubernetes Fundamentals" series. This is Module 3 - Intro to Pods.

In this lab, we will examine how to run containers in Pods.

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 emphemeral (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 explore pod concepts. These labs will let you inspsect 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 debig issues when they arrive. In this lab we will explore the Pod lifecycle, networking, and configuration.

For more information, see the Kubernetes documentation.

Developer(s): William Hearn and Zachary Seguin

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 won'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.

Module 3 - Intro to Pods

Step 1 of 6

Pods on the command line

Pods are the base primitive that Kubernetes uses to manage containerized applications. We can easily create a Pod on the CLI:

kubectl run nginx --image=nginx --port=80 --restart=Never

We start with kubectl run. This instructs Kubernetes to create a Pod resource. The first parameter, nginx, provides the name of the Pod. After that, --image=nginx instructs Kubernetes to create a Pod that runs a container based off the nginx image. --port=80 instructs Kubernetes to have the underlying container listen on port 80. --restart=Never tells Kubernetes to not restart the Pod.

List running Pods

Now that we have a Pod, we can see it in action by using the get verb:

kubectl get pods

NOTE: po is short for pods, so this works too: kubectl get po

We can see that we have a single Pod with a status of running:

nginx     1/1       Running   0          10s

NOTE: kubectl get is a common Kubernetes command that we will use throughout the training.

Inspect running Pods

Often we will need to inspect running Kubernetes objects. To do this we use the describe verb.

kubectl describe gives us more information about any Kubernetes object.

To show detailed information about our running Pod, use:

kubectl describe pods nginx

We can chain this command to get more fine-grained details:

kubectl describe pod nginx | grep IP | awk '{print $2}'

That will get the IP address of our nginx Pod. In general, you won't actually create Pods using the CLI. However, understanding how to get information from them is extremely important.

We can see that our Pod has a unique IP address, which we'll use in a second. Right now, our pod has been scheduled on node01:

kubectl describe pod nginx | grep Node | awk '{print $2}'

Let's SSH to this node:

ssh node01

We can actually see the container running Docker:

docker container ls | grep k8s_nginx

Let's inspect this container using docker container inspect, followed by the name of the container. Don't worry, you can just tab complete the name.

We can see that our container is running nicely. However, we can also see it doesn't have an IP address. Kubernetes is abstracting this away, even from Docker.

We already got the IP address of the Pod before, so let's download the files from NGINX using curl.

You'll need to execute curl <container IP>, with your specific IP address for the container.

Now that we've accessed the container, let's look at the logs with Docker, using docker container logs k8s_nginx, make sure to tab complete that.

Now exit the SSH session, we'll use kubectl to read the logs as well:

kubectl logs nginx

The messages are the same, Kubernetes is just abstracting away Docker.

Delete a Pod

For now, let's clean up the environment by deleting our Pod.

kubectl delete is the command we’ll use to delete resources.

kubectl delete pod nginx

WARNING: Be careful, once our Pod is deleted, it is gone forever.

This tab will not be visible to users and provides only information to help authors when creating content.

Creating Katacoda Scenarios

Thanks for creating Katacoda scenarios. This tab is designed to help you as an author have quick access the information you need when creating scenarios.

Here are some useful links to get you started.

Running Katacoda Workshops

If you are planning to use Katacoda for workshops, please contact [email protected] to arrange capacity.

Debugging Scenarios

Below is the response from any background scripts run or files uploaded. This stream can aid debugging scenarios.

If you still need assistance, please contact [email protected]