Kubernetes Documentation

Container Orchestration - Kubernetes automates deployment, scaling, and management of containerized applications.

What is Kubernetes?

Kubernetes (often abbreviated as K8s) is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation (CNCF).

Key Features

  • 🚀 Automated Deployment - Roll out changes with zero downtime
  • 📈 Auto-scaling - Scale applications based on demand
  • 💪 Self-healing - Automatically restart failed containers
  • 🔧 Load Balancing - Distribute traffic across containers
  • 💾 Storage Management - Persistent storage for containers
  • 🔐 Secret Management - Secure configuration and credentials

Architecture Overview

Control Plane (Master Node)

API Server

The front-end for Kubernetes control plane. Handles all REST operations.

etcd

Consistent and highly-available key-value store for cluster state and configuration.

Scheduler

Assigns Pods to Nodes based on resource availability and constraints.

Controller Manager

Runs controller processes that regulate cluster state (replication, endpoints, etc.)

Worker Nodes

kubelet

Agent that runs on each node and ensures containers are running in Pods.

kube-proxy

Network proxy that maintains network rules on nodes and enables communication.

Container Runtime

Software responsible for running containers (Docker, containerd, CRI-O).

Installation

Using Minikube (Local Development)

# Install Minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

# Start Minikube
minikube start

# Verify installation
kubectl get nodes

Install kubectl

# Linux
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

# macOS
brew install kubectl

# Verify installation
kubectl version --client

Using Docker Desktop

Docker Desktop includes Kubernetes. Enable it in Settings → Kubernetes.

Essential kubectl Commands

Cluster Information

# Get cluster info
kubectl cluster-info

# Get nodes
kubectl get nodes

# Get all resources
kubectl get all

# Describe a node
kubectl describe node <node-name>

Pods

# List pods
kubectl get pods

# List pods in all namespaces
kubectl get pods -A

# Get pods with more details
kubectl get pods -o wide

# Describe a pod
kubectl describe pod <pod-name>

# Get pod logs
kubectl logs <pod-name>

# Follow logs
kubectl logs -f <pod-name>

# Execute command in pod
kubectl exec -it <pod-name> -- sh

# Delete pod
kubectl delete pod <pod-name>

Deployments

# List deployments
kubectl get deployments

# Create deployment
kubectl create deployment nginx --image=nginx:latest

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

# Update deployment image
kubectl set image deployment/nginx nginx=nginx:1.21

# Rollout status
kubectl rollout status deployment/nginx

# Rollback deployment
kubectl rollout undo deployment/nginx

# Delete deployment
kubectl delete deployment nginx

Services

# List services
kubectl get services

# Create service
kubectl expose deployment nginx --port=80 --type=LoadBalancer

# Get service details
kubectl describe service <service-name>

# Port forward to local machine
kubectl port-forward service/nginx 8080:80

Namespaces

# List namespaces
kubectl get namespaces

# Create namespace
kubectl create namespace production

# Get resources in namespace
kubectl get pods -n production

# Set default namespace
kubectl config set-context --current --namespace=production

Quick Start Example

Deploy a simple Nginx application:

1. Create a Deployment

kubectl create deployment nginx-app --image=nginx:latest

2. Expose as Service

kubectl expose deployment nginx-app --port=80 --type=LoadBalancer

3. Check Status

# Get pods
kubectl get pods

# Get services
kubectl get services

# Access the service (Minikube)
minikube service nginx-app

YAML Configuration

Deploy using YAML files (declarative approach):

Deployment Example

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.21
        ports:
        - containerPort: 80

Service Example

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: LoadBalancer
💡 Tip: Use kubectl apply -f filename.yaml to create/update resources from YAML files.

Core Concepts

Understanding key Kubernetes objects:

  • Pods - Smallest deployable units containing one or more containers
  • Deployments - Manages ReplicaSets and provides declarative updates
  • Services - Exposes Pods to network traffic
  • ConfigMaps - Stores configuration data
  • Secrets - Stores sensitive data (passwords, tokens)
  • Volumes - Persistent storage for containers
  • Namespaces - Virtual clusters within a physical cluster

Next Steps

Continue learning with our detailed guides: