Skip to main content

Deployment / ReplicaSet

Pod Icon Pod Icon



Architecture

ex_service.png


Detailed Description

Kubernetes Deployments are designed to manage stateless services in your cluster and are designed to define the desired state of your application. The Desired State describes how your application should look in Kubernetes. You tell Kubernetes:

  • How many Pods should be running?
  • Which container image should be used?
  • What configurations (e.g., environment variables, ports) should be applied?

A Deployment ensures that the actual state in the cluster matches the desired state. For example, if a Pod crashes, Kubernetes automatically creates a new one to maintain the desired state.

Key Features

  • Rollbacks: Revert to a previous version during an update issue using kubectl rollout undo.
  • Rolling Updates: Smooth transitions between versions, supported by:
    • maxSurge: Temporary increase in Pods during updates (e.g., 25%).
    • maxUnavailable: Allowable percentage of Pods down during updates (e.g., 25%).
  • Scaling: Adjust replica counts with kubectl scale.
  • Monitoring Updates: Use kubectl rollout status to track rollout progress.

Command Reference Guide

Remeber to use dry-run and tee to check the configuration of each command first.
--dry-run=client -o yaml | tee nginx-deployment.yaml

# Create nginx deployment with the default of one replica
kubectl create deployment nginx --image=nginxdemos/hello --port=80

# Create nginx deployment with three replicas
kubectl create deployment nginx --image=nginxdemos/hello --port=80  --replicas=3




# Expose application as ClusterIP with port 8080 (ClusterIP is the default if not defined)
kubectl expose deployment nginx --type=ClusterIP --port=8080 --target-port=80
# --port=8080: The port exposed by the service (used internally to access the deployment)
# --target-port=80: The port on the pods where the application is running

# Get services
kubectl get service nginx -o wide

# Get full resource description using describe
kubectl describe service/nginx

# Get created endpoints
kubectl get endpoints

# curl by default service DNS entry
# Each curl request gets a different hostname due to Kubernetes' Kube-Proxy load balancing
curl nginx.default.svc.cluster.local

# Delete service
kubectl delete service/nginx

Hints

Deployments manage ReplicaSets, primarily due to historical reasons. There is no practical need to manually create ReplicaSets anymore, as Deployments provide a more user-friendly and feature-rich abstraction for managing application lifecycle, including replication, updates, and rollbacks.


Open questions

./.


My personal summary

./.