☸️ Kubernetes Introduction
Learn the fundamentals of Kubernetes (K8s) - the industry-standard container orchestration platform.
What is Kubernetes?
Kubernetes is an open-source container orchestration system for automating deployment, scaling, and management of containerized applications.
Core Concepts
Pod
The smallest deployable unit in Kubernetes. A pod can contain one or more containers.
Deployment
Manages the desired state of your pods, handling updates and rollbacks.
Service
Exposes your pods to network traffic, either internally or externally.
Namespace
Provides logical isolation between resources in a cluster.
Architecture Overview
┌─────────────────────────────────────────────────────┐
│ Control Plane │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌──────────┐ │
│ │ API │ │ etcd │ │Scheduler│ │Controller│ │
│ │ Server │ │ │ │ │ │ Manager │ │
│ └─────────┘ └─────────┘ └─────────┘ └──────────┘ │
└─────────────────────────────────────────────────────┘
│
┌─────────────────────┼─────────────────────┐
│ │ │
┌───▼───┐ ┌─────▼─────┐ ┌─────▼─────┐
│ Node 1│ │ Node 2 │ │ Node 3 │
│┌─────┐│ │ ┌───────┐ │ │ ┌───────┐ │
││ Pod ││ │ │ Pod │ │ │ │ Pod │ │
│└─────┘│ │ └───────┘ │ │ └───────┘ │
└───────┘ └───────────┘ └───────────┘Creating Resources
Deployment YAML
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
labels:
app: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:v1
ports:
- containerPort: 3000
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "500m"Service YAML
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancerEssential kubectl Commands
# Apply configuration
kubectl apply -f deployment.yaml
# Get resources
kubectl get pods
kubectl get deployments
kubectl get services
# Describe resource
kubectl describe pod myapp-xxxxx
# View logs
kubectl logs -f myapp-xxxxx
# Execute command in pod
kubectl exec -it myapp-xxxxx -- /bin/sh
# Scale deployment
kubectl scale deployment myapp --replicas=5
# Delete resources
kubectl delete -f deployment.yamlQuick Reference Table
| Resource | Short Name | Description |
|---|---|---|
| Pod | po | Smallest deployable unit |
| Deployment | deploy | Manages pod replicas |
| Service | svc | Network endpoint |
| ConfigMap | cm | Configuration data |
| Secret | secret | Sensitive data |
| Ingress | ing | HTTP routing |
| Namespace | ns | Resource isolation |
🎯 Pro Tip: Use
kubectl explain <resource>to get documentation about any resource type.