Chapter 1.5 - Fundamental Concepts
Learning Objectives
By the end of this chapter, you will be able to:
- Understand what a Pod is
- Explain the role of a Deployment
- Understand Services and their types
- Use Namespaces for organization
Introduction
Kubernetes uses several fundamental concepts that you will use constantly. This chapter presents the most important ones: Pods, Deployments, Services, and Namespaces.
Pods: The Atomic Unit
Definition
A Pod is the smallest deployable unit in Kubernetes.
Pod Characteristics
Key points:
- One Pod = 1 or more containers
- Containers in a Pod share:
- IP address
- Volumes
- Network namespace
- Pods are ephemeral (can be recreated)
Pod Example
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
Deployments: Lifecycle Management
Definition
A Deployment describes the desired state of your application.
Deployment Features
Advantages:
- Manages replicas automatically
- Rolling updates (without interruption)
- Rollback in case of issues
- Self-healing
Deployment Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
Services: Application Exposure
Definition
A Service exposes a set of Pods as a stable network service.
Problem solved:
- Pods have ephemeral IPs
- Pods can be recreated
- How to maintain a stable address?
Solution: The Service provides a stable IP and a DNS name
Service Types
1. ClusterIP (Default)
- Internal service within the cluster
- Accessible only from within the cluster
- Uses internal DNS
2. NodePort
- Exposed on a port (30000-32767) of each node
- Accessible from outside
- Unique port on all nodes
3. LoadBalancer
- Exposed via a cloud load balancer
- Automatic public IP
- Available on AWS, Azure, GCP
Service Example
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30080
Namespaces: Logical Isolation
Definition
Namespaces allow you to divide a cluster into multiple virtual environments.
Namespace Advantages
Use cases:
- Separate dev/staging/prod
- Isolate teams
- Manage resource quotas
- Apply security policies
Default Namespaces
Kubernetes creates several namespaces by default:
- default: Default namespace for your resources
- kube-system: Kubernetes system components
- kube-public: Public resources
- kube-node-lease: Node heartbeats
Usage Example
# Create a namespace
kubectl create namespace production
# Deploy in a namespace
kubectl apply -f deployment.yaml -n production
# List pods in a namespace
kubectl get pods -n production
Relationships Between Concepts
Overview
Hierarchy:
- Namespace: Contains everything
- Deployment: Manages Pods
- ReplicaSet: Maintains the number of replicas
- Pods: Run the containers
- Service: Exposes the Pods
Chapter Summary
In this chapter, you learned:
Pod: Smallest deployable unit, 1+ containers
Deployment: Manages lifecycle, replicas, updates
Service: Exposes Pods with a stable IP
Service Types: ClusterIP, NodePort, LoadBalancer
Namespaces: Logical isolation, organization
Relationships: Namespace -> Deployment -> Pods -> Service
Next Steps
Now that you have mastered the fundamental concepts:
Lab 1.1: First Deployment (hands-on practice)
Quiz Module 1: Validate your knowledge
Chapter created: December 2024