Creating Kubernetes Pods

15 minutes
  • 2 Learning Objectives

About this Hands-on Lab

Pods are the essential building-block of any Kubernetes application. When learning to use Kubernetes, one of the first things you will need to know is how to create pods. This lab will guide you through the process of creating a simple pod with a few basic settings. After completing this lab, you will know how to create pods, and you will be ready to begin exploring Kubernetes more deeply in the future.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a yaml file containing the pod spec for the nginx pod.

Create a file in /home/cloud_user/nginx.yml with this content:

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: web
spec:
  containers:
  - name: nginx
    image: nginx
    command: ["nginx"]
    args: ["-g", "daemon off;", "-q"]
    ports:
    - containerPort: 80
Create the pod.

Create the pod from the yaml file:

kubectl create -f /home/cloud_user/nginx.yml

You should see the pod listed with this command:

kubectl get pods -n web

It should have a status of Running.

Additional Resources

Your company is getting ready to launch a new website, and they need you to set up an nginx web server in their Kubernetes cluster. The nginx server will need to be accessible via network in the future, so you will need to expose port 80 as a containerPort for the nginx container. Your team has also asked you to ensure that nginx runs in quiet mode for the time being to cut down on unnecessary log output. You can do this by setting the command to nginx and passing the following arg to the container: -g daemon off; -q. As this nginx server belongs to the Web team, you will need to create it in the team's web namespace.

To summarize:

  • Use the nginx container image.
  • The container needs a containerPort of 80.
  • Set the command to nginx
  • Pass in the -g daemon off; -q args to run nginx in quiet mode.
  • Create the pod in the web namespace.

Once the pod is created, you should be able to find it with kubectl get pods -n web. Once the pod is created, you can get more information about its current status with kubectl describe pod nginx -n web.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?