“Hello World” in Kubernetes — For absolute Beginners — Part 1

Vignesh Kathirkamar
4 min readJul 16, 2022

This article is aimed at beginners who are just getting started with Kubernetes.

There is also a video version of this same article which you can find here: https://youtu.be/KbZOb0nzVlo

To understand this article in depth, following are the pre-requisites:

  1. Basic knowledge of Python and preferably “Flask” web framework
  2. What is Docker

Other requirements/installation required are as follows:

  1. Docker
  2. Minikube
  3. An account in Docker Hub
  4. kubectl

If you don’t have any of the above two, get them installed to follow this article.

Following are the version of Docker and Minikube I had installed at the time of writing this article.

Step 1: Create a “Hello World” application in Flask

Create a python file and copy paste the below code into it and name it as main.py.

The above part of code when run displays “Hello, How are you buddy?” in a browser in localhost as shown below

Hello World in Flask

Step 2: The Docker Part

Docker Basics:

The above image is all what you have to know about Docker. We aren’t going to give our computer to the client, so we are going to build a docker image which will work on clients end.

Step 2a: Creation of Dockerfile

Before creating the Docker file, find the folder structure of this project below

folder structure

You can find that I have kept the “main.py”, “requirements.txt” and “Dockerfile” in same folder called “tut_4”.

The “main.py” contains the code which we wrote in step 1

The “requirements.txt” contains the necessary python packages required for the project to run. (tip: use the command “pip freeze > requirements.txt” on your terminal to get your requirements.txt)

Finally create a file called “Dockerfile” without any extensions as shown in the figure and copy paste the below code into it.

Step 2b: Build, Tag and Push of Docker image

Build your docker image using the following command

sudo docker build -t <name_for_docker_image> .
Eg:
sudo docker build -t hello-world .

The above command will build your docker image, once it is done, Tag your docker image with the following commands. For, this purpose you need to have your account created in Docker Hub.

First login to the docker account using the below command

sudo docker login

the above command will prompt for your user id and password, enter them and follow the below command

sudo docker tag <docker image name>:<tag> <docker user id>/<some tag name>
Eg:
sudo docker tag hello-world:0.1 vigneshkathirkamar/hello-world:0.1

(your tag name can be a string too, example: “first”, “second”)

Once we have Tagged the docker image, its time to Push it to the Docker Hub repository using the following command

sudo docker push <image>
Eg:
sudo docker push vigneshkathirkamar/hello-world:0.1

Step 3: The Kubernetes Part

Before diving into Kubernetes, it is good to have a understanding of the terms “kubernetes cluster”,“node”, “container” and “pod”.

Find the image below of a Kubernetes Cluster:

As you can see above, a Kubernetes cluster is composed of “Node(s)” and “Control Plane”

Node: So, what are “Node(s)” in Kubernetes. Find the image below:

A Node is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster. Each Node is managed by the control plane. A Node can have multiple pods.

Now as we are clear with what a Node is, let’s move on to Pod.

Pod: As you can see from the above figure, the Node encompass the Pods. And within pods you can find cubes and cylinders. As mentioned in the figure, the cubes are nothing but Docker containers and the cylinders are Volume (Let’s discuss about Volume in another article).

Also you can find on one side of the hexagon (Node)figure, “kubelet” and “Docker”.

  • Kubelet is a process responsible for communication between the Kubernetes control plane and the Node; it manages the Pods and the containers running on a machine.
  • A container runtime (like Docker) is responsible for pulling the container image from a registry, unpacking the container, and running the application.

Let’s discuss the further steps in the next article — “ “Hello World” in Kubernetes — For absolute Beginners — Part 2 "

--

--