5 min read

How to create a simple Kubernetes cluster for local development?

Kubernetes, the container orchestration technology become one of the most demanding skills of software developers in the age of containerized applications.
How to create a simple Kubernetes cluster for local development?
How to create a simple Kubernetes cluster for local development?
Cracking the Certified Kubernetes Application Developer - CKAD exam in one month
Are you looking for the CKAD certification to sharpen your k8s skills? Check out this post for exam preparation tips.
Kubernetes, the container orchestration technology become one of the most demanding skills of software developer in the age of containerized application. In this series, I will share some hands-on experiences with Kubernetes that allow any developers to practice and gain K8S knowledge. Let start with what is K8S cluster and how to setup one on your local machines.

What are Kubernetes and Kubernetes clusters?

In a short definition, Kubernetes is an open-source system for automating the deployment, scaling, and management of containerized applications.

Kubernetes's short name is K8S as an abbreviation results from counting the eight letters between the "K" and the "s". Starting as an internal project in Google led by Joe Beda, Brendan Burns, and Craig McLuckie, K8S is now one of the most popular open-source projects under the Cloud Native Foundation (https://www.cncf.io/projects/kubernetes/).

The Kubernetes release timeline (source of information: Wikipedia, cncf.io)

A Kubernetes cluster is a set of nodes (master & worker nodes) that run containerized applications. Containerizing applications package an app with its dependencies and some necessary services.

The components of a Kubernetes cluster (image credit: Kubernetes.io)

More about Kubernetes:

Setup a Kubernetes cluster using  minikube

That's enough for theory, as clusters are the core of the K8S system, and all components of K8S run on clusters. Let's do some practice to get started with Kubernetes. I will demonstrate how we can install a single-node cluster using a tool called "minikube" (Windows OS).

Pre-requisites:

  • Docker for desktop installed.
  • Windows Hyper-V enabled.

Step 01: Download the installation package (minikube-installer.exe)

https://github.com/kubernetes/minikube/releases/latest/download/minikube-installer.exe

Step 02: Install "minikube" tool

Step 03: Start "minikube" (open your CMD and type the below command)

$ minikube start
The "minikube" tool was installed successfully! 

Let's verify the installation by some kubectl commands (a command-line tool for communicating with a Kubernetes cluster's control plane)

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.8", GitCommit:"9f2892aab98fe339f3bd70e3c470144299398ace", GitTreeState:"clean", BuildDate:"2020-08-13T16:12:48Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:53:14Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}

$ kubectl get nodes
NAME       STATUS   ROLES                  AGE   VERSION
minikube   Ready    control-plane,master   77d   v1.21.2

$ kubectl cluster-info
Kubernetes master is running at https://127.0.0.1:54008
CoreDNS is running at https://127.0.0.1:54008/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

Congrats, you've successfully set up a single-node cluster using "minikube" tool.

Let's try to run an Nginx container within our k8s cluster.

# Create a new pod that use nginx:alpine image
$ kubectl run my-nginx-server --image=nginx:alpine --restart=Never --port=80
pod/my-nginx-server created

# Get list of pods
$ kubectl get pods
NAME                          READY   STATUS      RESTARTS   AGE
my-nginx-server              1/1     Running     0          26s

# Execute a command in a container.
$ kubectl exec -it my-nginx-server sh
/ # curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Look good so far, we went through some concepts in Kubernetes like cluster, node, pod, kubectl... As this is just the 1st post of the Kubernetes series, we will be sure to emphasize these concepts again in upcoming posts to make sure we clearly understand them.

Recaps

  • Kubernetes: an open-source system for automating the deployment, scaling, and management of containerized applications.
  • Kubernetes cluster: a logical set of nodes (master & worker) that run containerized applications.
  • Worker nodes: where the containerized applications run, it can be a physical or virtual machine, that is controlled by the control-plane (master node).
  • kubectl: a command-line tool for communicating with a Kubernetes cluster's control plane.
  • pod: smallest deployment unit in k8s, a group of 1 or more containers that share network & storage resources, pod will be placed in cluster nodes.

Notes: Kubernetes support many containerization technologies (containerd, CRI-O, CRI), Docker is the default container runtimes.

What's next?

Going through the first post in this Kubernetes series, we have an overview of what is K8S and how to install a single-node cluster. In the next post, we will deep-dive into Kubernetes components and object to understand them more clearly about Kubernetes before starting some demo project to deploy our containerized applications to cloud infrastructure using Kubernetes.

The best is yet to come, stay tuned.