Kubernetes Deployment Guide for Beginners: Building a K8s Cluster from Scratch

Kubernetes (K8s) is the de facto standard for container orchestration and has become the "operating system" of the cloud-native era.

1. Core Concepts

Concept Description
Pod Smallest deployable unit, contains one or more containers
Service Network abstraction layer, provides stable access endpoint
Deployment Declarative Pod management
Namespace Resource isolation grouping
ConfigMap Configuration management
Secret Sensitive information management

2. Local Setup (Minikube)

# Install minikube
brew install minikube

# Start cluster
minikube start --cpus 4 --memory 8192

# Check status
kubectl cluster-info
kubectl get nodes

3. Deploying an Application

# deployment.yaml
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:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - port: 80
    targetPort: 80
  type: NodePort
kubectl apply -f deployment.yaml
kubectl get pods
kubectl get services
minikube service nginx-service

4. Common Commands

kubectl get pods                 # View Pods
kubectl get deployments          # View Deployments
kubectl logs pod-name           # View logs
kubectl exec -it pod-name -- sh # Enter container
kubectl describe pod pod-name   # View details
kubectl scale deployment nginx --replicas=5  # Scale

5. Production Recommendations

  • Use managed K8s services (EKS, AKS, GKE)
  • Configure resource requests and limits
  • Set up HPA for auto-scaling
  • Use Helm for application release management