> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Convert K8S Deployments to Rollout

> Guide to converting a Kubernetes Deployment into an Argo Rollout using workloadRef, enabling blue green or canary strategies and controlling original Deployment scale down behavior

In this lesson we'll convert an existing Kubernetes Deployment into an Argo Rollout so the Argo Rollouts controller can manage lifecycle and rollout strategy (for example, blue/green or canary). This approach lets you adopt an existing Deployment without rewriting the pod template by using workloadRef.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/v7HW2PPNQOGxY8Ve/images/Prep-Course-Certified-Argo-Project-Associate-CAPA/Argo-Rollouts/Demo-Convert-K8S-Deployments-to-Rollout/blue-gradient-k8s-deployment-rollout-slide.jpg?fit=max&auto=format&n=v7HW2PPNQOGxY8Ve&q=85&s=770be1c3ccbb81d99b462015a3dac88b" alt="A blue-gradient presentation slide with the centered title &#x22;K8S Deployment to Rollout.&#x22; Small copyright text &#x22;Copyright KodeKloud&#x22; appears in the lower-left corner." width="1920" height="1080" data-path="images/Prep-Course-Certified-Argo-Project-Associate-CAPA/Argo-Rollouts/Demo-Convert-K8S-Deployments-to-Rollout/blue-gradient-k8s-deployment-rollout-slide.jpg" />
</Frame>

Overview

* Replace the Deployment kind with an argoproj.io/v1alpha1 Rollout so Argo Rollouts manages the resource.
* Use spec.workloadRef to point the Rollout to an existing Deployment (no pod-template rewrite needed).
* Configure spec.workloadRef.scaleDown to control what happens to the original Deployment after the Rollout succeeds.
* Choose a rollout strategy; this example uses blueGreen and requires activeService (previewService is optional).

Key parts explained

| Field                      | Purpose                                                                                  | Example / Notes                                                      |
| -------------------------- | ---------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| apiVersion / kind          | Instructs Kubernetes to treat this as an Argo Rollout managed resource                   | `argoproj.io/v1alpha1 / Rollout`                                     |
| spec.replicas              | Number of desired replicas for the Rollout                                               | Same concept as Deployment                                           |
| spec.workloadRef           | Adopts an existing Deployment so the Rollout uses the same pod template                  | `apiVersion: apps/v1`, `kind: Deployment`, `name: <deployment-name>` |
| spec.workloadRef.scaleDown | Policy to control scaling behavior of the original Deployment after successful rollout   | `onSuccess`, `never`, `progressive` (see table below)                |
| spec.strategy.blueGreen    | Blue/green rollout configuration; `activeService` is required, `previewService` optional | Provides traffic promotion and internal preview testing              |

scaleDown option summary

| Option      | Behavior                                                                               |
| ----------- | -------------------------------------------------------------------------------------- |
| onSuccess   | Controller scales the original Deployment to zero after the Rollout becomes healthy.   |
| never       | Controller does not scale down the original Deployment. Use when you want both to run. |
| progressive | Controller gradually scales down the original Deployment alongside the Rollout.        |

Example Rollout manifest

* This manifest adopts an existing Deployment named `highway-animation-1` and performs a blue/green rollout using `activeService` and `previewService`.

```yaml theme={null}
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: highway-animation-rollout
  namespace: beta
spec:
  replicas: 4
  workloadRef:
    apiVersion: apps/v1
    kind: Deployment
    name: highway-animation-1
    scaleDown: onSuccess
  strategy:
    blueGreen:
      activeService: highway-bluegreen-active
      previewService: highway-bluegreen-preview
```

What happens when you apply this

* The Rollout resource takes control of the specified Deployment (it "adopts" it).
* The Rollout controller will create new ReplicaSets/Pods for the rollout while the original Deployment pods remain until scaleDown policy executes.
* With `scaleDown: onSuccess`, when the Rollout becomes healthy the controller scales the original Deployment to zero, leaving the Rollout-managed pods servicing traffic.

Apply the Rollout and observe the cluster

1. Initial state (plain Deployment running four replicas):

```bash theme={null}
# Initial state: existing deployment running 4 replicas
kubectl -n beta get pods,deploy
NAME                                          READY   STATUS    RESTARTS   AGE
pod/highway-animation-1-77dd97f459-65rm8      1/1     Running   0          4h13m
pod/highway-animation-1-77dd97f459-9dhpq      1/1     Running   0          4h13m
pod/highway-animation-1-77dd97f459-gksf2      1/1     Running   0          4h13m
pod/highway-animation-1-77dd97f459-lbf8w      1/1     Running   0          4h13m

NAME                                         READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/highway-animation-1          4/4     4            4           4h13m
```

2. Apply the Rollout manifest (example uses a public gist). This creates the Rollout and the blue/green services:

```bash theme={null}
kubectl -n beta apply -f https://gist.github.com/sidd-harth/5dedab96d94373e4f1f1317f33d3781f/raw/dcf228b4e2e8b12c912fb4f1fbb3f858e435fd0f/rollout-1-demo.yml
# Expected output:
# rollout.argoproj.io/highway-animation-rollout created
# service/highway-bluegreen-active created
# service/highway-bluegreen-preview created
```

3. After applying, new Rollout-managed pods will be created while the original Deployment pods continue running until the rollout completes:

```bash theme={null}
kubectl -n beta get pods,deploy
NAME                                               READY   STATUS             RESTARTS   AGE
pod/highway-animation-1-77dd97f459-65rm8           1/1     Running            0          4h19m
pod/highway-animation-1-77dd97f459-9dhpq           1/1     Running            0          4h19m
pod/highway-animation-1-77dd97f459-gksf2           1/1     Running            0          4h19m
pod/highway-animation-1-77dd97f459-lbf8w           1/1     Running            0          4h19m
pod/highway-animation-rollout-5f9c6d59f-m6fxg      0/1     ContainerCreating  0          3s
pod/highway-animation-rollout-5f9c6d59f-nq44x      0/1     Pending            0          2s
pod/highway-animation-rollout-5f9c6d59f-pmls4      0/1     Pending            0          2s
pod/highway-animation-rollout-5f9c6d59f-qcxb4      0/1     Pending            0          2s

NAME                                              READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/highway-animation-1               4/4     4            4           4h19m
```

4. When the Rollout becomes healthy, Rollout pods will reach Running and the original Deployment pods are terminated according to the scaleDown policy:

```bash theme={null}
kubectl -n beta get pods,deploy
NAME                                               READY   STATUS        RESTARTS   AGE
pod/highway-animation-1-77dd97f459-65rm8           1/1     Terminating   0          4h20m
pod/highway-animation-1-77dd97f459-9dhpq           1/1     Terminating   0          4h20m
pod/highway-animation-1-77dd97f459-gksf2           1/1     Terminating   0          4h20m
pod/highway-animation-1-77dd97f459-lbf8w           1/1     Terminating   0          4h20m
pod/highway-animation-rollout-5f9c6d59f-m6fxg      1/1     Running       0          53s
pod/highway-animation-rollout-5f9c6d59f-nq44x      1/1     Running       0          52s
pod/highway-animation-rollout-5f9c6d59f-pmls4      1/1     Running       0          52s
pod/highway-animation-rollout-5f9c6d59f-qcxb4      1/1     Running       0          52s
```

At this point the Rollout resource controls the application; the original Deployment has been scaled down according to the scaleDown policy, and the blue/green services allow controlled traffic promotion and preview testing.

<Callout icon="lightbulb" color="#1CB2FE">
  Note: Using workloadRef allows you to convert an existing Deployment to be managed by Argo Rollouts without rewriting the pod template. Review the available scaleDown options (onSuccess, never, progressive) to choose the behavior that suits your release workflow.
</Callout>

Links and references

* Argo Rollouts documentation: [https://argoproj.github.io/argo-rollouts/](https://argoproj.github.io/argo-rollouts/)
* Kubernetes Deployments: [https://kubernetes.io/docs/concepts/workloads/controllers/deployment/](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
* Example manifest used in this demo: [https://gist.github.com/sidd-harth/5dedab96d94373e4f1f1317f33d3781f](https://gist.github.com/sidd-harth/5dedab96d94373e4f1f1317f33d3781f)

That's all for now.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/certified-argo-project-associate-capa/module/959dfde0-9415-4fc2-bcad-fe9e4bf84cc7/lesson/196ad805-5a18-4575-b30f-21fe0f0cb005" />
</CardGroup>
