OCP-mysql
@ -21,6 +21,16 @@ description: Kubernetes教程_使用Kuboard在Kubernetes上部署Spring_Cloud微
|
||||
* `project --> properties --> docker.host` 修改为 `unix:///var/run/docker.sock`
|
||||
* `project --> properties --> docker.image.prefix` 修改为 `ocpsample` (此处使用你在 https://hub.docker.com 的账号)
|
||||
|
||||
::: tip
|
||||
|
||||
如果您使用自己的 docker 镜像仓库,您的 `docker.image.prefix` 要复杂一些,请参考 [使用私有仓库中的docker镜像](/learning/k8s-intermediate/private-registry.html)。具体而言,前缀应该由您的docker镜像仓库的多个参数组成,例如:
|
||||
<font color="blue" weight="500">my-registry.example.com</font>:<font color="green" weight="500">5000</font>/<font color="purple" weight="500">example</font>
|
||||
* 蓝色部分:registry 地址
|
||||
* 绿色部分:registry 端口
|
||||
* 紫色部分:repository 名字
|
||||
|
||||
:::
|
||||
|
||||
``` xml {11,12}
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
|
||||
|
Before Width: | Height: | Size: 235 KiB |
|
Before Width: | Height: | Size: 236 KiB After Width: | Height: | Size: 241 KiB |
|
After Width: | Height: | Size: 173 KiB |
@ -10,7 +10,7 @@ description: Kubernetes教程_使用Kuboard在Kubernetes上部署Spring_Cloud微
|
||||
* [准备OCP的构建环境和部署环境](/learning/k8s-practice/ocp/prepare.html)
|
||||
|
||||
* [构建docker镜像并推送到仓库](/learning/k8s-practice/ocp/build.html)
|
||||
|
||||
|
||||
> 也可以使用 `ocpsample/eureka-server:latest` 镜像
|
||||
* 理解 Spring Cloud Eureka 组件,请参考 [Eureka服务注册与发现](https://www.jianshu.com/p/c18d140ad9f6)
|
||||
|
||||
@ -57,7 +57,11 @@ description: Kubernetes教程_使用Kuboard在Kubernetes上部署Spring_Cloud微
|
||||
|
||||
* 使用 StatefulSet 部署 eureka-server,副本数量为 3
|
||||
* 使用 OCP eureka-server 的 application-slave0.yml 这个 profile
|
||||
* 使用环境变量覆盖 `eureka.client.service-url.defaultZone` 取值,将其设置为: `http://cloud-eureka-0.cloud-eureka:1111/eureka,http://cloud-eureka-1.cloud-eureka:1111/eureka,http://cloud-eureka-2.cloud-eureka:1111/eureka`
|
||||
* 使用环境变量覆盖 `eureka.client.service-url.defaultZone` 取值,将其设置为: `http://cloud-eureka-0.cloud-eureka.ocp.svc.cluster.local:1111/eureka,http://cloud-eureka-1.cloud-eureka.ocp.svc.cluster.local:1111/eureka,http://cloud-eureka-2.cloud-eureka.ocp.svc.cluster.local:1111/eureka`
|
||||
::: tip
|
||||
通过 cloud-eureka-0.cloud-eureka 也可以访问到对应的 POD,但是此处必须使用完整域名,否则 eureka-server 将不被认为是 available
|
||||
:::
|
||||
* 使用环境变量覆盖 `eureka.instance.prefer-ip-address` 取值,将其设置为:`false`
|
||||
* 为 eureka-server 创建 Ingress,并分配域名 `cloud-eureka.ocp.demo.kuboard.cn`
|
||||
* 请参考 [Ingress通过互联网访问您的应用](/learning/k8s-intermediate/service/ingress.html#ingress)
|
||||
* 该域名由 `工作负载名`.`名称空间`.`集群名字`.`一级域名` 组成,这种命名规则下,只需要将 `*.demo.kuboard.cn` 的域名解析指向集群 Ingress Controller 的地址就可以,在测试环境中配置新的模块时非常方便。
|
||||
@ -81,14 +85,17 @@ description: Kubernetes教程_使用Kuboard在Kubernetes上部署Spring_Cloud微
|
||||
| 容器名称 | eureka-server | |
|
||||
| 镜像 | ocpsample/eureka-server:latest | 也可以使用自己构建的镜像 |
|
||||
| 抓取策略 | Always | |
|
||||
| 环境变量 | <div style="max-width: 600px;">eureka.client.service-url.defaultZone=http://cloud-eureka-0.cloud-eureka:1111/eureka,http://cloud-eureka-1.cloud-eureka:1111/eureka,http://cloud-eureka-2.cloud-eureka:1111/eureka</div> | |
|
||||
| 环境变量 | <div style="max-width: 600px;"><span style="color: blue;">eureka.client.service-url.defaultZone=</span>http://cloud-eureka-0.cloud-eureka.ocp.svc.cluster.local:1111/eureka,http://cloud-eureka-1.cloud-eureka.ocp.svc.cluster.local:1111/eureka,http://cloud-eureka-2.cloud-eureka.ocp.svc.cluster.local:1111/eureka</div> <div style="max-width: 600px;"><span style="color: blue;">eureka.instance.prefer-ip-address=</span>false</div> | |
|
||||
| Service | NodePort:<br />协议 `TCP` 服务端口 `1111`节点端口 `31111` 容器端口 `1111` | 可从节点端口访问 |
|
||||
| Ingress | 域名:1cloud-eureka.ocp.demo.kuboard.cn1<br />路由配置: 映射URL `/` 服务端口 `1111` | 可通过域名访问 |
|
||||
| Ingress | 域名:cloud-eureka.ocp.demo.kuboard.cn<br />路由配置: 映射URL `/` 服务端口 `1111` | 可通过域名访问 |
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
* 点击 **保存** 按钮
|
||||
|
||||
* 点击 **应用** 按钮
|
||||
|
||||
* 点击 **完成** 按钮
|
||||
* 等待 eureka-server 完成部署
|
||||
* 根据您服务器到 hub.docker.com 的网速不同,等候的时间约 1-5 分钟
|
||||
@ -106,4 +113,4 @@ description: Kubernetes教程_使用Kuboard在Kubernetes上部署Spring_Cloud微
|
||||
|
||||
eureka-server 界面如下图所示:
|
||||
|
||||

|
||||

|
||||
|
||||
@ -21,6 +21,8 @@ Kuboard 网站将陆续 **连载** 如何使用 Kuboard 在 Kubernetes 上部署
|
||||
* [构建docker镜像并推送到仓库](/learning/k8s-practice/ocp/build.html)
|
||||
* [部署顺序](/learning/k8s-practice/ocp/sequence.html)
|
||||
* [在K8S上部署eureka-server](/learning/k8s-practice/ocp/eureka-server.html)
|
||||
* [在K8S上部署mysql](/learning/k8s-practice/ocp/mysql.html)
|
||||
* [在K8S上部署redis]
|
||||
* [在K8S上部署auth-server]
|
||||
* [在K8S上部署user-center]
|
||||
* [在K8S上部署api-gateway]
|
||||
|
||||
|
After Width: | Height: | Size: 210 KiB |
|
After Width: | Height: | Size: 288 KiB |
|
After Width: | Height: | Size: 233 KiB |
|
After Width: | Height: | Size: 112 KiB |
176
learning/k8s-practice/ocp/mysql.md
Normal file
@ -0,0 +1,176 @@
|
||||
---
|
||||
vssueId: 88
|
||||
layout: LearningLayout
|
||||
description: Kubernetes教程_使用Kuboard在Kubernetes上部署Spring_Cloud_open_capacity_platform微服务能力开放平台_部署mysql
|
||||
---
|
||||
|
||||
|
||||
# 在K8S上部署mysql
|
||||
|
||||
OCP 的 auth-center 和 user-center 都有自己的数据库,同时 auth-center、user-center 和 api-gateway 又都依赖于 redis 缓存服务。这使得我们的部署结构演变成下图所示:
|
||||
|
||||
我们必须先完成 db-auth-center、db-user-center 和 redis 的部署,才能继续部署 auth-center 和 user-center。本文描述了如何部署 db-auth-center、db-user-center。
|
||||
|
||||
::: danger
|
||||
将 mysql 部署到 K8S 中,可以非常便捷地搭建一套测试环境,但是,在生产环境里,并不建议直接将 mysql 部署到 K8S 上。
|
||||
:::
|
||||
|
||||
<p style="max-width: 720px;">
|
||||
<img src="./mysql.assets/image-20190927140239925.png" alt="Kubernetes教程:在K8s上部署MySQL/Redis">
|
||||
</p>
|
||||
|
||||
## 构建并推送mysql镜像
|
||||
|
||||
OCP 要求 mysql 版本 5.7 以上,当我们在 K8S 上部署 mysql 时,将选择 [mysql 官方镜像](https://hub.docker.com/_/mysql) 并基于此镜像,构建自己的 mysql 镜像,以便:
|
||||
* 把数据库初始化脚本打包到镜像中
|
||||
* 这样每次部署一个新的 mysql 实例时,可以自动初始化 OCP 所需要的表结构
|
||||
* 把自定义的数据库配置文件 my.cnf 打包到镜像中 <Badge type="warning">本文档不涉及</Badge>
|
||||
* 设置环境变量 <Badge type="warning">本文档不涉及</Badge>
|
||||
|
||||
### auth-center-mysql
|
||||
|
||||
* 在 master 节点上,执行命令 `cd /root/open-capacity-platform/sql` 切换当前目录。
|
||||
|
||||
> 假设您已经完成了 [准备OCP的构建环境和部署环境](./prepare.html)
|
||||
|
||||
* 执行命令 `vim dockerfile_auth-center` 以创建文件,其内容如下:
|
||||
|
||||
```
|
||||
FROM mysql:5.7.26
|
||||
ADD 02.oauth-center.sql /docker-entrypoint-initdb.d/02.oauth-center.sql
|
||||
EXPOSE 3306
|
||||
```
|
||||
|
||||
* 执行命令 `docker build -f dockerfile_auth-center -t ocpsample/auth-center-mysql:latest .`
|
||||
|
||||
::: tip
|
||||
如果使用私有仓库,则应该按照如下格式填写镜像名:
|
||||
|
||||
<font color="blue" weight="500">my-registry.example.com</font>:<font color="green" weight="500">5000</font>/<font color="purple" weight="500">example</font>/<font color="red" weight="500">auth-center-mysql</font>:<font color="brown" weight="500">latest</font>
|
||||
|
||||
* 蓝色部分:registry 地址
|
||||
* 绿色部分:registry 端口
|
||||
* 紫色部分:repository 名字
|
||||
* 红色部分:image 名字
|
||||
* 棕色部分:image 标签
|
||||
:::
|
||||
|
||||
* 执行命令 `docker login` 登录镜像仓库
|
||||
|
||||
* 执行命令 `docker push ocpsample/auth-center-mysql:latest`
|
||||
|
||||
大约2-5分钟,可完成镜像推送
|
||||
|
||||
### user-center-mysql
|
||||
|
||||
* 在 master 节点上,执行命令 `cd /root/open-capacity-platform/sql` 切换当前目录。(与上一个步骤目录相同)
|
||||
|
||||
* 执行命令 `vim dockerfile_user-center` 以创建文件,其内容如下:
|
||||
|
||||
```
|
||||
FROM mysql:5.7.26
|
||||
ADD 01.user-center.sql /docker-entrypoint-initdb.d/01.user-center.sql
|
||||
EXPOSE 3306
|
||||
```
|
||||
|
||||
* 执行命令 `docker build -f dockerfile_user-center -t ocpsample/user-center-mysql:latest .`
|
||||
|
||||
* 执行命令 `docker push ocpsample/user-center-mysql:latest`
|
||||
|
||||
大约 20 秒,可完成镜像推送
|
||||
|
||||
## 部署mysql
|
||||
|
||||
### 部署auth-center-mysql
|
||||
|
||||
* 在 Kuboard 界面中进入 `ocp` 名称空间
|
||||
|
||||
* 点击 **创建工作负载** 按钮
|
||||
|
||||
填写表单,如下图所示:
|
||||
|
||||
| 字段名称 | 填写内容 | 说明 |
|
||||
| -------- | ------------------------------------------------------------ | ---------------------------------------------------- |
|
||||
| 服务类型 | StatefulSet | |
|
||||
| 服务分层 | 持久层 | |
|
||||
| 服务名称 | auth-center | |
|
||||
| 服务描述 | 认证中心数据库 | |
|
||||
| 副本数量 | 1 | 请填写1 |
|
||||
| 容器名称 | auth-center-mysql | |
|
||||
| 镜像 | ocpsample/auth-center-mysql:latest | |
|
||||
| 抓取策略 | Always | |
|
||||
| 环境变量 | <span style="color: blue;">MYSQL_ROOT_PASSWORD=</span>root | 参考 [mysql官方镜像](https://hub.docker.com/_/mysql) |
|
||||
| Service | ClusterIP(集群内访问)<br />协议:`TCP` 服务端口: `3306` 容器端口: `3306` | |
|
||||
|
||||
::: tip 持久化
|
||||
|
||||
* 将 mysql 的容器内路径 `/var/lib/mysql` 映射到外部数据卷,可以使数据持久保存,请参考 [数据卷](/learning/k8s-intermediate/persistent/volume.html)
|
||||
* 为了保持教程的简洁,此处并没有为 `auth-center-mysql` 挂载外部存储,存入 mysql 的数据在每次容器重启后都将丢失,并重新执行初始化脚本 `02.auth-center.sql`
|
||||
|
||||
:::
|
||||
|
||||
::: tip 访问方式
|
||||
|
||||
为该 StatefulSet 配置了 ClusterIP(集群内访问)的访问方式,Kuboard 将创建一个与 StatefulSet 同名(db-auth-center)的 Kubernetes Service。您可以在集群内同名称空间 `ocp` 下任何容器组中通过 `db-auth-center:3306` 访问 `auth-center-mysql` 数据库,用户名为 root,密码为 root。
|
||||
|
||||
参考 [Service连接应用程序](/learning/k8s-intermediate/service/connecting.html)
|
||||
|
||||
:::
|
||||
|
||||

|
||||
|
||||
* 点击 **保存**
|
||||
* 点击 **应用**
|
||||
* 点击 **完成**
|
||||
|
||||
### 验证auth-center-mysql
|
||||
|
||||
* 在 Kuboard 中进入 `auth-center-mysql` 的终端界面,执行如下命令:
|
||||
|
||||
``` sh
|
||||
mysql -uroot -proot
|
||||
> show databases;
|
||||
> use oauth-center;
|
||||
> show tables;
|
||||
```
|
||||
* 可以验证,oauth-center 的数据库表结构已经完成初始化,输出结果如下图所示:
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
### 部署user-center-mysql
|
||||
|
||||
按照同样的方式部署 user-center-mysql,因此,本章节不在截图,只将必要的步骤和参数进行罗列:
|
||||
|
||||
* 点击 **创建工作负载** 按钮
|
||||
|
||||
* 填写表单,如下表所示:
|
||||
|
||||
| 字段名称 | 填写内容 | 说明 |
|
||||
| -------- | ------------------------------------------------------------ | ---------------------------------------------------- |
|
||||
| 服务类型 | StatefulSet | |
|
||||
| 服务分层 | 持久层 | |
|
||||
| 服务名称 | user-center | |
|
||||
| 服务描述 | 用户中心数据库 | |
|
||||
| 副本数量 | 1 | 请填写1 |
|
||||
| 容器名称 | user-center-mysql | |
|
||||
| 镜像 | ocpsample/user-center-mysql:latest | |
|
||||
| 抓取策略 | Always | |
|
||||
| 环境变量 | <span style="color: blue;">MYSQL_ROOT_PASSWORD=</span>root | 参考 [mysql官方镜像](https://hub.docker.com/_/mysql) |
|
||||
| Service | ClusterIP(集群内访问)<br />协议:`TCP` 服务端口: `3306` 容器端口: `3306` | |
|
||||
|
||||
- 点击 **保存**
|
||||
- 点击 **应用**
|
||||
- 点击 **完成**
|
||||
|
||||
### 验证user-center-mysql
|
||||
|
||||
* 在 Kuboard 中进入 `user-center-mysql` 的终端界面,执行如下命令:
|
||||
|
||||
```sh
|
||||
mysql -uroot -proot
|
||||
> show databases;
|
||||
> use user-center;
|
||||
> show tables;
|
||||
```
|
||||
@ -19,7 +19,8 @@ Kuboard v1.0.x 的更新说明
|
||||
|
||||
|
||||
|
||||
|
||||
* kubeadm 1.15升级到1.16
|
||||
* kuboard 使用 nfs
|
||||
|
||||
|
||||
* Service --> SessionAffinity
|
||||
|
||||
@ -7,6 +7,7 @@ description: Kubernetes教程_本文描述了如何获得Kuboard授权
|
||||
|
||||
## Kuboard 授权声明
|
||||
|
||||
* 许多网友在问,Kuboard收费么?
|
||||
* 使用 Kuboard 是 <font color="red">免费</font> 的,无论您是用于学习还是用于生产
|
||||
* 将来会推出 Kuboard Plus,当前所有的功能,将来仍然免费。Kuboard Plus 侧重点:
|
||||
* 更完善的权限管理(当前只区分集群管理员权限和只读权限)
|
||||
|
||||