Best Practices
Deploying Applications in a Conventional Manner
This scenario takes deploying the WordPress application as an example. WordPress is a blog platform developed in the PHP language and needs to be used together with MySQL. WordPress is used to run the content management program, and MySQL is used as the database to store data.
- Uploading images
- Deploying MySQL
- Deploying WordPress
-
Upload images.
-
Prepare the MySQL and WordPress images.
In this scenario, the MySQL and WordPress images can be obtained from Docker Hub directly and do not need to be created separately.
Note: In other scenarios, you can
create the required images with a dockerfile, or save an existing container as
an image for use. -
Create a repository.
In the ZStack Zaku main menu, click Artifact Repository > Repository. On the Repository page, click Create Repository and the Create Repository page is displayed.You can refer to the following example to enter the required information:
- Name: set the name of the repository.
- Description: optional. Add the information related to the repository.
- Type: set it to private in this scenario.
-
Upload the MySQL image to the repository.
Enter the Image tab of the repository details page and click Upload.On the Upload Image page, refer to the following example to enter the required information:
- Upload Method: select Online Upload in this scenario.
- External Image Address: enter docker.io/library/mysql:5.7.26 in this scenario.
- Architecture: select the same architecture as that of the node where the application is to be deployed.
- Username: it can be left blank in this scenario.
- Password: it can be left blank in this scenario.
-
Upload the WordPress image to the repository.
Enter the Image tab of the repository details page and click Upload.On the Upload Image page, refer to the following example to enter the required information:
- Upload Method: select Online Upload in this scenario.
- External Image Address: enter docker.io/library/wordpress:php8.1 in this scenario.
- Architecture: select the same architecture as that of the node where the application is to be deployed.
- Username: it can be left blank in this scenario.
- Password: it can be left blank in this scenario.
Note: In addition to online upload, ZStack Zaku also supports two image upload methods, file
upload and command-line upload. You can upload an image tarball to a
repository, or push an image to a repository directly with commands. For
details, see Uploading Images.
-
Prepare the MySQL and WordPress images.
-
Deploy MySQL.
-
Create a PVC.
In the ZStack Zaku main menu, select Container Orchestration > PVC Management > PVC. On the PVC page, click Create PVC and the Create PVC page is displayed.Refer to the following example to enter the required information:
- Name: set it to data-mysql in this scenario.
- Storageclass: select the storageclass
(StorageClass) used to create the PVC.
Note:
- A storageclass is a configuration template used to create PVCs dynamically in Kubernetes. It defines the attributes of PVCs, the creation policy and the storage plugin required.
- Storageclasses are created and managed by administrators. If no storageclass is available, contact an administrator.
- Access Mode: select the access mode allowed by the PVC. Set it to ReadWriteOnce in this scenario.
- Capacity: set an appropriate capacity for the PVC. Unit: Gi or Ti.
-
Create a workload.
In the ZStack Zaku main menu, click Container Orchestration > Application Management > Workload to enter the Workload page. Click Create Workload and the Create Workload page is displayed.
- Basic informationYou can refer to the following example to enter the required information:
- Name: set it to mysql-wordpress in this scenario.
- Type: select StatefulSet.
- Replicas: set it to 1.
- The default values can be used for the other settings.
- Container configurationClick Add Container and refer to the following example to enter the required information:
- Container Name: set the name of the container.
- Container Type: select work container.
- Image Source: select repository.
- Image: select the MySQL image.
- Image Tag: select 5.7.26.
- Resource Request: it can be left blank.
- Resource Limit: it can be left blank.
- Startup Command: it can be left blank.
- Startup Parameter: enter --ignore-db-dir=lost+found.
- Environment Variable: select
Custom Key/Value Pair and add the following four
environment variables:
- Key: MYSQL_ROOT_PASSWORD; value: the password of the MySQL root user
- Key: MYSQL_DATABASE; value: the name of the database to be created when MySQL starts
- Key: MYSQL_USER; value: the name of the database user
- Key: MYSQL_PASSWORD; value: the password of the database user
- Liveness Probe: it is not enabled in this scenario.
- Readiness Probe: it is not enabled in this scenario.
- Startup Probe: it is not enabled in this scenario.
- PostStart Hook: it is not enabled in this scenario.
- PreStop Hook: it is not enabled in this scenario.
- Resource mounting
- Mounting a PVC: click Add PVC and refer to
the following example to enter the required information:
- PVC: select the PVC created in step a.
- Container: select the container created in the container configuration.
- Mount Path: enter /var/lib/mysql.
- Permission: set it to read-write.
- Subpath: it is not entered in this scenario.
- In this scenario, no other resource is mounted.
- Mounting a PVC: click Add PVC and refer to
the following example to enter the required information:
- Advanced configuration: keep the default configuration in this scenario.
- Information confirmation
View the workload to be created and confirm the creation.
- Basic information
-
Create a service.
In the ZStack Zaku main menu, click Container Orchestration > Network Management > Service to enter the Service page. Click Create Service and the Create Service page is displayed.
You can refer to the following example to enter the required information:- Name: set it to mysql-wordpress in this scenario.
- Associated Workload: select the workload created in step b.
- Type: select ClusterIP.
Note: In this scenario,
the MySQL service is mainly used by the WordPress service, which
belongs to the access within the cluster, so the service type can be
set to ClusterIP. - IP Type: select IPv4.
- Service Port: set the following information:
- Port: set it to 3306 in this scenario.
- Container Port: set it to 3306 in this scenario.
- Protocol: set it to TCP in this scenario.
- Session Persistence: it is not enabled in this scenario.
- Label: it is not entered in this scenario.
- Annotation: it is not entered in this scenario.
-
Create a PVC.
-
Deploy WordPress.
-
Create a workload.
In the ZStack Zaku main menu, click Container Orchestration > Application Management > Workload to enter the Workload page. Click Create Workload and the Create Workload page is displayed.
- Basic informationYou can refer to the following example to enter the required information:
- Name: set it to wordpress in this scenario.
- Type: select Deployment.
- Replicas: set it to 1.
- The default values can be used for the other settings.
- Container configurationClick Add Container and refer to the following example to enter the required information:
- Container Name: set the name of the container.
- Container Type: select work container.
- Image Source: select repository.
- Image: select the WordPress image.
- Image Tag: select php8.1.
- Resource Request: it can be left blank.
- Resource Limit: it can be left blank.
- Startup Command: it can be left blank.
- Startup Parameter: it can be left blank.
- Environment Variable: select
Custom Key/Value Pair and add the following four
environment variables:
- Key: WORDPRESS_DB_Host; value: the access address of the database. Enter mysql-wordpress:3306 here.
- Key: WORDPRESS_DB_USER; value: the username used to access the database. Enter the same value as that of the environment variable MYSQL_USER of the MySQL workload here.
- Key: WORDPRESS_DB_PASSWORD; value: the password used to access the database. Enter the same value as that of the environment variable MYSQL_PASSWORD of the MySQL workload here.
- Key: WORDPRESS_DB_NAME; value: the name of the database. Enter the same value as that of the environment variable MYSQL_DATABASE of the MySQL workload here.
- Liveness Probe: it is not enabled in this scenario.
- Readiness Probe: it is not enabled in this scenario.
- Startup Probe: it is not enabled in this scenario.
- PostStart Hook: it is not enabled in this scenario.
- PreStop Hook: it is not enabled in this scenario.
- Resource mounting: no resource needs to be mounted here in this scenario.
- Advanced configuration: keep the default configuration in this scenario.
- Information confirmation
View the workload to be created and confirm the creation.
- Basic information
-
Create a service.
In the ZStack Zaku main menu, click Container Orchestration > Network Management > Service to enter the Service page. Click Create Service and the Create Service page is displayed.
You can refer to the following example to enter the required information:- Name: set it to wordpress in this scenario.
- Associated Workload: select the workload created in step b.
- Type: select NodePort.
- IP Type: select IPv4.
- Service Port: set the following information:
- Port: set it to 80 in this scenario.
- Container Port: set it to 80 in this scenario.
- Host Port: it can be left blank.
- Protocol: set it to TCP in this scenario.
- Session Persistence: it is not enabled in this scenario.
- Label: it is not entered in this scenario.
- Annotation: it is not entered in this scenario.
-
Create a workload.
Note: ${NoteIP} is the IP address of any node in the cluster, and ${Port} is the port of
the WordPress service. In the following figure, the port of the WordPress service is
31710.One-Click Deployment of Applications
- Uploading the MySQL Chart deployment package
- Releasing the application with one click
-
Upload the MySQL Chart deployment package.
- Prepare the MySQL Chart deployment package.
-
Create a repository.
In the ZStack Zaku main menu, click Artifact Repository > Repository. On the Repository page, click Create Repository and the Create Repository page is displayed.You can refer to the following example to enter the required information:
- Name: set the name of the repository.
- Description: optional. Add the information related to the repository.
- Type: set it to private in this scenario.
-
Upload the MySQL Chart deployment package.
Enter the Chart tab of the repository details page, and click Upload to upload the package prepared in step a to this repository.
-
Release the application with one click.
In the Chart list, find the MySQL Chart deployment package uploaded and click Operation > Release. On the Release Application page displayed, enter the configuration parameters as needed and click OK.
Note: In addition to the release path described in this section, ZStack Zaku also provides a variety of official Chart deployment packages in
the application market. You can enter Artifact Repository > Application Market to release these packages with one click. In this case, you do not need to
create a repository and upload a Chart deployment package prepared by yourself, which is
faster and more convenient.