Version: v1.2

Multi-Environment

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

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: example-app
  5. namespace: demo
  6. spec:
  7. components:
  8. - name: hello-world-server
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. traits:
  14. - type: scaler
  15. properties:
  16. replicas: 1
  17. - name: data-worker
  18. type: worker
  19. properties:
  20. image: busybox
  21. cmd:
  22. - sleep
  23. - '1000000'
  24. policies:
  25. - name: example-multi-env-policy
  26. type: env-binding
  27. properties:
  28. envs:
  29. - name: test
  30. placement: # selecting the namespace (in local cluster) to deploy to
  31. namespaceSelector:
  32. name: test
  33. selector: # selecting which component to use
  34. components:
  35. - data-worker
  36. - name: staging
  37. placement: # selecting the cluster to deploy to
  38. clusterSelector:
  39. name: cluster-staging
  40. - name: prod
  41. placement: # selecting both namespace and cluster to deploy to
  42. clusterSelector:
  43. name: cluster-prod
  44. namespaceSelector:
  45. name: prod
  46. patch: # overlay patch on above components
  47. components:
  48. - name: hello-world-server
  49. type: webservice
  50. traits:
  51. - type: scaler
  52. properties:
  53. replicas: 3
  54. workflow:
  55. steps:
  56. # deploy to test env
  57. - name: deploy-test
  58. type: deploy2env
  59. properties:
  60. policy: example-multi-env-policy
  61. env: test
  62. # deploy to staging env
  63. - name: deploy-staging
  64. type: deploy2env
  65. properties:
  66. policy: example-multi-env-policy
  67. env: staging
  68. # manual check
  69. - name: manual-approval
  70. type: suspend
  71. # deploy to prod env
  72. - name: deploy-prod
  73. type: deploy2env
  74. properties:
  75. policy: example-multi-env-policy
  76. env: prod

We apply the Application policy-demo in the example.

Before applying this example application, you need a namespace named demo in the current cluster and namespace test in both the current cluster and the staging cluster. You need namespace prod in cluster cluster-prod as well. You can create it by executing cmd kubectl create ns <namespace>.

  1. vela up -f app.yaml

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

  1. $ kubectl get app -n demo
  2. NAME COMPONENT TYPE PHASE HEALTHY STATUS AGE
  3. 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 Applicationpatchfalsenull
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 nameclusterSelectorfalsenull
namespaceSelectorselect deploy namespace by namespace namenamespaceSelectorfalsenull

selector

NameDescTypeRequiredDefault Value
componentscomponent names to be usedstring arrayfalsenull

clusterSelector

NameDescTypeRequiredDefault Value
namecluster namestringfalsenull

namespaceSelector

NameDescTypeRequiredDefault Value
namenamespace namestringfalsenull

You need to upgrade to KubeVela v1.1.5+ to enable namespaceSelector.