4.1 KiB
| title |
|---|
| Multi Environments |
If we have multiple clusters, we want to apply our application in the test cluster first, and then apply it to the production cluster after the application in test cluster is running. KubeVela provides the deploy2env workflow step to manage multi environments. You can have a glimpse of how does it work as below:
In this guide, you will learn how to manage multi environments via deploy2env in Workflow.
Before reading this section, please make sure you have learned about the Env Binding in KubeVela.
How to use
Apply the following Application with workflow step type of deploy2env:
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: multi-env-demo
namespace: default
spec:
components:
- name: nginx-server
type: webservice
properties:
image: nginx:1.21
port: 80
policies:
- name: env
type: env-binding
properties:
created: false
envs:
- name: test
patch:
components:
- name: nginx-server
type: webservice
properties:
image: nginx:1.20
port: 80
placement:
clusterSelector:
labels:
purpose: test
- name: prod
patch:
components:
- name: nginx-server
type: webservice
properties:
image: nginx:1.20
port: 80
placement:
clusterSelector:
labels:
purpose: prod
workflow:
steps:
- name: deploy-test-server
# specify the workflow step type
type: deploy2env
properties:
# specify the component name
component: nginx-server
# specify the policy name
policy: env
# specify the env name in policy
env: test
- name: manual-approval
# suspend is a built-in task of workflow used to suspend the workflow
type: suspend
- name: deploy-prod-server
type: deploy2env
properties:
component: nginx-server
policy: env
env: prod
Expected outcome
Check the Application status:
kubectl get application multi-env-demo -o yaml
We can see that the workflow is suspended at manual-approval:
...
status:
workflow:
...
stepIndex: 2
steps:
- name: deploy-test-server
phase: succeeded
resourceRef: {}
type: deploy2env
- name: manual-approval
phase: succeeded
resourceRef: {}
type: suspend
suspend: true
terminated: false
Switch to test cluster and check the component status:
$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-server 1/1 1 1 1m10s
Use resume command after everything is ok in test cluster:
$ vela workflow resume multi-env-demo
Successfully resume workflow: multi-env-demo
Recheck the Application status:
kubectl get application multi-env-demo -o yaml
All the step status in workflow is succeeded:
...
status:
workflow:
...
stepIndex: 3
steps:
- name: deploy-test-server
phase: succeeded
resourceRef: {}
type: deploy2env
- name: manual-approval
phase: succeeded
resourceRef: {}
type: suspend
- name: deploy-prod-server
phase: succeeded
resourceRef: {}
type: deploy2env
suspend: false
terminated: true
Then, check the component status in prod cluster:
$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-server 1/1 1 1 1m10s
We can see that the component have been applied to both clusters.
With deploy2env, we can easily manage applications in multiple environments.
