Kubernetes is an application
Kubernetes is an application
A Kubernetes cluster is made of a control plane/ Master node and nodes/ worker
node. The control plane exposes the API, has a scheduler
for assigning work, and records the state of the cluster and apps in a persistent
store. Nodes are where user
applications run.
Kubernetes control plane nodes are servers that run the cluster’s control plane
services.
(1) The API server--The API server is the Grand Central of Kubernetes. All
communication, between all components, must go
through the API server
(2) The cluster store(etcd service)--The cluster store is the only stateful part of
the control plane and persistently stores the entire configuration and
state of the cluster.The cluster store is the only stateful part of the control
plane and persistently stores the entire configuration and
state of the cluster.
(4)The scheduler- The scheduler is responsible for deciding which node will run a
new Pod in Kubernetes. It does not run the Pod—it just picks the best node for it.
How Does the Scheduler Work
Watches for new tasks (Pods) in the API Server.
Filters out unsuitable nodes (e.g., not enough CPU/RAM, network port conflicts,
taints, affinity/anti-affinity rules).
Ranks the remaining nodes based on factors like:
Does it already have the required container image?
How much free CPU and memory does it have?
How many tasks is it already running?
Selects the best node (highest ranking score) and assigns the task (Pod) to it.
Worker nodes
worker Nodes are servers that are the workers of a Kubernetes cluster.
At a high-level they do three things:
1. Watch the API server for new work assignments
2. Execute work assignments
3. Report back to the control plane (via the API server)
(3) Kube-Proxy-- kube-proxy runs on every node and is responsible for networking
inside the Kubernetes cluster.
What Does Kube-Proxy Do?
Assigns a Unique IP to Each Node
Ensures every node in the cluster gets a unique internal IP.
Manages Service Networking (Routing Traffic to Pods)
It sets up iptables or IPVS rules to forward traffic to the correct Pod.
Without kube-proxy, Services in Kubernetes wouldn’t work.
Handles Load Balancing Inside the Cluster
Distributes traffic between Pods for a Service.
Uses Round-Robin, Least Connections, or other algorithms depending on
IPVS/iptables mode.
Kubernetes DNS---Kubernetes has an internal DNS service that allows Pods and
Services to discover and communicate with each other using domain names instead of
IPs.Kubernetes uses CoreDNS to provide internal DNS resolution.CoreDNS typically
runs only on control plane nodes because it is part of the cluster's control plane
services.
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: myapp
image: myregistry.com/myapp:v1
Deploy Using a Manifest File:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myregistry.com/myapp:v1
Kubernetes follows a declarative model, meaning you describe how your application
should look, and Kubernetes makes it happen.
How It Works:
Declare the Desired State:
You write a YAML manifest file that describes your application’s state.
Example: How many replicas to run, which image to use, and what ports to
expose.
Submit to the API Server:
You use kubectl apply -f deployment.yaml to send the manifest to
Kubernetes.
Store in the Cluster:
Kubernetes saves this as the desired state in its database (etcd).
Implement the Desired State:
Kubernetes schedules Pods on available nodes and ensures the application
runs.
Continuous Monitoring & Self-Healing:
If the observed state (what’s actually running) differs from the desired
state, Kubernetes fixes it.
Example: If a Pod crashes, Kubernetes creates a new one to replace it.
Example Scenario
You deploy a web app with 10 replicas (desired state). If a node crashes, reducing
the running replicas to 8, Kubernetes automatically creates 2 new replicas to
restore the desired count to 10.
Here's a simple Deployment YAML file for a web application running 10 replicas in
Kubernetes:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 10 # Desired number of replicas
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: web-app
image: nginx:latest # Replace with your application image
ports:
- containerPort: 80
Explanation:
replicas: 10 → Ensures 10 instances of the app are always running.
image: nginx:latest → Uses an Nginx container (replace with your own app
image).
Kubernetes monitors the state → If a Pod crashes, Kubernetes replaces it
automatically.
Pod in Kubernetes