Chinese translation of page:quick-start/wordpress-deployment
Signed-off-by: jinchen <jinchen_jacean@163.com>
|
|
@ -1,199 +1,198 @@
|
|||
---
|
||||
title: "Compose and Deploy Wordpress"
|
||||
title: "创建 Wordpress 应用并发布至 Kubernetes"
|
||||
keywords: 'KubeSphere, Kubernetes, app, Wordpress'
|
||||
description: 'Compose and deploy Wordpress.'
|
||||
description: '创建 Wordpress 应用并发布至 Kubernetes。'
|
||||
|
||||
linkTitle: "Compose and Deploy Wordpress"
|
||||
weight: 3050
|
||||
---
|
||||
|
||||
## WordPress Introduction
|
||||
## WordPress 简介
|
||||
|
||||
WordPress is a free and open-source content management system written in PHP, allowing users to build their own websites. A complete Wordpress application includes the following Kubernetes objects with MySQL serving as the backend database.
|
||||
WordPress 是使用 PHP 语言开发的内容管理系统软件,用户可以在支持 PHP 和 MySQL 数据库的服务器上使用自己的博客,一个完整的 Wordpress 应用程序包括以下 Kubernetes 对象。
|
||||
|
||||

|
||||

|
||||
|
||||
## Objective
|
||||
## 目的
|
||||
|
||||
This tutorial demonstrates how to create an application (WordPress as an example) in KubeSphere and access it outside the cluster.
|
||||
本教程演示如何在 KubeSphere 中创建应用程序(以 WordPress 为例)并在集群外访问它。
|
||||
|
||||
## Prerequisites
|
||||
## 准备工作
|
||||
|
||||
An account `project-regular` is needed with the role `operator` assigned in one of your projects (the user has been invited to the project). For more information, see [Create Workspace, Project, Account and Role](../create-workspace-and-project/).
|
||||
需要一个 `project regular` 帐户,并在其中一个项目中分配角色 `operator`(该用户已被邀请参加该项目)。有关详细信息,请参见[创建企业空间、项目、帐户和角色](../create-workspace-and-project/).
|
||||
|
||||
## Estimated Time
|
||||
## 预计操作时间
|
||||
|
||||
About 15 minutes.
|
||||
大约15分钟。
|
||||
|
||||
## Hands-on Lab
|
||||
## 动手操作
|
||||
|
||||
### Task 1: Create Secrets
|
||||
### 任务 1: 创建密钥
|
||||
|
||||
#### Create a MySQL Secret
|
||||
#### 创建 MySQL 密钥
|
||||
|
||||
The environment variable `WORDPRESS_DB_PASSWORD` is the password to connect to the database in WordPress. In this step, you need to create a ConfigMap to store the environment variable that will be used in MySQL pod template.
|
||||
环境变量 `WORDPRESS_DB_PASSWORD` 是连接到 WORDPRESS 数据库的密码。在这一步中,您需要创建一个 ConfigMap 来存储将在 MySQL pod 模板中使用的环境变量。
|
||||
|
||||
1. Log in KubeSphere console using the account `project-regular`. Go to the detailed page of `demo-project` and navigate to **Configurations**. In **Secrets**, click **Create** on the right.
|
||||
1. 使用`project regular`帐户登录 KubeSphere 控制台。转到`demo project`的详细页面并导航到 **配置**。在 **密钥** 中,单击右侧的 **创建**。
|
||||
|
||||

|
||||

|
||||
|
||||
2. Enter the basic information (e.g. name it `mysql-secret`) and click **Next**. In the next page, select **Default** for **Type** and click **Add Data** to add a key-value pair. Input the Key (`MYSQL_ROOT_PASSWORD`) and Value (`123456`) as below and click `√` in the bottom-right corner to confirm. When you finish, click **Create** to continue.
|
||||
2. 输入基本信息 (例如,将其命名为 `mysql-secret`) ,然后单击 **下一步**。在下一页中, 选择 **类型** 为 **默认** ,然后单击 **添加数据** 来添加一个键值对。 输入键(Key) `MYSQL_ROOT_PASSWORD` 和值(Value) `123456` 单击右下角 `√` 的确认按钮, 完成后,单击 **创建** 按钮并继续.
|
||||
|
||||

|
||||

|
||||
|
||||
#### Create a WordPress Secret
|
||||
#### 创建 WordPress 密钥
|
||||
|
||||
Follow the same steps above to create a WordPress secret `wordpress-secret` with the key `WORDPRESS_DB_PASSWORD` and value `123456`. Secrets created display in the list as below:
|
||||
按照上面创建 MySQL 密钥相同的步骤创建一个名字为 `wordpress-secret` 的密钥, 输入键(Key) `WORDPRESS_DB_PASSWORD` 和值(Value) `123456`,创建的密钥显示在列表中,如下所示:
|
||||
|
||||

|
||||

|
||||
|
||||
### Task 2: Create a Volume
|
||||
### 任务 2: 创建存储卷
|
||||
|
||||
1. Go to **Volumes** under **Storage** and click **Create**.
|
||||
1. 点击 **存储管理** 下面的 **存储卷** 并单击 **创建**。
|
||||
|
||||

|
||||

|
||||
|
||||
2. Enter the basic information of the volume (e.g. name it `wordpress-pvc`) and click **Next**.
|
||||
3. In **Volume Settings**, you need to choose an available **Storage Class**, and set **Access Mode** and **Volume Capacity**. You can use the default value directly as shown below. Click **Next** to continue.
|
||||
2. 输入卷的基本信息 (例如,将其命名为 `wordpress-pvc`) ,然后单击 **下一步**。
|
||||
3. 在 **存储卷设置**, 您需要选择一个可用的 **存储类型**, 并设置 **访问模式** 和 **存储卷容量**。您可以直接使用默认值,如下所示。单击 **下一步** 继续。
|
||||
|
||||

|
||||

|
||||
|
||||
4. For **Advanced Settings**, you do not need to add extra information for this task and click **Create** to finish.
|
||||
4. 对于 **高级设置**,您不需要为当前操作设置额外的配置,单击 **创建** 即可完成。
|
||||
|
||||
### Task 3: Create an Application
|
||||
### 任务 3: 创建应用程序
|
||||
|
||||
#### Add MySQL backend component
|
||||
#### 添加 MySQL 后端组件
|
||||
|
||||
1. Navigate to **Applications** under **Application Workloads**, select **Composing App** and click **Create Composing Application**.
|
||||
1. 导航到 **应用负载** 下的 **应用**, 选择 **自制应用** 然后单击 **构建自制应用**。
|
||||
|
||||

|
||||

|
||||
|
||||
2. Enter the basic information (e.g. input `wordpress` for Application Name) and click **Next**.
|
||||
2. 输入基本信息 (例如在应用程序名称中输入 `wordpress`) 然后单击 **下一步**。
|
||||
|
||||

|
||||

|
||||
|
||||
3. In **Components**, click **Add Service** to set a component in the app.
|
||||
3. 在 **服务组件** 中, 单击 **添加服务** 在应用程序中设置组件。
|
||||
|
||||

|
||||

|
||||
|
||||
4. Define a service type for the component. Select **Stateful Service** here.
|
||||
5. Enter the name for the stateful service (e.g. **mysql**) and click **Next**.
|
||||
4. 设置组件的服务类型, 选择 **服务类型** 。
|
||||
5. 输入有状态服务的名称 (例如 **mysql**) ,然后单击 **下一步**。
|
||||
|
||||

|
||||

|
||||
|
||||
6. In **Container Image**, click **Add Container Image**.
|
||||
6. 在 **容器镜像** 中, 单击 **添加容器镜像**。
|
||||
|
||||

|
||||

|
||||
|
||||
7. Enter `mysql:5.6` in the search box, press **Enter** and click **Use Default Ports**. After that, do not click `√` in the bottom-right corner as the setting is not finished yet.
|
||||
7. 在镜像搜索框中输入 `mysql:5.6` , 单击 **回车键** 然后单击 **使用默认端口**。 配置还没有设置完成,请您不要点击右下角的 `√` 按钮。
|
||||
|
||||

|
||||

|
||||
|
||||
{{< notice note >}}
|
||||
|
||||
In **Advanced Settings**, make sure the memory limit is no less than 1000 Mi or MySQL may fail to start due to a lack of memory.
|
||||
在 **高级设置** 中, 请确保内存限制不小于 1000 Mi,否则 MySQL 可能因内存不足而无法启动。
|
||||
|
||||
{{</ notice >}}
|
||||
|
||||
8. Scroll down to **Environment Variables** and click **Use ConfigMap or Secret**. Input the name `MYSQL_ROOT_PASSWORD` and choose the resource `mysql-secret` and the key `MYSQL_ROOT_PASSWORD` created in the previous step. Click `√` after you finish and **Next** to continue.
|
||||
8. 向下滚动到 **环境变量** 然后单击 **引用配置文件或密匙**。 输入名称 `MYSQL_ROOT_PASSWORD` 然后选择资源 `mysql-secret` 和前面步骤中创建的密钥 `MYSQL_ROOT_PASSWORD` 完成后单击 `√` 保存配置 ,最后单击 **下一步** 继续。
|
||||
|
||||

|
||||

|
||||
|
||||
9. Select **Add Volume Template** in **Mount Volumes**. Input the value of **Volume Name** (`mysql`) and **Mount Path** (mode: `ReadAndWrite`, path: `/var/lib/mysql`) as below:
|
||||
9. 选择 **挂载存储** 中的 **添加存储卷**。 输入 **存储卷名称** (`mysql`) 和 **存储类型** (类型: `读写`, 路径: `/var/lib/mysql`)的值,如下所示:
|
||||
|
||||

|
||||

|
||||
|
||||
Click `√` after you finish and click **Next** to continue.
|
||||
完成后单击 `√` 保存设置并单击 **下一步** 继续。
|
||||
|
||||
10. In **Advanced Settings**, you can click **Add** directly or select other options based on your needs.
|
||||
10. 在 **高级设置** 中, 不需要设置,您可以直接点击 **添加** ,也可以根据需要选择其他选项。
|
||||
|
||||

|
||||

|
||||
|
||||
11. At this point, the MySQL component has beed added as shown below:
|
||||
11. 现在,您添加了MySQL组件,如下所示:
|
||||
|
||||

|
||||

|
||||
|
||||
#### Add WordPress frontend component
|
||||
#### 添加 WordPress 前端组件
|
||||
|
||||
12. Click **Add Service** again and select **Stateless Service** this time. Enter the name `wordpress` and click Next.
|
||||
12. 点击 **添加服务** 选择 **无状态服务** 输入名称 `wordpress` 然后单击 **下一步**。
|
||||
|
||||

|
||||

|
||||
|
||||
13. Similar to the step above, click **Add Container Image**, enter `wordpress:4.8-apache` in the search box, press **Enter** and click **Use Default Ports**.
|
||||
13. 与上述步骤类似,单击 **添加容器镜像**, 在搜索框中输入 `wordpress:4.8-apache` 镜像, 按 **回车** ,然后单击 **使用默认端口**。
|
||||
|
||||

|
||||

|
||||
|
||||
14. Scroll down to **Environment Variables** and click **Use ConfigMap or Secret**. Two environment variables need to be added here. Enter the values according to the screenshot below.
|
||||
|
||||
- For `WORDPRESS_DB_PASSWORD`, choose `wordpress-secret` and `WORDPRESS_DB_PASSWORD` created in Task 1.
|
||||
- Click **Add Environment Variable**, and enter `WORDPRESS_DB_HOST` and `mysql` for the key and value.
|
||||
14. 向下滚动到 **环境变量** 然后单击 **引用配置文件或密匙**,这里需要添加两个环境变量。根据下面的屏幕截图输入值。
|
||||
|
||||
- 对于 `WORDPRESS_DB_PASSWORD`, 请选择在任务 1 中创建的 `wordpress-secret` 和 `WORDPRESS_DB_PASSWORD`。
|
||||
- 单击 **添加环境变量**, 输入 `WORDPRESS_DB_HOST` 和 `mysql` 作为作为键(Key)和值(Value)。
|
||||
{{< notice warning >}}
|
||||
|
||||
For the second environment variable added here, the value must be exactly the same as the name you set for MySQL in step 5. Otherwise, Wordpress cannot connect to the corresponding database of MySQL.
|
||||
对于此处添加的第二个环境变量,该值必须与步骤 5 中为 MySQL 设置的名称完全相同。否则,Wordpress 将无法连接到 MySQL 对应的数据库。
|
||||
|
||||
{{</ notice >}}
|
||||
|
||||

|
||||

|
||||
|
||||
Click `√` to save it and **Next** to continue.
|
||||
单击 `√` 保存配置,单击 **下一步** 继续。
|
||||
|
||||
15. In **Mount Volumes**, click **Add Volume** and select **Choose an existing volume**.
|
||||
15. 在 **挂载存储** 设置中, 单击 **添加存储卷** 然后单击 **选择已有存储卷**。
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
|
||||

|
||||

|
||||
|
||||
16. Select `wordpress-pvc` created in the previous step, set the mode as `ReadAndWrite`, and input `/var/www/html` as its mount path. Click `√` to save it and **Next** to continue.
|
||||
16. 选择上一步创建的 `wordpress-pvc`, 将模式设置为 `读写`,并输入装载路径 `/var/www/html` 。 单击 `√` 保存并单击 **下一步** 继续。
|
||||
|
||||

|
||||

|
||||
|
||||
17. In **Advanced Settings**, you can click **Add** directly or select other options based on your needs.
|
||||
17. 在 **高级设置** 中, 您可以直接点击 **添加** 创建服务,也可以根据需要选择其他选项。
|
||||
|
||||

|
||||

|
||||
|
||||
18. The frontend component is also set now. Click **Next** to continue.
|
||||
18. 现在也设置了前端组件。单击 **下一步** 继续。
|
||||
|
||||

|
||||

|
||||
|
||||
19. You can set route rules (Ingress) here or click **Create** directly.
|
||||
19. 您可以在这里设置路由规则(入口),也可以直接单击 **创建** 来创建应用程序。
|
||||
|
||||

|
||||

|
||||
|
||||
20. The app will display in the list below after you create it.
|
||||
20. 创建后,应用程序将显示在下面的列表中。
|
||||
|
||||

|
||||

|
||||
|
||||
### Task 4: Verify the Resources
|
||||
### Task 4: 验证资源
|
||||
|
||||
In **Workloads**, check the status of `wordpress-v1` and `mysql-v1` in **Deployments** and **StatefulSets** respectively. If they are running as shown in the image below, it means WordPress has been created successfully.
|
||||
在 **工作负载** 中,分别检查 **部署** 和 **有状态副本集** 中的 `wordpress-v1` 和 `mysql-v1` 的状态。 如果他们运行如下图所示,这意味着 WordPress 已经成功创建。
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||
### Task 5: Access WordPress through NodePort
|
||||
### Task 5: 通过 NodePort 访问 WordPress
|
||||
|
||||
1. To access the service outside the cluster, navigate to **Services** first. Click the three dots on the right of `wordpress` and select **Edit Internet Access**.
|
||||
1. 要访问集群外的服务,请首先导航到 **服务** 。 单击 `wordpress` 右侧的三个点后选择 **编辑外网访问**。
|
||||
|
||||

|
||||

|
||||
|
||||
2. Select `NodePort` for **Access Method** and click **OK**.
|
||||
2. 在 **访问方式** 中选择 `NodePort`, 然后单击 **确定**。
|
||||
|
||||

|
||||

|
||||
|
||||
3. Click the service and you can see the port exposed.
|
||||
3. 单击服务,您可以看到暴露的端口。
|
||||
|
||||

|
||||

|
||||
|
||||
4. Access this application via `{Node IP}:{NodePort}` and you can see an image as below:
|
||||
4. 通过 `{Node IP}:{NodePort}` 访问此应用程序,您可以看到下图:
|
||||
|
||||

|
||||

|
||||
|
||||
{{< notice note >}}
|
||||
|
||||
Make sure the port is opened in your security groups before you access the service.
|
||||
在访问服务之前,请确保安全组中的端口已打开。
|
||||
|
||||
{{</ notice >}}
|
||||
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 81 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 72 KiB |