☁️ Cloud

Kubernetes

Kubernetes (K8s)

A container orchestration platform. Developed by Google. Provides automated deployment, scaling, and recovery.

📖 Detailed Explanation

Kubernetes (K8s) is a portable, extensible open-source platform for managing containerized workloads and services. Google open-sourced it in 2014, drawing on more than 15 years of experience running production workloads.

The core components of K8s are the control plane (API Server, etcd, Scheduler, Controller Manager) and worker nodes (kubelet, kube-proxy, Container Runtime). When you define the desired state through declarative configuration, K8s automatically reconciles the current state to the desired state.

A Pod is the smallest deployable unit in K8s and contains one or more containers. A Deployment manages the number of Pod replicas and the update strategy, and a Service provides a stable network endpoint for a set of Pods.

It simplifies operating large-scale distributed systems by providing features such as autoscaling (HPA, VPA, Cluster Autoscaler), self-healing, rolling updates, service discovery, and load balancing.

💻 Code Example

# Deployment: 애플리케이션 배포
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: my-app:v1.0.0
          ports:
            - containerPort: 8080
          resources:
            requests:
              cpu: "100m"
              memory: "128Mi"
            limits:
              cpu: "500m"
              memory: "512Mi"
          livenessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 30
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /ready
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 5

---
# Service: 네트워크 엔드포인트
apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  selector:
    app: my-app
  ports:
    - port: 80
      targetPort: 8080
  type: ClusterIP

---
# HPA: 자동 스케일링
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: my-app-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-app
  minReplicas: 3
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70

🗣️ How It's Said in Practice

DevOps: "We need to upgrade the K8s cluster this time, from 1.28 to 1.29. I'll do it as a rolling upgrade, draining nodes as I go."

Dev team: "Will there be service downtime?"

DevOps: "No, a PodDisruptionBudget is set, so the minimum replicas are maintained. Traffic switching is automatic too."

Interviewer: "In Kubernetes, how is a Pod recovered when it dies?"

Candidate: "The Deployment's ReplicaSet maintains the desired number of Pods. The kubelet monitors container status and restarts the container when the livenessProbe fails. Pod-level failures are detected by the controller, which schedules a new Pod."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

Reviewer: "The resources section has only limits and no requests. Without requests, the limits value is set as the requests, which can affect scheduling."

Author: "Oh, I'll set requests to about 50% of limits."

⚠️ Cautions

📚 Learn More