kubernetes

soni rajasoni raja
3 min read

Introduction

This article provides an introduction to Kubernetes, a popular container orchestration platform known as k8s, which simplifies deploying, scaling, and managing containerized applications. It highlights the prerequisites of Docker knowledge and the utility of Kubernetes for auto-healing, autoscaling, and system observation. Key concepts include nodes, clusters, images, containers, and pods. The article also offers practical guidance on creating Kubernetes clusters using tools like Kind and Minikube, both locally and on cloud platforms such as GKE and AWS K8s.


What is kubernetes

Docker is a pre-requisite before you proceed to understand kubernetes

Kubernetes (popularly known as k8s) is a container orchestration engine, which as the name suggests lets you create, delete, and update containers

This is useful when

  1. You have your docker images in the docker registry and want to deploy it in a cloud native fashion

  2. You want to not worry about patching, crashes. You want the system to auto heal

  3. You want to autoscale with some simple constructs

  4. You want to observe your complete system in a simple dashboard

notion image

💡

Kubernetes is also known as k8s. K_ _ s

Before kubernetes

Backend

notion image

Frontend (Nextjs)

notion image

Frontend (React)

notion image

After kubernetes

Your frontend, backend are all pods in your kubernetes cluster

notion image

Jargon

Ref - https://kubernetes.io/docs/concepts/overview/components/

Nodes

In kubernetes, you can create and connect various machines together, all of which are running kubernetes. Every machine here is known as a node

There are two types of nodes

Master Node (Control pane) - The node that takes care of deploying the containers/healing them/listening to the developer to understand what to deploy

![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F085e8ad8-528e-47d7-8922-a23dc4016453%2Fbc046171-9624-411b-a06b-391ac9d38af8%2FScreenshot_2024-06-01_at_2.55.57_AM.png?table=block&id=28f4ee90-9008-4054-a9ea-427e218272dd&cache=v2 align="left")

Worker Nodes - The nodes that actually run your Backend/frontend

![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F085e8ad8-528e-47d7-8922-a23dc4016453%2F2f0cf057-07cf-43d7-8865-d56f84ac664d%2FScreenshot_2024-06-01_at_3.19.30_AM.png?table=block&id=fb76030e-0923-45af-b81f-d9bba531f3d3&cache=v2 align="left")

notion image

notion image

Cluster

A bunch of worker nodes + master nodes make up your kubernetes cluster . You can always add more / remove nodes from a cluster.

Images

A Docker image is a lightweight, standalone, and executable software package that includes everything needed to run a piece of software, including the code, runtime, libraries, environment variables, and configuration files. Images are built from a set of instructions defined in a file called a Dockerfile.

Eg - https://hub.docker.com/_/mongo

Containers

A container is an image in execution. For example if you run

docker run -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword  -d postgres

Pods

A pod is the smallest and simplest unit in the Kubernetes object model that you can create or deploy

notion image

Creating a k8s cluster

Locally (Make sure you have docker)

  1. minukube

  2. kind - https://kind.sigs.k8s.io/docs/user/quick-start/

On cloud

  1. GKE

  2. AWS K8s

  3. vultr

Using kind

Single node setup

  • Create a 1 node cluster
kind create cluster --name local
  • Check the docker containers you have running
docker ps
  • You will notice a single container running (control-pane)

  • Delete the cluster

kind delete cluster -n local

Multi node setup

  • Create a clusters.yml file
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
  • Create the node setup
 kind create cluster --config clusters.yml --name local
  • Check docker containers
docker ps

notion image

Now you have a node cluster running locally

Using minikube

minikube start
  • Run docker ps to see the single node setup

💡

A single node setup works but is not ideal. You don’t want your control pane to run containers/act as a worker.

0
Subscribe to my newsletter

Read articles from soni raja directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

soni raja
soni raja

I'm cloud and devops for crafting robust and scalable solutions. With expertise in languages such as C/C++, JavaScript, and Node.js and a keen eye for optimizing database performance and mainting CI/CD piplines, I specialize in building and deploying web applications on servers. I've successfully implemented and maintained various backend systems, ensuring seamless functionality and a positive user experience. I'm excited about the prospect of collaborating on impactful projects and contributing my skills to innovative solutions.