生产实践
1.迭代新需求/修复BUG(编码--->提git)
2.测试环境发版,测试(应用通过编译打包发布至test命名空间)
3.测试通过,上线(应用镜像直接发布至prod命名空间)
系统架构
(1)物理架构
主机名 | 角色 | IP地址 |
---|---|---|
mfyxw10.mfyxw.com | zk-test(测试环境Test) | 192.168.80.10 |
mfyxw20.mfyxw.com | zk-prod(生产环境prod) | 192.168.80.20 |
mfyxw30.mfyxw.com | kubernetes运算节点 | 192.168.80.30 |
mfyxw40.mfyxw.com | kubernetes运算节点 | 192.168.80.40 |
mfyxw50.mfyxw.com | 运维主机,harbor仓库 | 192.168.80.50 |
(2)K8S内系统架构
环境 | 命名空间 | 应用 |
---|---|---|
测试环境(TEST) | test | apollo-config, apollo-admin |
测试环境(TEST) | test | dubbo-demo-service, dubbo-demo-web |
生产环境(PROD) | prod | apollo-config, apollo-admin |
生产环境(PROD) | prod | dubbo-demo-service, dubbo-demo-web |
OPS环境(infra) | infra | jenkins, dubbo-monitor, apollo-portal |
注意:Apollo分环境的原则:
1.要使用Apollo的话,portal服务可以在各环境*用一套
2.adminservice和configservice每个环境都需要部署一套并且数据库都不相同
3.在分环境之前,已经创建过portal、adminservice、configservice,都建议删除或使用dashboard,将设置为0,如果没有创建过,则此点可以忽略
1.添加域名解析
在mfyxw10.mfyxw.com主机上操作
(1)添加DNS域名解析
[root@mfyxw10 ~]# cat > /var/named/od.com.zone << EOF
\$ORIGIN od.com.
\$TTL 600 ; 10 minutes
@ IN SOA dns.od.com. dnsadmin.od.com. (
;序号请加1,表示比之前版本要新
2020031313 ; serial
10800 ; refresh (3 hours)
900 ; retry (15 minutes)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
NS dns.od.com.
\$TTL 60 ; 1 minute
dns A 192.168.80.10
harbor A 192.168.80.50 ;添加harbor记录
k8s-yaml A 192.168.80.50
traefik A 192.168.80.100
dashboard A 192.168.80.100
zk1 A 192.168.80.10
zk2 A 192.168.80.20
zk3 A 192.168.80.30
jenkins A 192.168.80.100
dubbo-monitor A 192.168.80.100
demo A 192.168.80.100
mysql A 192.168.80.10
config A 192.168.80.100
portal A 192.168.80.100
zk-test A 192.168.80.10
zk-prod A 192.168.80.20
config-test A 192.168.80.100
config-prod A 192.168.80.100
demo-test A 192.168.80.100
demo-prod A 192.168.80.100
EOF
(2)重启DNS服务
[root@mfyxw10 ~]# systemctl restart named
(3)测试域名解析
[root@mfyxw10 ~]# dig -t A config-test.od.com @192.168.80.10 +short
192.168.80.100
[root@mfyxw10 ~]#
[root@mfyxw10 ~]# dig -t A config-test.od.com @192.168.80.10 +short
192.168.80.100
[root@mfyxw10 ~]#
[root@mfyxw10 ~]# dig -t A config-prod.od.com @192.168.80.10 +short
192.168.80.100
[root@mfyxw10 ~]#
[root@mfyxw10 ~]# dig -t A zk-test.od.com @192.168.80.10 +short
192.168.80.10
[root@mfyxw10 ~]#
[root@mfyxw10 ~]# dig -t A zk-prod.od.com @192.168.80.10 +short
192.168.80.20
[root@mfyxw10 ~]#
[root@mfyxw10 ~]# dig -t A demo-test.od.com @192.168.80.10 +short
192.168.80.100
[root@mfyxw10 ~]#
[root@mfyxw10 ~]# dig -t A demo-prod.od.com @192.168.80.10 +short
192.168.80.100
2.在k8s集群中创建名称空间以及连接私有仓库的secret
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)任意一台执行即可
(1)在k8s集群中创建名称空间
[root@mfyxw30 ~]# kubectl create namespace test
namespace/test created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl create namespace prod
namespace/prod created
(2)创建secret
[root@mfyxw30 ~]# kubectl create secret docker-registry harbor --docker-server=harbor.od.com --docker-username=admin --docker-password=Harbor12345 -n test
secret/harbor created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl create secret docker-registry harbor --docker-server=harbor.od.com --docker-username=admin --docker-password=Harbor12345 -n prod
secret/harbor created
3.我原环境已部署过portal,adminservice,configservice,我将先删除
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)任意一台执行即可
[root@mfyxw30 ~]# kubectl get pod -n infra
NAME READY STATUS RESTARTS AGE
apollo-adminservice-5cccf97c64-w9tzw 1/1 Running 0 4m51s
apollo-configservice-5f6555448-bcx22 1/1 Running 0 4m43s
apollo-portal-57bc86966d-4w5ld 1/1 Running 0 4m59s
dubbo-monitor-6676dd74cc-9hghb 1/1 Running 22 20d
dubbo-monitor-6676dd74cc-rd86g 1/1 Running 21 20d
jenkins-b99776c69-49dnr 1/1 Running 2 44h
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl delete -f http://k8s-yaml.od.com/apollo-adminservice/deployment.yaml
deployment.extensions "apollo-adminservice" deleted
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl delete -f http://k8s-yaml.od.com/apollo-configservice/deployment.yaml
deployment.extensions "apollo-configservice" deleted
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl delete -f http://k8s-yaml.od.com/apollo-portal/deployment.yaml
deployment.extensions "apollo-portal" deleted
[root@mfyxw30 ~]# kubectl get pod -n infra
NAME READY STATUS RESTARTS AGE
dubbo-monitor-6676dd74cc-9hghb 1/1 Running 22 20d
dubbo-monitor-6676dd74cc-rd86g 1/1 Running 21 20d
jenkins-b99776c69-49dnr 1/1 Running 2 44h
4.分别导入各环境的数据库脚本以及授权
在mfyxw10.mfyxw.com主机上操作
(1)test环境的数据库脚本如下(建议vi /root/apolloconfigtest.sql,再复制粘贴内容):
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO‘ */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
# Create Database
# ------------------------------------------------------------
CREATE DATABASE IF NOT EXISTS ApolloConfigTestDB DEFAULT CHARACTER SET = utf8mb4;
Use ApolloConfigTestDB;
# Dump of table app
# ------------------------------------------------------------
DROP TABLE IF EXISTS `App`;
CREATE TABLE `App` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘主键‘,
`AppId` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘AppID‘,
`Name` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘应用名‘,
`OrgId` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘部门Id‘,
`OrgName` varchar(64) NOT NULL DEFAULT ‘default‘ COMMENT ‘部门名字‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `AppId` (`AppId`(191)),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
KEY `IX_Name` (`Name`(191))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘应用表‘;
# Dump of table appnamespace
# ------------------------------------------------------------
DROP TABLE IF EXISTS `AppNamespace`;
CREATE TABLE `AppNamespace` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`Name` varchar(32) NOT NULL DEFAULT ‘‘ COMMENT ‘namespace名字,注意,需要全局唯一‘,
`AppId` varchar(32) NOT NULL DEFAULT ‘‘ COMMENT ‘app id‘,
`Comment` varchar(64) NOT NULL DEFAULT ‘‘ COMMENT ‘注释‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `IX_AppId` (`AppId`),
KEY `Name_AppId` (`Name`,`AppId`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘应用namespace定义‘;
# Dump of table audit
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Audit`;
`EntityName` varchar(50) NOT NULL DEFAULT ‘default‘ COMMENT ‘表名‘,
`EntityId` int(10) unsigned DEFAULT NULL COMMENT ‘记录ID‘,
`OpName` varchar(50) NOT NULL DEFAULT ‘default‘ COMMENT ‘操作类型‘,
`Comment` varchar(500) DEFAULT NULL COMMENT ‘备注‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘日志审计表‘;
# Dump of table cluster
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Cluster`;
CREATE TABLE `Cluster` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`Name` varchar(32) NOT NULL DEFAULT ‘‘ COMMENT ‘集群名字‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `IX_AppId_Name` (`AppId`,`Name`),
KEY `IX_ParentClusterId` (`ParentClusterId`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘集群‘;
# Dump of table commit
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Commit`;
CREATE TABLE `Commit` (
`AppId` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘AppID‘,
`ClusterName` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘ClusterName‘,
`NamespaceName` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘namespaceName‘,
`Comment` varchar(500) DEFAULT NULL COMMENT ‘备注‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
KEY `AppId` (`AppId`(191)),
KEY `ClusterName` (`ClusterName`(191)),
KEY `NamespaceName` (`NamespaceName`(191))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘commit 历史表‘;
# Dump of table grayreleaserule
# ------------------------------------------------------------
DROP TABLE IF EXISTS `GrayReleaseRule`;
CREATE TABLE `GrayReleaseRule` (
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘主键‘,
`NamespaceName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘Namespace Name‘,
`BranchName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘branch name‘,
`Rules` varchar(16000) DEFAULT ‘[]‘ COMMENT ‘灰度规则‘,
`ReleaseId` int(11) unsigned NOT NULL DEFAULT ‘0‘ COMMENT ‘灰度对应的release‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘灰度规则表‘;
# Dump of table instance
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Instance`;
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增Id‘,
`AppId` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘AppID‘,
`ClusterName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘ClusterName‘,
`DataCenter` varchar(64) NOT NULL DEFAULT ‘default‘ COMMENT ‘Data Center Name‘,
PRIMARY KEY (`Id`),
UNIQUE KEY `IX_UNIQUE_KEY` (`AppId`,`ClusterName`,`Ip`,`DataCenter`),
KEY `IX_IP` (`Ip`),
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘使用配置的应用实例‘;
# Dump of table instanceconfig
# ------------------------------------------------------------
DROP TABLE IF EXISTS `InstanceConfig`;
CREATE TABLE `InstanceConfig` (
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增Id‘,
`InstanceId` int(11) unsigned DEFAULT NULL COMMENT ‘Instance Id‘,
`ConfigAppId` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘Config App Id‘,
`ConfigClusterName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘Config Cluster Name‘,
`ReleaseDeliveryTime` timestamp NULL DEFAULT NULL COMMENT ‘配置获取时间‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
PRIMARY KEY (`Id`),
UNIQUE KEY `IX_UNIQUE_KEY` (`InstanceId`,`ConfigAppId`,`ConfigNamespaceName`),
KEY `IX_ReleaseKey` (`ReleaseKey`),
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘应用实例的配置信息‘;
# Dump of table item
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Item`;
CREATE TABLE `Item` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增Id‘,
`Value` longtext NOT NULL COMMENT ‘配置项值‘,
`Comment` varchar(1024) DEFAULT ‘‘ COMMENT ‘注释‘,
`LineNum` int(10) unsigned DEFAULT ‘0‘ COMMENT ‘行号‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `IX_GroupId` (`NamespaceId`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘配置项目‘;
# Dump of table namespace
# ------------------------------------------------------------
CREATE TABLE `Namespace` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`AppId` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘AppID‘,
`ClusterName` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘Cluster Name‘,
`NamespaceName` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘Namespace Name‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `AppId_ClusterName_NamespaceName` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191)),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
KEY `IX_NamespaceName` (`NamespaceName`(191))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘命名空间‘;
# Dump of table namespacelock
# ------------------------------------------------------------
DROP TABLE IF EXISTS `NamespaceLock`;
CREATE TABLE `NamespaceLock` (
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增id‘,
`NamespaceId` int(10) unsigned NOT NULL DEFAULT ‘0‘ COMMENT ‘集群NamespaceId‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘default‘ COMMENT ‘最后修改人邮箱前缀‘,
`IsDeleted` bit(1) DEFAULT b‘0‘ COMMENT ‘软删除‘,
PRIMARY KEY (`Id`),
UNIQUE KEY `IX_NamespaceId` (`NamespaceId`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘namespace的编辑锁‘;
# Dump of table release
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Release`;
CREATE TABLE `Release` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`ReleaseKey` varchar(64) NOT NULL DEFAULT ‘‘ COMMENT ‘发布的Key‘,
`Name` varchar(64) NOT NULL DEFAULT ‘default‘ COMMENT ‘发布名字‘,
`NamespaceName` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘namespaceName‘,
`Configurations` longtext NOT NULL COMMENT ‘发布配置‘,
`IsAbandoned` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘是否废弃‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `AppId_ClusterName_GroupName` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191)),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
KEY `IX_ReleaseKey` (`ReleaseKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘发布‘;
# Dump of table releasehistory
# ------------------------------------------------------------
DROP TABLE IF EXISTS `ReleaseHistory`;
CREATE TABLE `ReleaseHistory` (
`ClusterName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘ClusterName‘,
`NamespaceName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘namespaceName‘,
`BranchName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘发布分支名‘,
`ReleaseId` int(11) unsigned NOT NULL DEFAULT ‘0‘ COMMENT ‘关联的Release Id‘,
`PreviousReleaseId` int(11) unsigned NOT NULL DEFAULT ‘0‘ COMMENT ‘前一次发布的ReleaseId‘,
`OperationContext` longtext NOT NULL COMMENT ‘发布上下文信息‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
KEY `IX_ReleaseId` (`ReleaseId`),
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘发布历史‘;
# Dump of table releasemessage
DROP TABLE IF EXISTS `ReleaseMessage`;
CREATE TABLE `ReleaseMessage` (
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`Message` varchar(1024) NOT NULL DEFAULT ‘‘ COMMENT ‘发布的消息内容‘,
PRIMARY KEY (`Id`),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
DROP TABLE IF EXISTS `ServerConfig`;
CREATE TABLE `ServerConfig` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增Id‘,
`Key` varchar(64) NOT NULL DEFAULT ‘default‘ COMMENT ‘配置项Key‘,
`Value` varchar(2048) NOT NULL DEFAULT ‘default‘ COMMENT ‘配置项值‘,
`Comment` varchar(1024) DEFAULT ‘‘ COMMENT ‘注释‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘最后修改时间‘,
PRIMARY KEY (`Id`),
KEY `IX_Key` (`Key`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘配置服务自身配置‘;
# Config
# ------------------------------------------------------------
INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`, `Comment`)
VALUES
(‘eureka.service.url‘, ‘default‘, ‘http://localhost:8080/eureka/‘, ‘Eureka服务Url,多个service>以英文逗号分隔‘),
(‘namespace.lock.switch‘, ‘default‘, ‘false‘, ‘一次发布只能有一个人修改开关‘),
(‘item.key.length.limit‘, ‘default‘, ‘128‘, ‘item key 最大长度限制‘),
(‘item.value.length.limit‘, ‘default‘, ‘20000‘, ‘item value最大长度限制‘),
(‘config-service.cache.enabled‘, ‘default‘, ‘false‘, ‘ConfigService是否开启缓存,开启后能提高性
能,但是会增大内存消耗!‘);
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
(2)导入test环境的数据库脚本
[root@mfyxw10 ~]# mysql -uroot -p < apolloconfigtest.sql
Enter password: #输入数据库密码即可完成导入
(3)查看创建的数据库名称及表名
[root@mfyxw10 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 63
Server version: 10.1.45-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| ApolloConfigDB |
| ApolloConfigTestDB |
| ApolloPortalDB |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
6 rows in set (0.01 sec)
MariaDB [(none)]> use ApolloConfigTestDB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [ApolloConfigTestDB]> show tables;
+------------------------------+
| Tables_in_ApolloConfigTestDB |
+------------------------------+
| App |
| AppNamespace |
| Audit |
| Cluster |
| Commit |
| GrayReleaseRule |
| Instance |
| InstanceConfig |
| Item |
| Namespace |
| NamespaceLock |
| Release |
| ReleaseHistory |
| ReleaseMessage |
| ServerConfig |
+------------------------------+
15 rows in set (0.00 sec)
MariaDB [ApolloConfigTestDB]>
(4)修改ApolloConfigTestDB数据库的ServerConfig的Value
查看原ServerConfig的Value值
MariaDB [(none)]> use ApolloConfigTestDB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [ApolloConfigTestDB]>
MariaDB [ApolloConfigTestDB]> select * from ServerConfig\G
*************************** 1. row ***************************
Id: 1
Key: eureka.service.url
Cluster: default
Value: http://localhost:8080/eureka/
Comment: Eureka服务Url,多个service以英文逗号分隔
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 22:14:48
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 22:14:48
*************************** 2. row ***************************
Id: 2
Key: namespace.lock.switch
Cluster: default
Value: false
Comment: 一次发布只能有一个人修改开关
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 22:14:48
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 22:14:48
*************************** 3. row ***************************
Id: 3
Key: item.key.length.limit
Cluster: default
Value: 128
Comment: item key 最大长度限制
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 22:14:48
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 22:14:48
*************************** 4. row ***************************
Id: 4
Key: item.value.length.limit
Cluster: default
Value: 20000
Comment: item value最大长度限制
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 22:14:48
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 22:14:48
*************************** 5. row ***************************
Id: 5
Key: config-service.cache.enabled
Cluster: default
Value: false
Comment: ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 22:14:48
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 22:14:48
5 rows in set (0.00 sec)
MariaDB [ApolloConfigTestDB]>
更新ServerConfig的Value值
MariaDB [ApolloConfigTestDB]> update ApolloConfigTestDB.ServerConfig set ServerConfig.Value="http://config-test.od.com/eureka" where ServerConfig.key="eureka.service.url";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [ApolloConfigTestDB]>
查看更新后的ServerConfig的Value值
MariaDB [ApolloConfigTestDB]> select * from ServerConfig\G;
*************************** 1. row ***************************
Id: 1
Key: eureka.service.url
Cluster: default
Value: http://config-test.od.com/eureka
Comment: Eureka服务Url,多个service以英文逗号分隔
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 22:14:48
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 22:57:02
*************************** 2. row ***************************
Id: 2
Key: namespace.lock.switch
Cluster: default
Value: false
Comment: 一次发布只能有一个人修改开关
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 22:14:48
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 22:14:48
*************************** 3. row ***************************
Id: 3
Key: item.key.length.limit
Cluster: default
Value: 128
Comment: item key 最大长度限制
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 22:14:48
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 22:14:48
*************************** 4. row ***************************
Id: 4
Key: item.value.length.limit
Cluster: default
Value: 20000
Comment: item value最大长度限制
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 22:14:48
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 22:14:48
*************************** 5. row ***************************
Id: 5
Key: config-service.cache.enabled
Cluster: default
Value: false
Comment: ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 22:14:48
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 22:14:48
5 rows in set (0.00 sec)
ERROR: No query specified
MariaDB [ApolloConfigTestDB]>
(5)对ApolloConfigTestDB数据库授权
MariaDB [(none)]> grant INSERT,UPDATE,DELETE,SELECT on ApolloConfigTestDB.* to "apolloconfig"@"192.168.80.%" identified by "123456";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
(6)prod环境的数据库脚本如下(建议vi /root/apolloconfigprod.sql,再复制粘贴内容):
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO‘ */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
# Create Database
# ------------------------------------------------------------
CREATE DATABASE IF NOT EXISTS ApolloConfigProdDB DEFAULT CHARACTER SET = utf8mb4;
Use ApolloConfigProdDB;
# Dump of table app
# ------------------------------------------------------------
DROP TABLE IF EXISTS `App`;
CREATE TABLE `App` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘主键‘,
`AppId` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘AppID‘,
`Name` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘应用名‘,
`OrgId` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘部门Id‘,
`OrgName` varchar(64) NOT NULL DEFAULT ‘default‘ COMMENT ‘部门名字‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `AppId` (`AppId`(191)),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
KEY `IX_Name` (`Name`(191))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘应用表‘;
# Dump of table appnamespace
# ------------------------------------------------------------
DROP TABLE IF EXISTS `AppNamespace`;
CREATE TABLE `AppNamespace` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`Name` varchar(32) NOT NULL DEFAULT ‘‘ COMMENT ‘namespace名字,注意,需要全局唯一‘,
`AppId` varchar(32) NOT NULL DEFAULT ‘‘ COMMENT ‘app id‘,
`Comment` varchar(64) NOT NULL DEFAULT ‘‘ COMMENT ‘注释‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `IX_AppId` (`AppId`),
KEY `Name_AppId` (`Name`,`AppId`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘应用namespace定义‘;
# Dump of table audit
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Audit`;
`EntityName` varchar(50) NOT NULL DEFAULT ‘default‘ COMMENT ‘表名‘,
`EntityId` int(10) unsigned DEFAULT NULL COMMENT ‘记录ID‘,
`OpName` varchar(50) NOT NULL DEFAULT ‘default‘ COMMENT ‘操作类型‘,
`Comment` varchar(500) DEFAULT NULL COMMENT ‘备注‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘日志审计表‘;
# Dump of table cluster
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Cluster`;
CREATE TABLE `Cluster` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`Name` varchar(32) NOT NULL DEFAULT ‘‘ COMMENT ‘集群名字‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `IX_AppId_Name` (`AppId`,`Name`),
KEY `IX_ParentClusterId` (`ParentClusterId`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘集群‘;
# Dump of table commit
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Commit`;
CREATE TABLE `Commit` (
`AppId` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘AppID‘,
`ClusterName` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘ClusterName‘,
`NamespaceName` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘namespaceName‘,
`Comment` varchar(500) DEFAULT NULL COMMENT ‘备注‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
KEY `AppId` (`AppId`(191)),
KEY `ClusterName` (`ClusterName`(191)),
KEY `NamespaceName` (`NamespaceName`(191))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘commit 历史表‘;
# Dump of table grayreleaserule
# ------------------------------------------------------------
DROP TABLE IF EXISTS `GrayReleaseRule`;
CREATE TABLE `GrayReleaseRule` (
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘主键‘,
`NamespaceName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘Namespace Name‘,
`BranchName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘branch name‘,
`Rules` varchar(16000) DEFAULT ‘[]‘ COMMENT ‘灰度规则‘,
`ReleaseId` int(11) unsigned NOT NULL DEFAULT ‘0‘ COMMENT ‘灰度对应的release‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘灰度规则表‘;
# Dump of table instance
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Instance`;
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增Id‘,
`AppId` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘AppID‘,
`ClusterName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘ClusterName‘,
`DataCenter` varchar(64) NOT NULL DEFAULT ‘default‘ COMMENT ‘Data Center Name‘,
PRIMARY KEY (`Id`),
UNIQUE KEY `IX_UNIQUE_KEY` (`AppId`,`ClusterName`,`Ip`,`DataCenter`),
KEY `IX_IP` (`Ip`),
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘使用配置的应用实例‘;
# Dump of table instanceconfig
# ------------------------------------------------------------
DROP TABLE IF EXISTS `InstanceConfig`;
CREATE TABLE `InstanceConfig` (
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增Id‘,
`InstanceId` int(11) unsigned DEFAULT NULL COMMENT ‘Instance Id‘,
`ConfigAppId` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘Config App Id‘,
`ConfigClusterName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘Config Cluster Name‘,
`ReleaseDeliveryTime` timestamp NULL DEFAULT NULL COMMENT ‘配置获取时间‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
PRIMARY KEY (`Id`),
UNIQUE KEY `IX_UNIQUE_KEY` (`InstanceId`,`ConfigAppId`,`ConfigNamespaceName`),
KEY `IX_ReleaseKey` (`ReleaseKey`),
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘应用实例的配置信息‘;
# Dump of table item
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Item`;
CREATE TABLE `Item` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增Id‘,
`Value` longtext NOT NULL COMMENT ‘配置项值‘,
`Comment` varchar(1024) DEFAULT ‘‘ COMMENT ‘注释‘,
`LineNum` int(10) unsigned DEFAULT ‘0‘ COMMENT ‘行号‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `IX_GroupId` (`NamespaceId`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘配置项目‘;
# Dump of table namespace
# ------------------------------------------------------------
CREATE TABLE `Namespace` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`AppId` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘AppID‘,
`ClusterName` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘Cluster Name‘,
`NamespaceName` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘Namespace Name‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `AppId_ClusterName_NamespaceName` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191)),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
KEY `IX_NamespaceName` (`NamespaceName`(191))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘命名空间‘;
# Dump of table namespacelock
# ------------------------------------------------------------
DROP TABLE IF EXISTS `NamespaceLock`;
CREATE TABLE `NamespaceLock` (
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增id‘,
`NamespaceId` int(10) unsigned NOT NULL DEFAULT ‘0‘ COMMENT ‘集群NamespaceId‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘default‘ COMMENT ‘最后修改人邮箱前缀‘,
`IsDeleted` bit(1) DEFAULT b‘0‘ COMMENT ‘软删除‘,
PRIMARY KEY (`Id`),
UNIQUE KEY `IX_NamespaceId` (`NamespaceId`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘namespace的编辑锁‘;
# Dump of table release
# ------------------------------------------------------------
DROP TABLE IF EXISTS `Release`;
CREATE TABLE `Release` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`ReleaseKey` varchar(64) NOT NULL DEFAULT ‘‘ COMMENT ‘发布的Key‘,
`Name` varchar(64) NOT NULL DEFAULT ‘default‘ COMMENT ‘发布名字‘,
`NamespaceName` varchar(500) NOT NULL DEFAULT ‘default‘ COMMENT ‘namespaceName‘,
`Configurations` longtext NOT NULL COMMENT ‘发布配置‘,
`IsAbandoned` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘是否废弃‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
PRIMARY KEY (`Id`),
KEY `AppId_ClusterName_GroupName` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191)),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
KEY `IX_ReleaseKey` (`ReleaseKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘发布‘;
# Dump of table releasehistory
# ------------------------------------------------------------
DROP TABLE IF EXISTS `ReleaseHistory`;
CREATE TABLE `ReleaseHistory` (
`ClusterName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘ClusterName‘,
`NamespaceName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘namespaceName‘,
`BranchName` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘发布分支名‘,
`ReleaseId` int(11) unsigned NOT NULL DEFAULT ‘0‘ COMMENT ‘关联的Release Id‘,
`PreviousReleaseId` int(11) unsigned NOT NULL DEFAULT ‘0‘ COMMENT ‘前一次发布的ReleaseId‘,
`OperationContext` longtext NOT NULL COMMENT ‘发布上下文信息‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
KEY `IX_ReleaseId` (`ReleaseId`),
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘发布历史‘;
# Dump of table releasemessage
DROP TABLE IF EXISTS `ReleaseMessage`;
CREATE TABLE `ReleaseMessage` (
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增主键‘,
`Message` varchar(1024) NOT NULL DEFAULT ‘‘ COMMENT ‘发布的消息内容‘,
PRIMARY KEY (`Id`),
KEY `DataChange_LastTime` (`DataChange_LastTime`),
DROP TABLE IF EXISTS `ServerConfig`;
CREATE TABLE `ServerConfig` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT ‘自增Id‘,
`Key` varchar(64) NOT NULL DEFAULT ‘default‘ COMMENT ‘配置项Key‘,
`Value` varchar(2048) NOT NULL DEFAULT ‘default‘ COMMENT ‘配置项值‘,
`Comment` varchar(1024) DEFAULT ‘‘ COMMENT ‘注释‘,
`IsDeleted` bit(1) NOT NULL DEFAULT b‘0‘ COMMENT ‘1: deleted, 0: normal‘,
`DataChange_CreatedBy` varchar(32) NOT NULL DEFAULT ‘default‘ COMMENT ‘创建人邮箱前缀‘,
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间‘,
`DataChange_LastModifiedBy` varchar(32) DEFAULT ‘‘ COMMENT ‘最后修改人邮箱前缀‘,
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘最后修改时间‘,
PRIMARY KEY (`Id`),
KEY `IX_Key` (`Key`),
KEY `DataChange_LastTime` (`DataChange_LastTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘配置服务自身配置‘;
# Config
# ------------------------------------------------------------
INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`, `Comment`)
VALUES
(‘eureka.service.url‘, ‘default‘, ‘http://localhost:8080/eureka/‘, ‘Eureka服务Url,多个service>以英文逗号分隔‘),
(‘namespace.lock.switch‘, ‘default‘, ‘false‘, ‘一次发布只能有一个人修改开关‘),
(‘item.key.length.limit‘, ‘default‘, ‘128‘, ‘item key 最大长度限制‘),
(‘item.value.length.limit‘, ‘default‘, ‘20000‘, ‘item value最大长度限制‘),
(‘config-service.cache.enabled‘, ‘default‘, ‘false‘, ‘ConfigService是否开启缓存,开启后能提高性
能,但是会增大内存消耗!‘);
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
(7)导入prod环境的数据库脚本
[root@mfyxw10 ~]# mysql -uroot -p < apolloconfigprod.sql
Enter password: #输入数据库密码即可完成导入
(8)查看创建的数据库名称及表名
[root@mfyxw10 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 63
Server version: 10.1.45-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| ApolloConfigDB |
| ApolloConfigProdDB |
| ApolloConfigTestDB |
| ApolloPortalDB |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
7 rows in set (0.00 sec)
MariaDB [(none)]>
MariaDB [(none)]> use ApolloConfigProdDB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [ApolloConfigProdDB]> show tables;
+------------------------------+
| Tables_in_ApolloConfigProdDB |
+------------------------------+
| App |
| AppNamespace |
| Audit |
| Cluster |
| Commit |
| GrayReleaseRule |
| Instance |
| InstanceConfig |
| Item |
| Namespace |
| NamespaceLock |
| Release |
| ReleaseHistory |
| ReleaseMessage |
| ServerConfig |
+------------------------------+
15 rows in set (0.00 sec)
MariaDB [ApolloConfigProdDB]>
(9)修改ApolloConfigProdDB数据库的ServerConfig的Value
查看原ServerConfig的Value值
MariaDB [(none)]> use ApolloConfigProdDB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [ApolloConfigProdDB]> select * from ServerConfig\G
*************************** 1. row ***************************
Id: 1
Key: eureka.service.url
Cluster: default
Value: http://localhost:8080/eureka/
Comment: Eureka服务Url,多个service以英文逗号分隔
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 23:04:16
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:04:16
*************************** 2. row ***************************
Id: 2
Key: namespace.lock.switch
Cluster: default
Value: false
Comment: 一次发布只能有一个人修改开关
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 23:04:16
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:04:16
*************************** 3. row ***************************
Id: 3
Key: item.key.length.limit
Cluster: default
Value: 128
Comment: item key 最大长度限制
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 23:04:16
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:04:16
*************************** 4. row ***************************
Id: 4
Key: item.value.length.limit
Cluster: default
Value: 20000
Comment: item value最大长度限制
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 23:04:16
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:04:16
*************************** 5. row ***************************
Id: 5
Key: config-service.cache.enabled
Cluster: default
Value: false
Comment: ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 23:04:16
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:04:16
5 rows in set (0.00 sec)
MariaDB [ApolloConfigProdDB]>
更新ServerConfig的Value值
MariaDB [ApolloConfigProdDB]> update ApolloConfigProdDB.ServerConfig set ServerConfig.Value="http://config-prod.od.com/eureka" where ServerConfig.key="eureka.service.url";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
MariaDB [ApolloConfigProdDB]>
查看更新后的ServerConfig的Value值
MariaDB [ApolloConfigProdDB]> select * from ServerConfig\G;
*************************** 1. row ***************************
Id: 1
Key: eureka.service.url
Cluster: default
Value: http://config-prod.od.com/eureka
Comment: Eureka服务Url,多个service以英文逗号分隔
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 23:04:16
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:04:16
*************************** 2. row ***************************
Id: 2
Key: namespace.lock.switch
Cluster: default
Value: false
Comment: 一次发布只能有一个人修改开关
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 23:04:16
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:04:16
*************************** 3. row ***************************
Id: 3
Key: item.key.length.limit
Cluster: default
Value: 128
Comment: item key 最大长度限制
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 23:04:16
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:04:16
*************************** 4. row ***************************
Id: 4
Key: item.value.length.limit
Cluster: default
Value: 20000
Comment: item value最大长度限制
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 23:04:16
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:04:16
*************************** 5. row ***************************
Id: 5
Key: config-service.cache.enabled
Cluster: default
Value: false
Comment: ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-09 23:04:16
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:04:16
5 rows in set (0.00 sec)
ERROR: No query specified
MariaDB [ApolloConfigProdDB]>
(5)对ApolloConfigProdDB数据库授权
MariaDB [(none)]> grant INSERT,DELETE,UPDATE,SELECT on ApolloConfigProdDB.* to "apolloconfig"@"192.168.80.%" identified by "123456";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
5.修改ApolloPortalDB中的ServerConfig的Value值
(1)查看原来ServerConfig的值
MariaDB [(none)]> use ApolloPortalDB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [ApolloPortalDB]> show tables;
+--------------------------+
| Tables_in_ApolloPortalDB |
+--------------------------+
| App |
| AppNamespace |
| Authorities |
| Consumer |
| ConsumerAudit |
| ConsumerRole |
| ConsumerToken |
| Favorite |
| Permission |
| Role |
| RolePermission |
| ServerConfig |
| UserRole |
| Users |
+--------------------------+
14 rows in set (0.00 sec)
MariaDB [ApolloPortalDB]> select * from ServerConfig\G;
*************************** 1. row ***************************
Id: 1
Key: apollo.portal.envs
Value: dev
Comment: 可支持的环境列表
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
*************************** 2. row ***************************
Id: 2
Key: organizations
Value: [{"orgId":"yf1","orgName":"Linux学院"},{"orgId":"yf2","orgName":"云计算学院"},{"orgId":"yf3","orgName":"Python学院"},{"orgId":"yf4","orgName":"大数据学院"}]
Comment: 部门列表
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:31:50
*************************** 3. row ***************************
Id: 3
Key: superAdmin
Value: apollo
Comment: Portal超级管理员
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
*************************** 4. row ***************************
Id: 4
Key: api.readTimeout
Value: 10000
Comment: http接口read timeout
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
*************************** 5. row ***************************
Id: 5
Key: consumer.token.salt
Value: someSalt
Comment: consumer token salt
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
*************************** 6. row ***************************
Id: 6
Key: admin.createPrivateNamespace.switch
Value: true
Comment: 是否允许项目管理员创建私有namespace
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
*************************** 7. row ***************************
Id: 7
Key: configView.memberOnly.envs
Value: pro
Comment: 只对项目成员显示配置信息的环境列表,多个env以英文逗号分隔
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
7 rows in set (0.00 sec)
ERROR: No query specified
MariaDB [ApolloPortalDB]>
(2)更新ServerConfig的Value的值为fat,pro
MariaDB [ApolloPortalDB]> update ApolloPortalDB.ServerConfig set ServerConfig.Value=‘fat,pro‘ where Id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [ApolloPortalDB]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [ApolloPortalDB]>
(3)查看更新ServerConfig的ID为1的Value的值
MariaDB [ApolloPortalDB]> select * from ServerConfig\G
*************************** 1. row ***************************
Id: 1
Key: apollo.portal.envs
Value: fat,pro
Comment: 可支持的环境列表
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-09 23:22:50
*************************** 2. row ***************************
Id: 2
Key: organizations
Value: [{"orgId":"yf1","orgName":"Linux学院"},{"orgId":"yf2","orgName":"云计算学院"},{"orgId":"yf3","orgName":"Python学院"},{"orgId":"yf4","orgName":"大数据学院"}]
Comment: 部门列表
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:31:50
*************************** 3. row ***************************
Id: 3
Key: superAdmin
Value: apollo
Comment: Portal超级管理员
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
*************************** 4. row ***************************
Id: 4
Key: api.readTimeout
Value: 10000
Comment: http接口read timeout
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
*************************** 5. row ***************************
Id: 5
Key: consumer.token.salt
Value: someSalt
Comment: consumer token salt
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
*************************** 6. row ***************************
Id: 6
Key: admin.createPrivateNamespace.switch
Value: true
Comment: 是否允许项目管理员创建私有namespace
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
*************************** 7. row ***************************
Id: 7
Key: configView.memberOnly.envs
Value: pro
Comment: 只对项目成员显示配置信息的环境列表,多个env以英文逗号分隔
IsDeleted:
DataChange_CreatedBy: default
DataChange_CreatedTime: 2020-07-06 10:15:59
DataChange_LastModifiedBy:
DataChange_LastTime: 2020-07-06 10:15:59
7 rows in set (0.00 sec)
MariaDB [ApolloPortalDB]>
6.修改apollo-portal的configmap.yaml资源配置清单并应用
在运维主机mfyxw50.mfyxw.com上操作
(1)修改apollo-portal的configmap资源配置清单
[root@mfyxw50 ~]# cat > /data/k8s-yaml/apollo-portal/configmap.yaml << EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: apollo-portal-cm
namespace: infra
data:
application-github.properties: |
# DataSource
spring.datasource.url = jdbc:mysql://mysql.od.com:3306/ApolloPortalDB?characterEncoding=utf8
spring.datasource.username = apolloportal
spring.datasource.password = 123456
app.properties: |
appId=100003173
apollo-env.properties: |
fat.meta=http://config-test.od.com
pro.meta=http://config-prod.od.com
EOF
(2)应用apollo-portal的configmap资源配置清单
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)任意一台主机上操作即可
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-portal/configmap.yaml
configmap/apollo-portal-cm configured
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl get cm -n infra
NAME DATA AGE
apollo-adminservice-cm 2 3d22h
apollo-configservice-cm 2 6d15h
apollo-portal-cm 3 3d15h
dubbo-monitor-cm 1 21d
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl describe cm apollo-portal-cm -n infra
Name: apollo-portal-cm
Namespace: infra
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","data":{"apollo-env.properties":"fat.meta=http://config-test.od.com\npro.meta=http://config-prod.od.com\n","app.propert...
Data
====
app.properties:
----
appId=100003173
application-github.properties:
----
# DataSource
spring.datasource.url = jdbc:mysql://mysql.od.com:3306/ApolloPortalDB?characterEncoding=utf8
spring.datasource.username = apolloportal
spring.datasource.password = 123456
apollo-env.properties:
----
fat.meta=http://config-test.od.com
pro.meta=http://config-prod.od.com
Events: <none>
7.创建资源配置清单
(1)创建资源配置清单存放目录
在运维主机(mfyxw50.mfyxw.com)上操作
[root@mfyxw50 ~]# mkdir -p /data/k8s-yaml/test/{apollo-configservice,apollo-adminservice,dubbo-demo-service,dubbo-demo-consumer}
[root@mfyxw50 ~]# mkdir -p /data/k8s-yaml/prod/{apollo-configservice,apollo-adminservice,dubbo-demo-service,dubbo-demo-consumer}
(2)创建test环境的apollo-configservice资源配置清单
在运维主机(mfyxw50.mfyxw.com)上操作
deployment.yaml
[root@mfyxw50 ~]# cat > /data/k8s-yaml/test/apollo-configservice/deployment.yaml << EOF
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: apollo-configservice
namespace: test
labels:
name: apollo-configservice
spec:
replicas: 1
selector:
matchLabels:
name: apollo-configservice
template:
metadata:
labels:
app: apollo-configservice
name: apollo-configservice
spec:
volumes:
- name: configmap-volume
configMap:
name: apollo-configservice-cm
containers:
- name: apollo-configservice
image: harbor.od.com/infra/apollo-configservice:v1.5.1
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- name: configmap-volume
mountPath: /apollo-configservice/config
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
securityContext:
runAsUser: 0
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
EOF
configmap.yaml
[root@mfyxw50 ~]# cat > /data/k8s-yaml/test/apollo-configservice/configmap.yaml << EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: apollo-configservice-cm
namespace: test
data:
application-github.properties: |
# DataSource
spring.datasource.url = jdbc:mysql://mysql.od.com:3306/ApolloConfigTestDB?characterEncoding=utf8
spring.datasource.username = apolloconfig
spring.datasource.password = 123456
eureka.service.url = http://config-test.od.com/eureka
app.properties: |
appId=100003171
EOF
service.yaml
[root@mfyxw50 ~]# cat > /data/k8s-yaml/test/apollo-configservice/service.yaml <<EOF
kind: Service
apiVersion: v1
metadata:
name: apollo-configservice
namespace: test
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8080
selector:
app: apollo-configservice
clusterIP: None
type: ClusterIP
sessionAffinity: None
EOF
Ingress.yaml
[root@mfyxw50 ~]# cat > /data/k8s-yaml/test/apollo-configservice/Ingress.yaml <<EOF
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: apollo-configservice
namespace: test
spec:
rules:
- host: config-test.od.com
http:
paths:
- path: /
backend:
serviceName: apollo-configservice
servicePort: 8080
EOF
(3)应用测试环境的apollo-configservice配置资源清单
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)上任意一台执行即可
[root@mfyxw30 ~]# kubectl get pod -n test
No resources found.
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-configservice/configmap.yaml
configmap/apollo-configservice-cm created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-configservice/deployment.yaml
deployment.extensions/apollo-configservice created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-configservice/service.yaml
service/apollo-configservice created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-configservice/Ingress.yaml
ingress.extensions/apollo-configservice created
[root@mfyxw30 ~]# kubectl get pod -n test
NAME READY STATUS RESTARTS AGE
apollo-configservice-5f6555448-qrj77 1/1 Running 0 40s
(4)在浏览器访问config-test.od.com
在eurake中能看到测试环境test的apollo-configservice已经注册到eurake了
(5)创建test环境的apollo-adminservice资源配置清单
在运维主机mfyxw50.mfyxw.com上执行
deployment.yaml
[root@mfyxw50 ~]# cat > /data/k8s-yaml/test/apollo-adminservice/deployment.yaml <<EOF
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: apollo-adminservice
namespace: test
labels:
name: apollo-adminservice
spec:
replicas: 1
selector:
matchLabels:
name: apollo-adminservice
template:
metadata:
labels:
app: apollo-adminservice
name: apollo-adminservice
spec:
volumes:
- name: configmap-volume
configMap:
name: apollo-adminservice-cm
containers:
- name: apollo-adminservice
image: harbor.od.com/infra/apollo-adminservice:v1.5.1
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- name: configmap-volume
mountPath: /apollo-adminservice/config
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
securityContext:
runAsUser: 0
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
EOF
configmap.yaml
[root@mfyxw50 ~]# cat > /data/k8s-yaml/test/apollo-adminservice/configmap.yaml <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: apollo-adminservice-cm
namespace: test
data:
application-github.properties: |
# DataSource
spring.datasource.url = jdbc:mysql://mysql.od.com:3306/ApolloConfigTestDB?characterEncoding=utf8
spring.datasource.username = apolloconfig
spring.datasource.password = 123456
eureka.service.url = http://config-test.od.com/eureka
app.properties: |
appId=100003172
EOF
(8)应用测试环境test的apollo-adminservice配置资源清单
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)上任意一台执行即可
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-adminservice/configmap.yaml
configmap/apollo-adminservice-cm created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-adminservice/deployment.yaml
deployment.extensions/apollo-adminservice created
[root@mfyxw30 ~]# kubectl get pod -n test
NAME READY STATUS RESTARTS AGE
apollo-adminservice-5cccf97c64-ddjjc 1/1 Running 0 24s
apollo-configservice-5f6555448-qrj77 1/1 Running 0 20m
(9)再次在浏览器访问config-test.od.com
可以看到,apollo-configservice和apollo-adminservice都分别注册到eurake了
(10)创建prod生产环境configservice资源配置清单
在运维主机mfyxw50.mfyxw.com上操作
deployment.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/prod/apollo-configservice/deployment.yaml << EOF
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: apollo-configservice
namespace: prod
labels:
name: apollo-configservice
spec:
replicas: 1
selector:
matchLabels:
name: apollo-configservice
template:
metadata:
labels:
app: apollo-configservice
name: apollo-configservice
spec:
volumes:
- name: configmap-volume
configMap:
name: apollo-configservice-cm
containers:
- name: apollo-configservice
image: harbor.od.com/infra/apollo-configservice:v1.5.1
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- name: configmap-volume
mountPath: /apollo-configservice/config
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
securityContext:
runAsUser: 0
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
EOF
configmap.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/prod/apollo-configservice/configmap.yaml << EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: apollo-configservice-cm
namespace: prod
data:
application-github.properties: |
# DataSource
spring.datasource.url = jdbc:mysql://mysql.od.com:3306/ApolloConfigProdDB?characterEncoding=utf8
spring.datasource.username = apolloconfig
spring.datasource.password = 123456
eureka.service.url = http://config-prod.od.com/eureka
app.properties: |
appId=100003171
EOF
Ingress.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/prod/apollo-configservice/Ingress.yaml <<EOF
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: apollo-configservice
namespace: prod
spec:
rules:
- host: config-prod.od.com
http:
paths:
- path: /
backend:
serviceName: apollo-configservice
servicePort: 8080
EOF
service.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/prod/apollo-configservice/service.yaml <<EOF
kind: Service
apiVersion: v1
metadata:
name: apollo-configservice
namespace: prod
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8080
selector:
app: apollo-configservice
clusterIP: None
type: ClusterIP
sessionAffinity: None
EOF
(11)创建prod生产环境adminservice资源配置清单
在运维主机mfyxw50.mfyxw.com上操作
deployment.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/prod/apollo-adminservice/deployment.yaml <<EOF
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: apollo-adminservice
namespace: prod
labels:
name: apollo-adminservice
spec:
replicas: 1
selector:
matchLabels:
name: apollo-adminservice
template:
metadata:
labels:
app: apollo-adminservice
name: apollo-adminservice
spec:
volumes:
- name: configmap-volume
configMap:
name: apollo-adminservice-cm
containers:
- name: apollo-adminservice
image: harbor.od.com/infra/apollo-adminservice:v1.5.1
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- name: configmap-volume
mountPath: /apollo-adminservice/config
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
securityContext:
runAsUser: 0
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
EOF
configmap.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/prod/apollo-adminservice/configmap.yaml <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: apollo-adminservice-cm
namespace: prod
data:
application-github.properties: |
# DataSource
spring.datasource.url = jdbc:mysql://mysql.od.com:3306/ApolloConfigProdDB?characterEncoding=utf8
spring.datasource.username = apolloconfig
spring.datasource.password = 123456
eureka.service.url = http://config-prod.od.com/eureka
app.properties: |
appId=100003172
EOF
(12)创建prod生产环境configservice和adminservice资源配置清单
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)上任意一台执行即可
[root@mfyxw30 ~]# kubectl get pod -n prod
No resources found.
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-configservice/configmap.yaml
configmap/apollo-configservice-cm created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-configservice/deployment.yaml
deployment.extensions/apollo-configservice created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-configservice/service.yaml
service/apollo-configservice created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-configservice/Ingress.yaml
ingress.extensions/apollo-configservice created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-adminservice/configmap.yaml
configmap/apollo-adminservice-cm created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-adminservice/deployment.yaml
deployment.extensions/apollo-adminservice created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl get pod -n prod
NAME READY STATUS RESTARTS AGE
apollo-adminservice-5cccf97c64-dvlfx 1/1 Running 0 32s
apollo-configservice-5f6555448-7kj46 1/1 Running 0 66s
(13)在浏览器中访问config-prod.od.com
8.将portal应用起来
我的portal在前面的实验已经启动了,也被我在dashboard中设置为0了,建议登录portal.od.com里删除dubbo-demo-service和dubbo-demo-web项目或进入ApolloPortalDB数据库删除清除AppNamespace和App表的内容
在浏览器访问portal.od.com,表示已经停止了portal
那我就去数据库中进行操作吧
在mfyxw10.mfyxw.com主机上操作
(1)对portal数据库的AppNamespace和App内容清空
[root@mfyxw10 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 169
Server version: 10.1.45-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> use ApolloPortalDB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [ApolloPortalDB]> select * from AppNamespace;
+----+-------------+--------------------+------------+----------+-----------------------+-----------+----------------------+------------------------+---------------------------+---------------------+
| Id | Name | AppId | Format | IsPublic | Comment | IsDeleted | DataChange_CreatedBy | DataChange_CreatedTime | DataChange_LastModifiedBy | DataChange_LastTime |
+----+-------------+--------------------+------------+----------+-----------------------+-----------+----------------------+------------------------+---------------------------+---------------------+
| 1 | application | dubbo-demo-service | properties | | default app namespace | | apollo | 2020-07-07 21:22:36 | apollo | 2020-07-07 21:22:36 |
| 2 | application | dubbo-demo-web | properties | | default app namespace | | apollo | 2020-07-09 14:10:45 | apollo | 2020-07-09 14:10:45 |
+----+-------------+--------------------+------------+----------+-----------------------+-----------+----------------------+------------------------+---------------------------+---------------------+
2 rows in set (0.00 sec)
MariaDB [ApolloPortalDB]> select * from App;
+----+--------------------+----------------------+-------+-------------+-----------+----------------+-----------+----------------------+------------------------+---------------------------+---------------------+
| Id | AppId | Name | OrgId | OrgName | OwnerName | OwnerEmail | IsDeleted | DataChange_CreatedBy | DataChange_CreatedTime | DataChange_LastModifiedBy | DataChange_LastTime |
+----+--------------------+----------------------+-------+-------------+-----------+----------------+-----------+----------------------+------------------------+---------------------------+---------------------+
| 1 | dubbo-demo-service | dubbo服务提供者 | yf1 | Linux学院 | apollo | mapleyf@qq.com | | apollo | 2020-07-07 21:22:36 | apollo | 2020-07-07 21:22:36 |
| 2 | dubbo-demo-web | dubbo服务消费者 | yf1 | Linux学院 | apollo | mapleyf@qq.com | | apollo | 2020-07-09 14:10:45 | apollo | 2020-07-09 14:10:45 |
+----+--------------------+----------------------+-------+-------------+-----------+----------------+-----------+----------------------+------------------------+---------------------------+---------------------+
2 rows in set (0.00 sec)
MariaDB [ApolloPortalDB]> truncate table AppNamespace;
Query OK, 0 rows affected (0.01 sec)
MariaDB [ApolloPortalDB]> truncate table App;
Query OK, 0 rows affected (0.01 sec)
MariaDB [ApolloPortalDB]> select * from AppNamespace;
Empty set (0.00 sec)
MariaDB [ApolloPortalDB]> select * from App;
Empty set (0.00 sec)
MariaDB [ApolloPortalDB]>
(2)应用portal的deployment.yaml资源配置清单
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)任意一台执行
portal的资源配置清单在之前的应用了,只是此节实验就把deployment给delete了,现在重新应用,前面已经修改了configmap
[root@mfyxw30 ~]# kubectl get pod -n infra
NAME READY STATUS RESTARTS AGE
dubbo-monitor-6676dd74cc-9hghb 1/1 Running 22 21d
dubbo-monitor-6676dd74cc-rd86g 1/1 Running 21 21d
jenkins-b99776c69-49dnr 1/1 Running 2 2d3h
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-portal/deployment.yaml
deployment.extensions/apollo-portal created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl get pod -n infra
NAME READY STATUS RESTARTS AGE
apollo-portal-57bc86966d-rgvs8 1/1 Running 0 25s
dubbo-monitor-6676dd74cc-9hghb 1/1 Running 22 21d
dubbo-monitor-6676dd74cc-rd86g 1/1 Running 21 21d
jenkins-b99776c69-49dnr 1/1 Running 2 2d3h
(3)浏览portal.od.com,可以看到是一个没有任何项目的了
9.分别在portal中创建二个项目和新增配置项
(1)添加dubbo-demo-service提供者项目
(2)添加dubbo-demo-service提供者的配置并发布
测试环境的配置并发布
新增配置
添加测试环境的配置项:dubbo.registry
添加测试环境的配置项:dubbo.port
单击发布
完成发布
生产环境的配置并发布
新增配置
添加生产环境的配置项:dubbo.registry
添加生产环境的配置项:dubbo.port
发布
成功分布
(3)添加dubbo-demo-web消费者项目
(4)添加dubbo-demo-web消费者的配置并发布
单击新增配置项(测试环境)
添加测试环境的配置项:dubbo.registry
单击发布
成功发布测试环境dubbo的服务消费者注册中心
单击新增配置项(生产环境)
添加生产环境的配置项:dubbo.registry
单击发布
成功发布生产环境dubbo的服务消费者注册中心
10.构建测试环境的dubbo-demo-service镜像
登录jenkins,构建dubbo-demo-service镜像
构建成功
11.交付测试环境的dubbo提供者
(1)创建测试环境的dubbo-demo-service资源配置清单
在运维主机mfyxw50.mfyxw.com上操作
deployment.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/test/dubbo-demo-service/deployment.yaml << EOF
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: dubbo-demo-service
namespace: test
labels:
name: dubbo-demo-service
spec:
replicas: 1
selector:
matchLabels:
name: dubbo-demo-service
template:
metadata:
labels:
app: dubbo-demo-service
name: dubbo-demo-service
spec:
containers:
- name: dubbo-demo-service
image: harbor.od.com/app/dubbo-demo-service:apollo_20200707_2136
ports:
- containerPort: 20880
protocol: TCP
env:
- name: JAR_BALL
value: dubbo-server.jar
- name: C_OPTS
value: -Denv=fat -Dapollo.meta=http://config-test.od.com
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
EOF
(2)应用测试环境的dubbo-demo-service资源配置清单
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)任意一节点执行
[root@mfyxw30 ~]# kubectl get pod -n test
NAME READY STATUS RESTARTS AGE
apollo-adminservice-5cccf97c64-ddjjc 1/1 Running 2 2d23h
apollo-configservice-5f6555448-qrj77 1/1 Running 2 2d23h
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/test/dubbo-demo-service/deployment.yaml
deployment.extensions/dubbo-demo-service created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl get pod -n test
NAME READY STATUS RESTARTS AGE
apollo-adminservice-5cccf97c64-ddjjc 1/1 Running 2 2d23h
apollo-configservice-5f6555448-qrj77 1/1 Running 2 2d23h
dubbo-demo-service-cc6b9d8c7-zm4sw 1/1 Running 0 13s
(3)修改dubbo-monitor的configmap
可以通过登录dashboard,找到infra名称空间,找到configmap来修改dubbo-monitor-cm的zookeeper指向测试环境
也可以通过资源配置清单来创建并应用
通过资源配置清单来创建
在运维主机mfyxw50.mfyxw.com上执行
[root@mfyxw50 ~]# cat > /data/k8s-yaml/dubbo-monitor/configmap.yaml << EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: dubbo-monitor-cm
namespace: infra
data:
dubbo.properties: |
dubbo.container=log4j,spring,registry,jetty
dubbo.application.name=simple-monitor
dubbo.application.owner=
dubbo.registry.address=zookeeper://zk-test.od.com:2181
dubbo.protocol.port=20880
dubbo.jetty.port=8080
dubbo.jetty.directory=/dubbo-monitor-simple/monitor
dubbo.charts.directory=/dubbo-monitor-simple/charts
dubbo.statistics.directory=/dubbo-monitor-simple/statistics
dubbo.log4j.file=/dubbo-monitor-simple/logs/dubbo-monitor.log
dubbo.log4j.level=WARN
EOF
应用dubbo-monitor资源配置清单
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)任意一台节点上执行即可
我前面的项目已经应用过了dubbo-monitor资源配置清单 ,所以,先删除再重新创建,接着把dubbo-monitor的pod删除,自动重新生成即可
[root@mfyxw30 ~]# kubectl delete -f http://k8s-yaml.od.com/dubbo-monitor/configmap.yaml
configmap "dubbo-monitor-cm" deleted
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/dubbo-monitor/configmap.yaml
configmap/dubbo-monitor-cm created
[root@mfyxw30 ~]# kubectl get pod -n infra
NAME READY STATUS RESTARTS AGE
apollo-portal-57bc86966d-khxvw 1/1 Running 1 2d18h
dubbo-monitor-6676dd74cc-tlrqz 1/1 Running 0 2m29s
jenkins-b99776c69-49dnr 1/1 Running 4 5d2h
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl delete pod dubbo-monitor-6676dd74cc-tlrqz -n infra
pod "dubbo-monitor-6676dd74cc-tlrqz" deleted
[root@mfyxw30 ~]# kubectl get pod -n infra
NAME READY STATUS RESTARTS AGE
apollo-portal-57bc86966d-khxvw 1/1 Running 1 2d19h
dubbo-monitor-6676dd74cc-7bq9j 1/1 Running 0 18m
jenkins-b99776c69-49dnr 1/1 Running 4 5d3h
(4)登录dubbo-monitor查看下测试环境dubbo-demo-service
12.构建测试环境的dubbo消费都镜像
测试环境的消费者构建成功
13.创建测试环境的dubbo消费者的资源配置清单并应用
(1)创建测试环境的dubbo消费者的资源配置清单
在运维主机mfyxw50.mfyxw.com上执行
deployment.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/test/dubbo-demo-consumer/deployment.yaml << EOF
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: dubbo-demo-consumer
namespace: test
labels:
name: dubbo-demo-consumer
spec:
replicas: 1
selector:
matchLabels:
name: dubbo-demo-consumer
template:
metadata:
labels:
app: dubbo-demo-consumer
name: dubbo-demo-consumer
spec:
containers:
- name: dubbo-demo-consumer
image: harbor.od.com/app/dubbo-demo-consumer:apollo_20200713_1714
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 20880
protocol: TCP
env:
- name: JAR_BALL
value: dubbo-client.jar
- name: C_OPTS
value: -Denv=fat -Dapollo.meta=http://config-test.od.com
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
securityContext:
runAsUser: 0
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
EOF
service.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/test/dubbo-demo-consumer/service.yaml << EOF
kind: Service
apiVersion: v1
metadata:
name: dubbo-demo-consumer
namespace: test
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8080
selector:
app: dubbo-demo-consumer
clusterIP: None
type: ClusterIP
sessionAffinity: None
EOF
Ingress.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/test/dubbo-demo-consumer/Ingress.yaml << EOF
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: dubbo-demo-consumer
namespace: test
spec:
rules:
- host: demo-test.od.com
http:
paths:
- path: /
backend:
serviceName: dubbo-demo-consumer
servicePort: 8080
EOF
(2)应用测试环境的dubbo消费者的资源配置清单
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)任意一台节点上执行即可
[root@mfyxw30 ~]# kubectl get pod -n test
NAME READY STATUS RESTARTS AGE
apollo-adminservice-5cccf97c64-ddjjc 1/1 Running 2 3d1h
apollo-configservice-5f6555448-qrj77 1/1 Running 2 3d1h
dubbo-demo-service-cc6b9d8c7-h2rdx 1/1 Running 0 82m
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/test/dubbo-demo-consumer/deployment.yaml
deployment.extensions/dubbo-demo-consumer created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/test/dubbo-demo-consumer/service.yaml
service/dubbo-demo-consumer created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/test/dubbo-demo-consumer/Ingress.yaml
ingress.extensions/dubbo-demo-consumer created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl get pod -n test
NAME READY STATUS RESTARTS AGE
apollo-adminservice-5cccf97c64-ddjjc 1/1 Running 2 3d1h
apollo-configservice-5f6555448-qrj77 1/1 Running 2 3d1h
dubbo-demo-consumer-68466fb764-k2t47 1/1 Running 0 28s
dubbo-demo-service-cc6b9d8c7-h2rdx 1/1 Running 0 83m
(3)登录dubbo-monitor查看,dubbo-demo-consumer是否已经注册了
14.访问dubbo消费者
备注:现已经把测试环境的dubbo提供者和消费者已经交付到k8s集群,测试人员会对此版本进行测试,如没有问题,则可以将此版本镜像交付到生产环境。
15.将测试环境的dubbo提供者和消费者交付到生产环境
分别将dubbo提供者和消费者的资源配置清单复制一份至生产环境
在运维主机mfyxw50.mfyxw.com上执行
(1)创建或修改dubbo提供者的资源配置清单
deployment.yaml文件内容如下:
[root@mfyxw50 ~]# cat > /data/k8s-yaml/prod/dubbo-demo-service/deployment.yaml << EOF
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: dubbo-demo-service
namespace: prod
labels:
name: dubbo-demo-service
spec:
replicas: 1
selector:
matchLabels:
name: dubbo-demo-service
template:
metadata:
labels:
app: dubbo-demo-service
name: dubbo-demo-service
spec:
containers:
- name: dubbo-demo-service
image: harbor.od.com/app/dubbo-demo-service:apollo_20200707_2136
ports:
- containerPort: 20880
protocol: TCP
env:
- name: JAR_BALL
value: dubbo-server.jar
- name: C_OPTS
value: -Denv=pro -Dapollo.meta=http://config-prod.od.com
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
EOF
(2)创建或修改dubbo消费者的资源配置清单
deployment.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/prod/dubbo-demo-consumer/deployment.yaml << EOF
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: dubbo-demo-consumer
namespace: prod
labels:
name: dubbo-demo-consumer
spec:
replicas: 1
selector:
matchLabels:
name: dubbo-demo-consumer
template:
metadata:
labels:
app: dubbo-demo-consumer
name: dubbo-demo-consumer
spec:
containers:
- name: dubbo-demo-consumer
image: harbor.od.com/app/dubbo-demo-consumer:apollo_20200713_1714
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 20880
protocol: TCP
env:
- name: JAR_BALL
value: dubbo-client.jar
- name: C_OPTS
value: -Denv=pro -Dapollo.meta=http://config-prod.od.com
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
securityContext:
runAsUser: 0
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
EOF
Ingress.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/prod/dubbo-demo-consumer/Ingress.yaml << EOF
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: dubbo-demo-consumer
namespace: prod
spec:
rules:
- host: demo-prod.od.com
http:
paths:
- path: /
backend:
serviceName: dubbo-demo-consumer
servicePort: 8080
EOF
service.yaml文件内容如下
[root@mfyxw50 ~]# cat > /data/k8s-yaml/prod/dubbo-demo-consumer/service.yaml << EOF
kind: Service
apiVersion: v1
metadata:
name: dubbo-demo-consumer
namespace: prod
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8080
selector:
app: dubbo-demo-consumer
clusterIP: None
type: ClusterIP
sessionAffinity: None
EOF
(3)应用dubbo提供者和消费者资源配置清单
在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)任意一台节点上执行即可
[root@mfyxw30 ~]# kubectl get pod -n prod
NAME READY STATUS RESTARTS AGE
apollo-adminservice-5cccf97c64-dvlfx 1/1 Running 2 3d
apollo-configservice-5f6555448-7kj46 1/1 Running 2 3d
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/prod/dubbo-demo-service/deployment.yaml
deployment.extensions/dubbo-demo-service created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/prod/dubbo-demo-consumer/deployment.yaml
deployment.extensions/dubbo-demo-consumer created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/prod/dubbo-demo-consumer/service.yaml
service/dubbo-demo-consumer created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/prod/dubbo-demo-consumer/Ingress.yaml
ingress.extensions/dubbo-demo-consumer created
[root@mfyxw30 ~]#
[root@mfyxw30 ~]# kubectl get pod -n prod
NAME READY STATUS RESTARTS AGE
apollo-adminservice-5cccf97c64-dvlfx 1/1 Running 2 3d
apollo-configservice-5f6555448-7kj46 1/1 Running 2 3d
dubbo-demo-consumer-85c9c67947-f67nh 1/1 Running 0 16s
dubbo-demo-service-bf45dcbbb-qfrzs 1/1 Running 0 24s