containerization-and-devops

Class 12 - Kubernetes 2 (Review & Basics)

1. Introduction to Kubernetes

What is Kubernetes? Kubernetes is a platform used to:

πŸ‘‰ It handles everything needed to run apps reliably.

Why Kubernetes is Needed Modern apps have:

Problems without Kubernetes:

Solution: Kubernetes automates:


2. Kubernetes Architecture

A cluster has 2 main parts:

A. Control Plane (Master)

Components:

  1. API Server: Entry point, all commands go through it
  2. Scheduler: Decides where containers run
  3. Controller Manager: Maintains desired state (e.g., Keeps 3 pods running)
  4. etcd: Stores cluster data

B. Worker Nodes

Components:

  1. Kubelet: Talks to control plane
  2. Container Runtime: Runs containers (Example: Docker)
  3. Kube Proxy: Handles networking

3. Why Not Real Kubernetes for Learning?

Real clusters need:

πŸ‘‰ Not suitable for laptops


4. Tools for Local Kubernetes

Tool Characteristics
Minikube Single node, Beginner friendly
k3s Lightweight Kubernetes
k3d Runs k3s in Docker, Fast and easy
kind Kubernetes in Docker, Good for testing


6. Installation

Install kubectl

curl -LO https://dl.k8s.io/release/stable/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
kubectl version --client

Install k3d

curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash

Create Cluster

k3d cluster create mycluster
kubectl get nodes

Terminal Output

Installation and Cluster Creation


7. kubectl Basics

What is kubectl? CLI tool to interact with Kubernetes.

Cluster Connection kubectl uses: ~/.kube/config Contains:

View Clusters

kubectl config get-contexts

Switch Cluster

kubectl config use-context k3d-mycluster

8. Common Commands (IMPORTANT)

View Nodes:

kubectl get nodes

View Pods:

kubectl get pods

Run Container:

kubectl run nginx --image=nginx

Pod Details:

kubectl describe pod nginx

Logs:

kubectl logs nginx

Terminal Output

Common Commands


9. Deployment

Create Deployment:

kubectl create deployment web --image=nginx

Scale App:

kubectl scale deployment web --replicas=3

Expose App:

kubectl expose deployment web --port=80 --type=NodePort

Access App:

kubectl port-forward service/web 8080:80

Delete:

kubectl delete pod nginx
kubectl delete deployment web

Terminal Output

Deployment and Services


10. Advanced Topics (Mention Only)


11. kubeconfig Deep Understanding

3 Main Sections:

  1. Clusters: Server address
  2. Users: Credentials
  3. Context: Cluster + User

Current Context: current-context: k3d-mycluster


12. How kubectl Works

  1. Reads kubeconfig
  2. Finds context
  3. Connects to API server
  4. Executes command

13. Common Issues

kubectl not working:

Fix:

kubectl config use-context <correct-cluster>

14. Simple Analogy


15. Final Summary

Kubernetes manages containers automatically.

πŸ”₯ One-Line Memory Trick:

Kubernetes = β€œSystem that ensures your app runs exactly how you defined.”


← Previous Class Next Class β†’ Theory Index