|
| 1 | +# 🚀 **Module 4: Creating and Deploying Your First Serverless Function** |
| 2 | + |
| 3 | +**Technology Stack:** |
| 4 | + |
| 5 | +- Python |
| 6 | +- Serverless |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## 🎯 **Scenario** |
| 11 | + |
| 12 | +Instead of managing servers directly, your applications can scale automatically in response to events, scaling down to zero when idle, which can improve resource efficiency and cost management. In this workspace, you will be required to quickly build an application image, upload it to the internal repository and then load balance it with Red Hat Serverless! |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## 🐾 **Guided Walkthrough** |
| 17 | + |
| 18 | +1. Create a new project/namespace from the openshift ui and name it <username>-serverless |
| 19 | +2. From the openshift UI, start a new terminal |
| 20 | + - 2.1. Type in `oc project` to see which project you have enabled |
| 21 | + - 2.2. Type in `kn` to download the k-native CLI |
| 22 | +3. Create your first Knative service |
| 23 | + |
| 24 | + ```sh |
| 25 | + kn service create module4-helloworld \ |
| 26 | + --image quay.io/pknezevich/module4-dotnet-hellolang \ |
| 27 | + --autoscale-window 20s \ |
| 28 | + --env countryCode=DE |
| 29 | + ``` |
| 30 | + |
| 31 | +4. Verify your service has been created and you can curl/navigate to your application |
| 32 | +5. Tag the revision to **green** |
| 33 | +6. NOTE: we will update with ENV VAR but typically you would use: `kn service update <service-name> --image <new-image>` |
| 34 | + |
| 35 | + ```sh |
| 36 | + kn service update module4-helloworld \ |
| 37 | + --env countryCode=DE \ |
| 38 | + --tag module4-helloworld-00001=blue --untag green \ |
| 39 | + --tag @latest=green \ |
| 40 | + --traffic blue=100,green=0 |
| 41 | + ``` |
| 42 | + |
| 43 | +7. Tag the blue revision to **inactive** |
| 44 | +8. To create a third revision: |
| 45 | + - 8.1. From OC change the tag from `module4-helloworld-00002` green to blue |
| 46 | + - 8.2. Create a new revision |
| 47 | + - 8.2.1. ENV change (quick revision, this is usually done via an image change) |
| 48 | + - 8.2.1.1. Change a **different country code** |
| 49 | + - 8.2.2. Tag the **old revision to blue** |
| 50 | + - 8.2.3. Do not allow any traffic to new revision until you’re ready to (traffic distribution still stays on blue) |
| 51 | + |
| 52 | + ```sh |
| 53 | + kn service update module4-helloworld \ |
| 54 | + --env countryCode=FR \ |
| 55 | + --tag module4-helloworld-00002=blue --untag green \ |
| 56 | + --tag @latest=green \ |
| 57 | + --traffic blue=100,green=0 |
| 58 | + ``` |
| 59 | + |
| 60 | +9. Build a 3-revision load-balanced environment with 3 different country languages, distribute the traffic evenly between each (33%) |
| 61 | +10. Add a new image as a revision - `quay.io/pknezevich/helloworld-v2` |
| 62 | + |
| 63 | + ```sh |
| 64 | + kn service update module4-helloworld \ |
| 65 | + --image quay.io/pknezevich/helloworld-v2 \ |
| 66 | + --env countryCode=IT \ |
| 67 | + --tag module4-helloworld-00001=blue --untag green \ |
| 68 | + --tag @latest=green \ |
| 69 | + --traffic blue=100,green=0 |
| 70 | + ``` |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## 🧩 **Challenge** |
| 75 | + |
| 76 | +- [ ] Design your current environment - canary, blue/green, knife edge |
| 77 | + - You can rename the revision tags to whatever you’d like them to be |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## ✅ **Key Takeaways** |
| 82 | + |
| 83 | +- First time approach to Red Hat’s Serverless Scale-to-zero and auto-scaling |
| 84 | +- Understanding Revisions and Introduced ‘image tagging’ to your container image |
| 85 | +- Demonstrated blue-green deployment |
| 86 | +- Demonstrated canary deployments (using traffic distribution) |
| 87 | +- Demonstrated a knife-edge cutover |
0 commit comments