MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Kubernetes Deployment Explained: API Resource, YAML Example, and Use Cases

Fearture of Kubernetes Deployment

  • Replication
  • Controller
  • Versioning
  • Rollout
  • Rollback

Note:
ReplicaSets = Replication+Controller in the Deployment


$ kubectl explain deploy.spec.strategy.type
KIND: Deployment
VERSION: apps/v1

FIELD: type

DESCRIPTION:
Type of deployment. Can be “Recreate” or “RollingUpdate”. Default is
RollingUpdate.


Kubernetes Deployement Strategy

Type of deployment

  • Recreate
  • RollingUpdate

.spec.strategy specifies the strategy used to replace old Pods by new ones. .spec.strategy.type can be “Recreate” or “RollingUpdate”. “RollingUpdate” is the default value

Recreate Deployment

All existing Pods are killed before new ones are created when .spec.strategy.type==Recreate.

This will only guarantee Pod termination previous to creation for upgrades. If you upgrade a Deployment, all Pods of the old revision will be terminated immediately. Successful removal is awaited before any Pod of the new revision is created. If you manually delete a Pod, the lifecycle is controlled by the ReplicaSet and the replacement will be created immediately (even if the old Pod is still in a Terminating state). If you need an “at most” guarantee for your Pods, you should consider using a StatefulSet.

Diagram of a load balancer moving traffic from v1.1 Pods to v1.2 Pods one at a time
Recreate strategy diagram: all v1.1 Pods are terminated before v1.2 Pods start behind the load balancer
Recreate deployment diagram: v1 Pods stop, a period with no Pods follows, then v2 Pods start

Rolling Update Deployment

The advantage of the rolling update strategy is that the update is applied Pod-by-Pod so the greater system can remain active.

There is a minor performance reduction during this update process because the system is consistently one active Pod short of the desired number of Pods. This is often much preferred to a full system deactivation.

The rolling update strategy is used as the default update strategy but isn’t suited for all situations.

Ramped rolling update diagram: v1.1 Pods are replaced one by one with v1.2 Pods behind a load balancer
Rolling update diagram: Deployment shifts Pods from the old ReplicaSet to the new one in stages

The Deployment updates Pods in a rolling update fashion when .spec.strategy.type==RollingUpdate. You can specify maxUnavailable and maxSurge to control the rolling update process.

   maxSurge     <string>
     The maximum number of pods that can be scheduled above the desired number
     of pods. Value can be an absolute number (ex: 5) or a percentage of desired
     pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number
     is calculated from percentage by rounding up. Defaults to 25%. Example:
     when this is set to 30%, the new ReplicaSet can be scaled up immediately
     when the rolling update starts, such that the total number of old and new
     pods do not exceed 130% of desired pods. Once old pods have been killed,
     new ReplicaSet can be scaled up further, ensuring that total number of pods
     running at any time during the update is at most 130% of desired pods.

   maxUnavailable       <string>
     The maximum number of pods that can be unavailable during the update. Value
     can be an absolute number (ex: 5) or a percentage of desired pods (ex:
     10%). Absolute number is calculated from percentage by rounding down. This
     can not be 0 if MaxSurge is 0. Defaults to 25%. Example: when this is set
     to 30%, the old ReplicaSet can be scaled down to 70% of desired pods
     immediately when the rolling update starts. Once new pods are ready, old
     ReplicaSet can be scaled down further, followed by scaling up the new
     ReplicaSet, ensuring that the total number of pods available at all times
     during the update is at least 70% of desired pods.Code language: PHP (php)

kubernetes deployment strategy example: Recreate


apiVersion: apps/v1  
kind: Deployment
metadata:
  name: hello-deploy
spec:
  replicas: 10
  selector:
    matchLabels:
      app: hello-world
  minReadySeconds: 10
  strategy:
    type: Recreate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-Pod
        image: scmgalaxy/nginx-devopsschoolv1
        ports:
        - containerPort: 80

kubernetes deployment strategy example: Rollingupdate


apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 5
  selector:
    matchLabels:
      app: helloworld
  template:
    metadata:
      labels:
        app: helloworld
        track: stable
    spec:
      containers:
      - name: helloworld
        image: scmgalaxy/nginx-devopsschoolv1
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: 50m
          limits:
            cpu: 100m

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Kubernetes Job & CronJob Explained: API Resource, YAML Example, and Use Cases

Kubernetes Jobs and CronJobs Explained with Examples: Complete Hands-on Guide for DevOps Engineer Keywords 1. Introduction In Kubernetes, not every workload is a long-running application like a…

Read More

Kubernetes PersistentVolume, PersistentVolumeClaim, volume using hostPath

pv.yaml $ kubectl create -f pv.yaml $ kubectl get pv pvc.yaml $ kubectl create -f pvc.yaml $ kubectl get pvc pod.yaml Rajesh Kumar I’m Rajesh Kumar, a…

Read More

Kubernetes Service Example Programs

Here’s a complete YAML file that contains three Deployments and their corresponding Services: Each container runs on port 80. ✅ Full Kubernetes YAML (deployment-and-services.yaml) 🚀 Usage To…

Read More

Openshift Tutorials for DeploymentConfigs

OpenShift DeploymentConfigs are a core resource in OpenShift used to manage the deployment and lifecycle of applications. While Kubernetes uses Deployments to manage the rolling updates of…

Read More

Kubernetes Tutorials: How to modify CHANGE-CAUSE in Deployment revision

Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have…

Read More

Helm Lab – 4: Creating and Packaging a Helm Chart

Windows Commands Linux Commands Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry…

Read More