Difficulty: Beginner
Estimated Time: 10 minutes

In this scenario, you'll learn how to create pod using YAML. We will also run Flask python application as a kubernetes pod.

In this scenario, you learned how to build image using Dockerfile and create pods using YAML.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Kubernetes Pods with YAML

Step 1 of 4

Step 1 - Create Docker Image

In this step, we will create docker image. To complete this step, you need to complete following tasks:

Task : Create Dockerfile

To complete this task, you need to copy the following code:

FROM ubuntu
RUN apt-get update
RUN apt-get --yes install python python-pip
RUN pip install flask
COPY app.py /opt/app.py
EXPOSE 5000
ENTRYPOINT FLASK_APP=/opt/app.py flask run --host=0.0.0.0

This tells Docker to:

  • Build an image starting with the ubuntu image.
  • Install the Python dependencies.
  • Copy app.py into the path /opt in the image.
  • EXPOSE web server via port 5000
  • Using the ENTRYPOINT to specify starting command to the container.

Task : Run Docker Build

Using the docker build command to build the image. You can give the image a friendly name by using the -t <image_name> option.

To complete this task you need to execute the following code: docker build --tag flask:latest .

Dockerfile
pod.yaml