This case will introduce what is environment and how to initialize an environment.
An Application development team usually needs to initialize some shared environment for users. An environment is a logical concept that represents a set of common resources for Applications.
For example, a team usually wants two environments: one for development, and one for production.
In general, the resource types that can be initialized include the following types:
One or more Kubernetes clusters. Different environments may need different sizes and versions of Kubernetes clusters. Environment initialization can also manage multiple clusters .
Any type of Kubernetes custom resources (CRDS) and system plug-ins can be set up in environment initialization.
All kinds of shared resources and services. For example. shared resources in microservices. These shared resources can be a microservice component, cloud database, cache, load balancer, API gateway, and so on.
Various management policies and processes. An environment may have different global policies. The policy can be chaos test, security scan, SLO and son on; the process can be initializing a database table, registering an automatic discovery configuration, and so on.
KubeVela allows you to use different resources to initialize the environment.
You can use the
Workflow in your
Application. Note that there may be dependencies between initializations, we can use
depends-on-app in workflow to do it.
The initialization of different environments has dependencies. Common resources can be separated as dependencies. In this way, reusable initialization modules can be formed.
For example, if both the test and develop environments rely on the same controllers, these controllers can be pulled out and initialized as separate environments, specifying dependency initialization in both the development and test environments.
Make sure your KubeVela version is
If we want to use some CRD controller like OpenKruise in cluster, we can use
Helm to initialize
We can directly use Application to initialize a kruise environment. The application below will deploy a kruise controller in cluster.
We have to enable
fluxcd in cluster since we use
Helm to deploy kruise.
We can use
depends-on-app to make sure
fluxcd is deployed before kruise.
depends-on-appwill check if the cluster has the application with
properties. If the application exists, the next step will be executed after the application is running. If the application do not exists, KubeVela will check the ConfigMap with the same name, and read the config of the Application and apply to cluster. For more information, please refer to depends-on-app.
Check the application in cluster:
Kruise is running successfully! Then you can use kruise in your cluster. If you need to set up a new environment, the only thing you need to do is to apply the files like above.
Some Kubernetes native resources like ConfigMap/PVC are commonly used in the environment.
If you want to apply those resources before deploying your application, you can add an initialization workflow to your application.
KubeVela provides a built-in workflow step
apply-object to fill in native Kubernetes resources.
In this way, by filling in Kubernetes native resources, we can avoid writing redundant component definitions.
Apply the following application, it will initialize an environment with ConfigMap/PVC. There is two components in this application, the first one will write data to PVC, the second on will read the data from PVC:
Check the PVC and ConfigMap in cluster：
Check the application in cluster：
Check the logs of the second component:
We can see that both components is running. The two components share the same PVC and use the same ConfigMap.