DEV Community

Cover image for Getting Started with Kubernetes : An Introduction to Kubernetes
Seyi Lufadeju
Seyi Lufadeju

Posted on • Edited on

Getting Started with Kubernetes : An Introduction to Kubernetes

Introduction
Kubernetes, often abbreviated as K8s, is an open-source container orchestration platform that automates deploying, scaling, and operating application containers. Originally developed by Google, it is now maintained by the Cloud Native Computing Foundation (CNCF). This guide provides a step-by-step approach to getting started with Kubernetes.


_

Get more extensive and enriched understanding with this hands on project for Getting Started with AKS Cluster: A Hands on Guide to Deploy an Application on AKS Cluster Using a Kubernetes Manifest File -- https://dev.to/seyilufadejucyberservices/getting-started-with-aks-cluster-a-hands-on-guide-to-deploy-an-application-on-aks-cluster-using-a-5f8p
_


Explanation of Components

- Control Plane (Master Node)
The Control Plane manages the entire Kubernetes cluster, scheduling workloads, handling networking, and maintaining the desired state.

API Server: Central communication hub for Kubernetes, exposing the API used by kubectl and other components.
Controller Manager: Ensures that the cluster remains in the desired state by running controllers (e.g., ReplicaSet, Node Controller).
Scheduler: Assigns Pods to available Worker Nodes based on resource requirements.
etcd: A key-value store database that holds the current state of the cluster.

- Worker Nodes
Each Worker Node runs application workloads in Pods and is managed by the Control Plane.

Kubelet: An agent running on each Worker Node that ensures containers are running as instructed by the API Server.
Container Runtime: Software responsible for running the containers (e.g., Docker, containerd, CRI-O).
Kube Proxy: Manages networking within and outside the cluster, ensuring communication between services.

- Pods
A Pod is the smallest deployable unit in Kubernetes, containing one or more containers that share the same storage and network namespace.


📌** Diagram: Kubernetes Architecture**

+------------------------------------------------------+
|                     Control Plane                   |
| ---------------------------------------------------  |
|  API Server   |  Controller Manager  | Scheduler    |
|  etcd (Data Store)                                  |
+------------------------------------------------------+
                    |
                    v
+-----------------------------------------+
|             Worker Node 1               |
|  +-----------+  +-------------------+  |
|  | Kubelet   |  |  Pod 1 (App 1)    |  |
|  |           |  |  Pod 2 (App 2)    |  |
|  +-----------+  +-------------------+  |
|  | Kube Proxy (Networking)            |  |
|  +-------------------------------------+  |
+-----------------------------------------+
                    |
+-----------------------------------------+
|             Worker Node 2               |
|  +-----------+  +-------------------+  |
|  | Kubelet   |  |  Pod 3 (App 3)    |  |
|  +-----------+  +-------------------+  |
|  | Kube Proxy (Networking)            |  |
|  +-------------------------------------+  |
+-----------------------------------------+

Enter fullscreen mode Exit fullscreen mode

📌 Main Objects:
Kubernetes Objects Kubernetes uses objects to define the desired state of applications.
Pods: The smallest deployable unit in Kubernetes, which can contain one or more containers.
Deployments: Manages the rollout and scaling of Pods.
Services: Exposes applications to the network.
ConfigMaps & Secrets: Manage configuration data.
Persistent Volumes (PV) & Persistent Volume Claims (PVC): Manage storage.
📌 Diagram: Kubernetes Objects

+------------------+
|    Deployment    |
+------------------+
        |
        v
+------------------+       +------------------+
|      Pod 1       |       |      Pod 2       |
|  (App + Sidecar) |       |  (App + DB)      |
+------------------+       +------------------+
        |
        v
+---------------------+
|   Service (LoadBalancer)  |
+---------------------+
        |
        v
+---------------------+
| External Users/API |
+---------------------+
Enter fullscreen mode Exit fullscreen mode

📌 Networking Types:
Kubernetes Networking Kubernetes provides different networking models to allow communication within the cluster and with external clients.
Pod-to-Pod Communication (via CNI like Flannel or Calico)
Service Discovery (ClusterIP, NodePort, LoadBalancer)
Ingress Controller (Manages external access)

📌 Diagram: Kubernetes Networking

+-----------------------------------------------------+
|                     Cluster                         |
|  +---------------------+  +---------------------+  |
|  | Pod A (App)         |  | Pod B (DB)          |  |
|  +---------------------+  +---------------------+  |
|         |                           |             |
|    Service A                   Service B         |
|  +---------------------+  +---------------------+  |
|  | ClusterIP (Internal) |  | NodePort (External)|  |
|  +---------------------+  +---------------------+  |
+-----------------------------------------------------+
         |
+---------------------+
|  LoadBalancer (LB)  |
+---------------------+
         |
+---------------------+
|       Internet      |
+---------------------+
Enter fullscreen mode Exit fullscreen mode

📌 Diagram: Kubernetes Deployment Flow
Kubernetes Deployment Flow When deploying an application, Kubernetes follows these steps:
Create a Deployment → Defines the desired number of Pods.
Schedule Pods → Kubernetes schedules Pods on Worker Nodes.
Networking → Services expose applications internally and externally.
Scaling → Kubernetes automatically scales Pods based on demand.
Health Checks → Kubernetes monitors and restarts unhealthy Pods.

+------------------------------------+
|          Deployment YAML           |
+------------------------------------+
        |
        v
+------------------------------------+
|   kubectl apply -f deployment.yml  |
+------------------------------------+
        |
        v
+------------------------------------+
|          Kubernetes API Server     |
+------------------------------------+
        |
        v
+------------------------------------+
|         Scheduler Assigns Pod      |
+------------------------------------+
        |
        v
+------------------------------------+
|         Pod Runs on Node           |
+------------------------------------+
        |
        v
+------------------------------------+
|     Service Exposes App            |
+------------------------------------+
Enter fullscreen mode Exit fullscreen mode

📌 Scaling:
Kubernetes Scaling and Self-Healing Kubernetes ensures applications remain available by automatically scaling and self-healing.
Horizontal Pod Autoscaler (HPA): Increases/decreases Pods based on CPU/memory usage.
Cluster Autoscaler: Adds/removes Worker Nodes.

📌 Self-Healing:

Restarting Failed Pods: Kubelet restarts unhealthy Pods.
Rescheduling Pods: If a Node fails, Kubernetes schedules Pods on another Node.

📌 Diagram: Kubernetes Scaling

+------------------+
|     HPA          |
+------------------+
        |
        v
+------------------+       +------------------+       +------------------+
|      Pod 1       | ----> |      Pod 2       | ----> |      Pod 3       |
+------------------+       +------------------+       +------------------+
Enter fullscreen mode Exit fullscreen mode

Prerequisites
Before diving into Kubernetes, ensure you have the following prerequisites:

  • Basic understanding of containers and Docker

  • A system with at least 4GB RAM and a multi-core processor

  • Installed tools: Docker, Kubectl, Minikube (for local Kubernetes cluster)


Setting Up Kubernetes
- Install Minikube (Local Cluster)

# Install Minikube (MacOS/Linux)
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

# Install Minikube (Windows - Use PowerShell)
wget https://storage.googleapis.com/minikube/releases/latest/minikube-windows-amd64.exe -OutFile minikube.exe
Move-Item .\minikube.exe C:\Windows\
Enter fullscreen mode Exit fullscreen mode

- Start Minikube

minikube start
Enter fullscreen mode Exit fullscreen mode

- Verify Installation
Run the following command to check if Minikube is running:

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

You should see an output indicating a single node is in a Ready state.


Kubernetes Basic Concepts

- Pods
A Pod is the smallest deployable unit in Kubernetes, encapsulating one or more containers.

kubectl run my-pod --image=nginx --restart=Never
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

- Deployments
A Deployment manages a set of identical Pods.

kubectl create deployment my-deployment --image=nginx
kubectl get deployments
Enter fullscreen mode Exit fullscreen mode

- Services
A Service exposes a set of Pods to external traffic or internal services.

kubectl expose deployment my-deployment --type=NodePort --port=80
kubectl get services
Enter fullscreen mode Exit fullscreen mode

Conclusion
Kubernetes simplifies container management by automating deployment, scaling, and networking. Understanding its architecture and key components (Pods, Deployments, Services) is essential for mastering cloud-native application deployment.

Top comments (0)