Skip to content

Files

Latest commit

 

History

History
55 lines (43 loc) · 2.6 KB

03-k8s-deployment.md

File metadata and controls

55 lines (43 loc) · 2.6 KB

Kubernetes Deployment

What is a Kubernetes Deployment?

A Kubernetes Deployment is a resource object in Kubernetes that provides declarative updates to applications. It allows you to describe an application’s life cycle, such as which images to use for the app, the number of pod replicas, and the update strategy. Deployments manage the creation and scaling of pods, ensuring that the desired state of the application is maintained.

Kubernetes Deployment vs. Docker Container

Kubernetes Deployment

  • Declarative Management: You define the desired state of your application, and Kubernetes ensures that the current state matches the desired state.
  • Scaling: Easily scale the number of pod replicas up or down.
  • Self-Healing: Automatically replaces failed or deleted pods to maintain the desired number of replicas.
  • Rolling Updates: Update applications without downtime by gradually replacing old pods with new ones.

Docker Container

  • Imperative Management: You manually start, stop, and manage containers.
  • Scaling: Requires manual intervention or additional tools to scale containers.
  • Self-Healing: No built-in self-healing; requires external tools or scripts to handle failures.
  • Updates: Updating containers often involves stopping the old container and starting a new one, which can lead to downtime.

Scaling and Healing in Kubernetes

Scaling

Kubernetes Deployments make scaling applications straightforward. You can scale the number of pod replicas by updating the deployment configuration. Kubernetes will automatically create or remove pods to match the desired replica count.

apiVersion: apps/v1
kind: Deployment
metadata:
    name: my-app
spec:
    replicas: 3
    selector:
        matchLabels:
            app: my-app
    template:
        metadata:
            labels:
                app: my-app
        spec:
            containers:
            - name: my-app-container
                image: my-app-image:latest

Self-Healing

Kubernetes ensures that the desired state of the application is maintained. If a pod is deleted or fails, the Deployment controller will automatically create a new pod to replace it, ensuring that the specified number of replicas is always running.

kubectl delete pod <pod-name>

After deleting a pod, Kubernetes will detect the discrepancy and create a new pod to maintain the desired state.

In summary, Kubernetes Deployments provide a robust way to manage applications, offering features like declarative management, scaling, self-healing, and rolling updates, which are not inherently available in Docker containers.