Deployment

A Deployment is a higher-level controller that manages stateless ReplicaSets.

It provides declarative updates to applications (e.g., rolling updates, rollbacks)

When you create a Deployment:

  • It creates a ReplicaSet

  • ReplicaSet creates Pods

If you change your Deployment (e.g., new image version), Kubernetes will:

  • Create a new ReplicaSet

  • Slowly scale down the old one and scale up the new one (rolling update).

After a re-deployment, old replicatsets are not deleted, in case there is a need to regress to them.

Why Deployments exist?

To enable:

  • Zero-downtime upgrades

  • Rollbacks

  • History tracking

  • Scaling apps easily

Why Deployments are stateless?

  1. Pods are ephemeral

    • Pods managed by a Deployment can be killed, restarted, rescheduled anytime.

    • They may come up on a different node with a new IP and hostname.

    • If they stored important data inside their filesystem → that data would be lost.


  1. ReplicaSets scale dynamically

    • Deployments create ReplicaSets, which spin up/destroy Pods dynamically.

    • When you scale up, new Pods appear on random nodes.

    • When you scale down, Pods are deleted (with their data).


  1. Rolling updates replace Pods

    • During upgrades, old Pods are terminated and replaced with new ones.

    • If Pods held data locally, you’d lose it every time you update your Deployment.


  1. Networking & identity are not stable

    • Pods in a Deployment get random names and IPs (myapp-7d9c8c9c7f-abc12).

    • They are interchangeable — meaning Kubernetes treats them as identical, stateless workers.

Commands

To apply and run a Deployment configuration:

To list the Deployments:

To describe a Deployment:

To delete a Deployment:

To update image through the CLI:

To get the rollout history of Deployments:

To rollback a Deployment to a previous version:

To scale Deployments:

Check consumption of a Deployment:

Example

Limiting Resources

Also make sure that the sum of limits resources for all Pods don't exceed the available server resources, to be more conservative.

Or to be more agressive or economic you can "overbook" limits at the risk of some Pods failing if they all start reach limits.

Create a pod with resource requests and limits at both pod-level and container-level

Last updated