In Walrus, operators declare the types of resources to be provided in the Resource Definition
. They then apply different resource deployment templates to various types of environments and projects by setting up matching rules. Developers do not need to focus on the specific implementation of the underlying layer.
By creating Resource
objects to declare the types of resources needed and their basic information, they can flexibly automate the creation of required resources and use them in various environments. This shields the complexity of the infrastructure of different environments and reduces the cognitive burden on researchers and developers.
This tutorial will use a MySQL database as an example and show how to quickly deploy an application to different environments with Walrus by configuring two API objects: Resource Definition
and Resource
.
What is Resource Definition?
To begin, let's clarify some of the concepts involved.Resource Definitions
are central to Walrus' approach to creating a unified abstraction of the upper layers of a multi-cloud, hybrid infrastructure. This approach simplifies deployment configuration.
Similar to the concept of multi-architecture in containers, this allows the same image to contain different architectures of the image Manifest
configuration. The image is acquired according to the actual environment, automatically selecting the appropriate image, enabling seamless switching of containers on different hardware.
Walrus Resource Definition serves as the Manifest
in the deployment process. It includes the configuration of various rules and automatically selects the appropriate deployment template based on the environment during deployment.
The Resource Definition consists of 4 parts:
Template: The configuration required to create resources through customization or abstraction using open source templates.
Matching rule: Define the matching conditions for each rule and the template to be used when the conditions are met.
Admin Predefined Config: Simplify user configuration at deployment time by adding predefined configurations such as administrative configurations, best practices, etc. under matching rules.
UI Schema: Hide complexity with customized user interface styles based on requirements.
Now let's take a look at how you can leverage resource definitions to shield complexity and deploy applications across multiple infrastructures.
How to Deploy Applications across multiple infrastructures
Prerequisites
Before you begin, prepare the appropriate resources, and complete the following configuration tasks:
1. Connector configuration
Go to Default Project > Connectors > New Connector
, enter the name aws, select the connector of the cloud provider type, select AWS
for the type, select Production
for the applicable environment type, and enter other information to complete the configuration.
Click New Connector
again, enter the name alibaba
, select Alibaba
for the type, select Production
for the applicable environment type, and enter other information to complete the configuration.
2. Prepare the environments
Go to Default Project > Environment > New Environment
, enter production
as the name, and associate the newly created connector named aws
with the production deployment environment.
Create another new environment, enter the name dr
, and associate it with the connector named alibaba
, which will be used as the cloud disaster recovery environment. Together with the local
environment that comes with the default project, we now have a total of three environments: local
, production
, and dr
.
Configure Resource Definition
This is an example of deploying a MySQL database.
1. Resource Definition Matching Rules
Go to Operations > Resource Definition
and select New Resource Definition
.
Enter the name as demo-mysql
and select the type as MySQL.
Create New Matching Rule
. dev
is utilized to specify the match rules and templates for the development environment. Please add a selector and select the environment name as local
. Use the latest version of builtin/kubernetes-mysql
for the template and match the CPU and memory resources in the predefined configuration section.
The production
one represents the production environment. To add a selector, select the environment name and enter production. The template utilizes the latest version of builtin/aws-rds-mysql
. In the predefined configuration section, match the Vpc Id
so that you don't need to fill it in when creating resources using this resource definition. Other configurations should be based on the actual situation.
The matching rule dr
represents the disaster recovery environment. To select this environment, add a selector and enter dr
as the environment name. Use the latest version of builtin/alicloud-rds-mysql
for the template. Match the Vpc Id
in the predefined configuration section and configure the remaining settings according to the actual situation.
2. Customize UI Schema
After configuring the rules, Walrus will automatically generate UI schema based on the configuration and predefined settings. Administrators can then customize the UI schema to their specific needs.
To view the generated UI schema, go to Operations > Resource Definition
, find the corresponding Resource Definition
and preview UI Schema. We have simplified the configurations by removing the complex ones and only including the common configurations. This will help users spin up quickly. Below is the finalized UI Schema:
Deploy MySQL across Multiple Environments
The configured resource definitions will aid in application deployment across infrastructure.
Navigate to
Applications> Local Environment > New Resource
.Enter the resource name, select the resource type as
MySQL
, specify the architecture, database version, and other configurations, and then clickSave and Deploy
to complete the deployment.Navigate to the
production
environment and selectNew Resource
. Choose theMySQL
resource type and enter the configuration details.
Repeat step 3 for the DR
environment.
Verify that all three environments now have MySQL resources deployed. The Kubernetes connector is used for the local
environment, the AWS
connector is used for the production environment, and the Alibaba
connector is used for the DR
environment. This allows for dynamic creation of corresponding resources based on the current environment.
In the Kubernetes cluster, the MySQL container is created for the local
environment.
The production
environment creates the rds
service in the aws
.
The dr
environment has created the corresponding rds
service in the alibaba
cloud.
Deploy Application across infrastructure via Walrus File
The Walrus file can be used to deploy an application, in addition to using the UI:
1. Prepare app.yaml
as follows:
version: v1
resources:
- name: mysql
type: mysql
attributes:
architecture: standalone
database: mydb
engine_version: "8.0"
username: rdsuser
2. Run the command to deploy MySQL to different environments.
# deploy to local environment
walrus apply -f app.yaml -p default -e local
# deploy to production environment
walrus apply -f app.yaml -p default -e production
# deploy to dr environment
walrus apply -f app.yaml -p default -e dr
CLI deployment allows for the reuse of the same Walrus file for multiple environments.
We have simplified application deployment by configuring resource definitions and deploying them to multiple environments, reducing infrastructure complexity and workload for developers and operators.
With XaC (Everything is Code), Walrus unifies the application lifecycle, from provisioning underlying infrastructure resources to releasing upper-tier applications. It also integrates with CI tools to automate CI/CD pipeline delivery. If you are tired of dealing with complex infrastructure provisioning or want to streamline your application management and deployment process, consider installing and using Walrus.
If you are interested in platform engineering, welcome to our community:
Discord: https://discord.gg/fXZUKK2baF
Twitter/X: https://twitter.com/Seal_io
LinkedIn: https://www.linkedin.com/company/seal-io
Youtube: https://www.youtube.com/@Seal-io