Kubernetes and Docker
What is the pod ?
What is a Pod?
A Pod is the smallest deployable unit in Kubernetes.
It represents one or more containers that:
Share the same network (IP, ports)
Share storage volumes
Run together on the same node
Think of a Pod as a wrapper around containers.
Manifest yaml file:
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
2)what is the replicates?
ReplicaSet (Ensure Desired Number of Pods)
🔹 What is a ReplicaSet?
A ReplicaSet ensures a specified number of identical Pods are running at all times.
🔹 Why do we use ReplicaSets?
High availability
Self-healing
Automatic Pod recreation
===================
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-rs
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
====================
What ReplicaSet Does
Watches Pods with matching labels
If Pod crashes → creates a new one
If extra Pod exists → deletes it
=====================
Deployment (Production-Grade Controller)
🔹 What is a Deployment?
A Deployment is a higher-level object that:
Manages ReplicaSets
Provides rolling updates
Enables rollback
🔹 Why do we use Deployments?
Zero-downtime deployments
Version control of applications
Safe upgrades & rollbacks
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
strategy:
type: RollingUpdate
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
=======
Docker Fundamentals
A. Docker Image
🔹 What is it?
A Docker image is a read-only blueprint that contains:
Application code
Runtime (JVM, Node, Python, etc.)
Libraries & dependencies
OS user-space
🔹 Why do we use images?
Consistent environments
Immutable deployments
Fast startup
🔹 Where used?
Local development
CI/CD pipelines
Kubernetes Pods
🔹 How implemented?
docker pull nginx
docker images
B. Docker Container
🔹 What is it?
A container is a running instance of an image.
🔹 Why do we use containers?
Lightweight (vs VM)
Fast startup
Process isolation
🔹 Where used?
Run applications
Microservices
Batch jobs
🔹 How implemented?
docker run -d -p 8080:80 nginx
docker ps
C. Docker Layers
🔹 What is it?
Images are built in layers, each instruction adds a new layer.
🔹 Why layers?
Faster builds (cache)
Reuse
Smaller image sizes
🔹 Where used?
Docker build process
Registry storage
🔹 How implemented?
FROM node:18
COPY . .
RUN npm install
Each line → one layer.
2️⃣ Dockerfile: Build, Tag, Push Cycle
A. Dockerfile
🔹 What is it?
A text file containing instructions to build an image.
🔹 Why use it?
Automation
Reproducibility
CI/CD compatibility
🔹 How implemented?
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]
B. Build
docker build -t myapp:1.0 .
C. Tag
docker tag myapp:1.0 mydockerhubuser/myapp:1.0
D. Push
docker login
docker push mydockerhubuser/myapp:1.0
3️⃣ Container Networking
A. Ports
🔹 What is it?
Ports allow external access to containers.
🔹 Why needed?
Containers are isolated by default.
🔹 How implemented?
docker run -p 8080:80 nginx
Host 8080 → Container 80
B. Container Networking
🔹 What is it?
Docker creates virtual networks.
🔹 Why?
Container-to-container communication
Isolation
🔹 How implemented?
docker network create app-net
docker run --network app-net nginx
Containers can communicate via container name.
C. Health Checks
🔹 What is it?
Checks if container is healthy, not just running.
🔹 Why?
Auto restart
Load balancer decisions
Kubernetes readiness/liveness
🔹 How implemented?
Dockerfile
HEALTHCHECK CMD curl -f http://localhost:80 || exit 1
Runtime
docker inspect --format='{{.State.Health.Status}}'
4️⃣ Container Registries
A. What is a Registry?
A place to store and distribute Docker images.
B. Why use registries?
Centralized storage
CI/CD integration
Version control
C. Popular Registries
Registry
Cloud
Docker Hub
Public
Amazon ECR
AWS
Azure ACR
Azure
Google GCR
GCP
D. How to Push to Each
🔹 Docker Hub
docker login
docker push user/app:tag
.
Comments
Post a Comment