# Part 3: Workload

## What Will You Do

In this part of the self-paced exercise, you will deploy a stateless workload to both clusters. The stateless workload will be used to demonstrate the ability to keep an application available by means of the blue-green upgrade strategy.

---

## Step 1: Deploy Workload

In this step, you will create a stateless workload on the clusters. The workload will be used to show how the blue-green upgrade strategy can be applied with no disruption to the stateless cluster applications.

- Save the below specification file to your computer as "workload-spec.yaml". Note, the highlighted sections in the spec will need to be updated to match your environment.

```
name: stateless-workload
namespace: default
project: defaultproject
type: NativeYaml
clusters: blue,green
payload: stateless-workload.yaml
```

- Save the below specification file to your computer as "stateless-workload.yaml".

```
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: default
  name: deployment-2048
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: app-2048
  replicas: 5
  template:
    metadata:
      labels:
        app.kubernetes.io/name: app-2048
    spec:
      containers:
      - image: public.ecr.aws/l6m2t8p7/docker-2048:latest
        imagePullPolicy: Always
        name: app-2048
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  namespace: default
  name: service-2048
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: LoadBalancer
  selector:
    app.kubernetes.io/name: app-2048
```

- Open Terminal (on macOS/Linux) or Command Prompt (Windows) and navigate to the folder where you saved the files
- Execute the following command to provision the cluster from the specification file previously saved

```
rctl create workload workload-spec.yaml
```

If there were no errors, you should see a message like below

```
Workload created successfully
```

- Login to the web console
- Navigate to your project
- Select Applications -> Workloads

Now, let us publish the newly created workload to the EKS clusters. The workload can be deployed to multiple clusters as per the configured "placement policy". In this case, you are deploying to a single EKS cluster with the name "karpenter-cluster".

```
rctl publish workload stateless-workload
```

In the web console, click on Applications -> Workloads. You should see something like the following.

---

## Step 2: Access Blue Workload

In this step, we will access the workload on the **_blue_** cluster to ensure it is working.

- Navigate to Infrastructure -> Clusters
- Click on "KUBECTL" in the cluster card of the **_blue_** cluster
- Enter the below command

```
kubectl get services -n default service-2048
```

- You should see a result like the following showing the inflate deployment with 0 pods running.

```
NAME           TYPE           CLUSTER-IP       EXTERNAL-IP                                                               PORT(S)        AGE
service-2048   LoadBalancer   10.100.139.203   a359df9b63fc84d3797397f23db718c3-2075536630.us-west-2.elb.amazonaws.com   80:32518/TCP   10s
```

- Configure your DNS to point to the **_EXTERNAL-IP_**
- In your web browser, navigate to the DNS entry previously created

We are currently able to access the stateless workload running on the **_blue_** cluster.

---

## Step 3: Access Green Workload

In this step, we will access the workload on the **_green_** cluster to ensure it is working.

- Navigate to Infrastructure -> Clusters
- Click on "KUBECTL" in the cluster card of the **_green_** cluster
- Enter the below command

```
kubectl get services -n default service-2048
```

- You should see a result like the following showing the inflate deployment with 0 pods running.

```
NAME           TYPE           CLUSTER-IP      EXTERNAL-IP                                                              PORT(S)        AGE
service-2048   LoadBalancer   10.100.22.204   a18c021ac258f4fcfb1950184a832c7a-465706458.us-west-2.elb.amazonaws.com   80:32370/TCP   11m
```

- In your web browser, navigate to the **_EXTERNAL-IP_**

We are currently able to access the stateless workload running on the **_green_** cluster.

---

## Step 4: Redirect Traffic

Now that we know that the stateless workload is running on the **_green_** cluster with the newer version of Kubernetes, we will update our DNS to redirect traffic to the **_EXTERNAL-IP_** of the **_green_** cluster.

- Configure your DNS to point to the **_EXTERNAL-IP_** of the **_green_** cluster
- In your web browser, navigate to the DNS entry

We are now accessing the stateless workload running on the **_green_** cluster with no disruption to the end user.

---

## Recap

Congratulations! At this point, you have successfully applied the blue-green upgrade strategy to a cluster running stateless workloads.
