Skip to main content

Kubernetes Fundamentals - From Zero to Hero

· 2 min read
Goel Academy
DevOps & Cloud Learning Hub

Kubernetes (K8s) is an open-source container orchestration platform that automates deployment, scaling, and management of containerized applications.

Why Kubernetes?

  • Self-healing - Restarts failed containers automatically
  • Horizontal scaling - Scale applications up or down easily
  • Service discovery - Built-in DNS and load balancing
  • Automated rollouts - Zero-downtime deployments
  • Secret management - Secure handling of sensitive data

Core Concepts

1. Pods

The smallest deployable unit in Kubernetes:

apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.21
ports:
- containerPort: 80
resources:
limits:
memory: "128Mi"
cpu: "500m"

2. Deployments

Manage the desired state of your pods:

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.21
ports:
- containerPort: 80

3. Services

Expose your applications:

apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- port: 80
targetPort: 80

Essential kubectl Commands

# Get cluster info
kubectl cluster-info

# List all pods
kubectl get pods -A

# Describe a pod
kubectl describe pod nginx-pod

# View logs
kubectl logs nginx-pod

# Execute command in pod
kubectl exec -it nginx-pod -- /bin/bash

# Apply configuration
kubectl apply -f deployment.yaml

# Scale deployment
kubectl scale deployment nginx-deployment --replicas=5

ConfigMaps and Secrets

# ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
DATABASE_URL: "postgres://db:5432"
LOG_LEVEL: "info"

---
# Secret
apiVersion: v1
kind: Secret
metadata:
name: app-secrets
type: Opaque
data:
password: cGFzc3dvcmQxMjM= # base64 encoded

Best Practices

  1. Use namespaces to organize resources
  2. Set resource limits on all containers
  3. Use liveness and readiness probes
  4. Implement RBAC for security
  5. Use Helm for package management

Coming next: Advanced Kubernetes patterns with Helm and Operators!