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) | | | +-------------------------------------+ | +-----------------------------------------+
π 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 | +---------------------+
π 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 | +---------------------+
π 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 | +------------------------------------+
π 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 | +------------------+ +------------------+ +------------------+
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\
- Start Minikube
minikube start
- Verify Installation
Run the following command to check if Minikube is running:
kubectl get nodes
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
- Deployments
A Deployment manages a set of identical Pods.
kubectl create deployment my-deployment --image=nginx kubectl get deployments
- 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
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)