Skip to main content
Version: v1.1

Multi-Environment Deployment

This documentation will introduce how to use env-binding to automate multi-stage application rollout across multiple environments.

Background#

Users usually have two or more environments to deploy applications to. For example, dev environment to test the application code, and production environment to deploy applications to serve live traffic. For different environments, the deployment configuration also has some nuance.

Multi-env Application Deployment#

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: example-app
namespace: test
spec:
components:
- name: hello-world-server
type: webservice
properties:
image: crccheck/hello-world
port: 8000
traits:
- type: scaler
properties:
replicas: 1
- name: data-worker
type: worker
properties:
image: busybox
cmd:
- sleep
- '1000000'
policies:
- name: example-multi-env-policy
type: env-binding
properties:
envs:
- name: staging
placement: # selecting the cluster to deploy to
clusterSelector:
name: cluster-staging
selector: # selecting which component to use
components:
- hello-world-server
- name: prod
placement:
clusterSelector:
name: cluster-prod
patch: # overlay patch on above components
components:
- name: hello-world-server
type: webservice
traits:
- type: scaler
properties:
replicas: 3
workflow:
steps:
# deploy to staging env
- name: deploy-staging
type: deploy2env
properties:
policy: example-multi-env-policy
env: staging
# manual check
- name: manual-approval
type: suspend
# deploy to prod env
- name: deploy-prod
type: deploy2env
properties:
policy: example-multi-env-policy
env: prod

We apply the Application policy-demo in the example.

Before applying this example application, you need a namespace named test in the current cluster and two sub-clusters. You can create it by executing cmd kubectl create ns test.

kubectl apply -f app.yaml

After the Application is created, a configured Application will be created under the test namespace.

$ kubectl get app -n test
NAME COMPONENT TYPE PHASE HEALTHY STATUS AGE
example-app hello-world-server webservice running 25s

If you want to learn more about env-binding, please refer to Multi Cluster Deployment.

Appendix: Parameter List#

NameDescTypeRequiredDefault Value
envsenvironment configurationenv arraytruenull

env

NameDescTypeRequiredDefault Value
nameenvironment namestringtruenull
patchconfigure the components of the Applicationpatchtruenull
placementresource scheduling strategy, choose to deploy the configured resources to the specified cluster or namespaceplacementtruenull
selectoridentify which components to be deployed for this environment, default to be empty which means deploying all componentsselectorfalsenull

patch

NameDescTypeRequiredDefault Value
componentscomponents that need to be configuredcomponent arraytruenull

placement

NameDescTypeRequiredDefault Value
clusterSelectorselect deploy cluster by cluster nameclusterSelectortruenull

selector

名称描述类型是否必须默认值
componentscomponent names to be usedstring arrayfalsenull

clusterSelector

NameDescTypeRequiredDefault Value
namecluster namestringfalsenull
Last updated on by Hongchao Deng