k8s 交付配置中心Apollo day05
vi cm.yamliapiVersion: v1kind: ConfigMapmetadata:name: dubbo-monitor-cmnamespace: infradata:dubbo.properties: |dubbo.container=log4j,spring,registry,jettydubbo.application.name=...
回顾
一个集群里,消费者去服务端拿接口,走的是pod网络,pod ip之间就不要绕弯子,所以要每台宿主机上 snat 优化。
所以服务端只需要一个dp.yaml 的资源。
conf]# kubectl create cm kubelet-cm --from-file=./kubelet.kubeconfig
## 快速生成一个cm 类型的资源
交付apollo-configservice
官网地址:https://github.com/ctripcorp/apollo, 使用 Apollo v1.5.1 Release。
dubbot 服务交付到两个环境,测试环境和生产环境。
安装部署mysql数据库
在数据库主机 hdss7-11.host.com 上
注意:mysql 版本应为5.6 或以上,用mariadb的话用10.1 以上
vi /etc/yum.repos.d/MariaDB.repo
i[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.1/centos7-amd64/
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
# 导入gpg-key
rpm --import https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
yum list mariadb-server --show-duplicates
~]# yum install MariaDB-server -y
vi /etc/my.cnf
i[mysql]
default-character-set = utf8mb4
[mysqld]
character_set_server = utf8mb4
collation_server = utf8mb4_general_ci
init_connect = "SET NAMES 'utf8mb4'"
systemctl start mariadb
systemctl enable mariadb
mysqladmin -u root password
123456
123456
\s 确认都是utf-8mb4
drop database test;
exit
执行数据库脚本
~]# wget wget https://github.com/ctripcorp/apollo/blob/v1.5.1/scripts/db/migration/configdb/V1.0.0__initialization.sql -O apolloconfig.sql
mysql -uroot -p < apolloconfig.sql
数据库用户授权
grant INSERT,DELETE,UPDATE,SELECT on ApolloConfigDB.* to "apolloconfig"@"10.4.7.%" identified by "123456";
# 除了运算节点的pod 自己通信用pod 网络,出来的就要走node网络,用snat,带上面具了要。
修改初始命令
> update ApolloConfigDB.ServerConfig set ServerConfig.Value="http://config.od.com/eureka" where ServerConfig.Key="eureka.service.url";
解析这个域名
config A 10.4.7.10
制作docker 镜像
mkdir /data/dockerfile/apollo-configservice
src]# unzip -o apollo-configservice-1.5.1-github.zip -d /data/dockerfile/apollo-configservice
解析这个域名
mysql A 10.4.7.11
cd /data/dockerfile/apollo-configservice
vi application-github.properties
## https://github.com/ctripcorp/apollo/blob/v1.5.1/scripts/apollo-on-kubernetes/apollo-config-server/scripts/startup-kubernetes.sh
vi startup.sh
# 多了这一行
APOLLO_CONFIG_SERVICE_NAME=$(hostname -i)
# 调整jvm 内存
FROM stanleyws/jre8:8u112
ENV VERSION 1.5.1
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\
echo "Asia/Shanghai" > /etc/timezone
ADD apollo-configservice-${VERSION}.jar /apollo-configservice/apollo-configservice.jar
ADD config/ /apollo-configservice/config
ADD scripts/ /apollo-configservice/scripts
CMD ["/apollo-configservice/scripts/startup.sh"]
# docker build . -t harbor.od.com/infra/apollo-configservice:v1.5.1
资源配置清单
configservice 提供http接口;
admin 不提供http;
portal 提供http;
cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: apollo-configservice-cm
namespace: infra
data:
application-github.properties: |
# DataSource
spring.datasource.url = jdbc:mysql://mysql.od.com:3306/ApolloConfigDB?characterEncoding=utf8
spring.datasource.username = apolloconfig
spring.datasource.password = 123456
eureka.service.url = http://config.od.com/eureka
app.properties: |
appId=100003171
dp.yaml
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: apollo-configservice
namespace: infra
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
svc.yaml
kind: Service
apiVersion: v1
metadata:
name: apollo-configservice
namespace: infra
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8080
selector:
app: apollo-configservice
ingress.yaml
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: apollo-configservice
namespace: infra
spec:
rules:
- host: config.od.com
http:
paths:
- path: /
backend:
serviceName: apollo-configservice
servicePort: 8080
apollo-adminservice 制作docker 镜像
先交付config service,再交付admin server。
mkdir /data/dockerfile/apollo-adminserveice
unzip -o apollo-adminservice-1.5.1-github.zip -d /data/dockerfile/apollo-adminserveice
vi startup.sh
SERVER_PORT=8080
APOLLO_ADMIN_SERVICE_NAME=$(hostname -i)
cd /data/dockerfile/apollo-adminserveice
vi Dockerfile
FROM stanleyws/jre8:8u112
ENV VERSION 1.5.1
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\
echo "Asia/Shanghai" > /etc/timezone
ADD apollo-adminservice-${VERSION}.jar /apollo-adminservice/apollo-adminservice.jar
ADD config/ /apollo-adminservice/config
ADD scripts/ /apollo-adminservice/scripts
CMD ["/apollo-adminservice/scripts/startup.sh"]
docker build . -t harbor.od.com/infra/apollo-adminservice:v1.5.1
docker push !$
交付apollo-adminservice到k8s集群
vi cm.yaml
iapiVersion: v1
kind: ConfigMap
metadata:
name: apollo-adminservice-cm
namespace: infra
data:
application-github.properties: |
# DataSource
spring.datasource.url = jdbc:mysql://mysql.od.com:3306/ApolloConfigDB?characterEncoding=utf8
spring.datasource.username = apolloconfig
spring.datasource.password = 123456
eureka.service.url = http://config.od.com/eureka
app.properties: |
appId=100003172
vi dp.yaml
ikind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: apollo-adminservice
namespace: infra
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
admin 比config 快一些,
configservice这个组件,里面集成了eureka,启动的时候要先启动eureka再启动configservice
curl 172.7.22.5:8080/info
交付apollo-portal,数据库初始化
初始化portal.db
> source ./apolloportal.sql
> grant INSERT,DELETE,UPDATE,SELECT on ApolloPortalDB.* to "apolloportal"@"10.4.7.%" identified by "123456";
> update ServerConfig set Value='[{"orgId":"od01","orgName":"Linux学院"},{"orgId":"od02","orgName":"云计算学院"},{"orgId":"od03","orgName":"Python学院"}]' where Id=2;
> select user,host from mysql.user;
制作apollo-portal 的docker镜像
配置portal的meta service
vi /data/dockerfile/apollo-portal/config/apollo-env.aproperties
# portal连接的环境列表
# 一套配置中心,管理不同的环境
# 放到cm里,不用改这个配置文件
# 更新startup.sh,以下是和管网差异部分
SERVER_PORT=8080
APOLLO_PORTAL_SERVICE_NAME=$(hostname -i)
vi Dockerfile
iFROM stanleyws/jre8:8u112
ENV VERSION 1.5.1
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\
echo "Asia/Shanghai" > /etc/timezone
ADD apollo-portal-${VERSION}.jar /apollo-portal/apollo-portal.jar
ADD config/ /apollo-portal/config
ADD scripts/ /apollo-portal/scripts
CMD ["/apollo-portal/scripts/startup.sh"]
docker build . -t harbor.od.com/infra/apollo-portal:v1.5.1
docker push !$
制作apollo-portal 的资源配置清单
mkdir apollo-portal
vi cm.yaml
iapiVersion: 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: |
dev.meta=http://config.od.com
vi dp.yaml
ikind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: apollo-portal
namespace: infra
labels:
name: apollo-portal
spec:
replicas: 1
selector:
matchLabels:
name: apollo-portal
template:
metadata:
labels:
app: apollo-portal
name: apollo-portal
spec:
volumes:
- name: configmap-volume
configMap:
name: apollo-portal-cm
containers:
- name: apollo-portal
image: harbor.od.com/infra/apollo-portal:v1.5.1
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- name: configmap-volume
mountPath: /apollo-portal/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
vi svc.yaml
ikind: Service
apiVersion: v1
metadata:
name: apollo-portal
namespace: infra
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8080
selector:
app: apollo-portal
vi ingress.yaml
ikind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: apollo-portal
namespace: infra
spec:
rules:
- host: portal.od.com
http:
paths:
- path: /
backend:
serviceName: apollo-portal
servicePort: 8080
portal A 10.4.7.10
user: apollo
passwd: admin
dubbo服务提供者连接apollo实战
查看源码,看需要新增什么配置
用这个配置项,就要重新打一版镜像,用jenkins
cd /data/nfs-volumes/jenkins_home
cd maven-3.6.1-8u232/conf/
vi setting.xml
/mirror
做好镜像之后,修改dp资源清单的镜像。
- name: C_OPTS
value: -Denv=dev -Dapollo.meta=http://config.od.com
连接到apollo的参数是C_OPS
dubbo服务消费者连接apollo实战
apollo 分环境实战
1、添加域名解析
2、把dp设置成0
3、创建名称空间
portal服务可以个环境公用,config service 和admin service 需要每个环境个有一套。
先把之前的环境dp设置为0.先都关了
4、修改数据库
> update ApolloConfigTestDB.ServerConfig set ServerConfig.Value="http://config-test.od.com/eureka" where ServerConfig.Key="eureka.service.url";
> update ApolloConfigProdDB.ServerConfig set ServerConfig.Value="http://config-prod.od.com/eureka" where ServerConfig.Key="eureka.service.url";
> grant INSERT,DELETE,UPDATE,SELECT on ApolloConfigTestDB.* to "apolloconfig"@"10.4.7.%" identified by "123456";
> grant INSERT,DELETE,UPDATE,SELECT on ApolloConfigProdDB.* to "apolloconfig"@"10.4.7.%" identified by "123456";
[ApolloPortalDB]> update ServerConfig set Value='fat,pro' where Id=1;
# 设置apollo支持的环境
5、修改portal的cm
## 只修改这里,然后应用
cm.yaml
apollo-env.properties: |
fat.meta=http://config-test.od.com
pro.meta=http://config-prod.od.com
6、创建yaml资源清单
修改资源清单namespace等;
7、两个名称空间的service都起来,就可以起portal了。
先吧portal里原来的app表清了
dubbo连接apollo到不同环境实战
1、创建服务端项目
有修改,要先发布一个版本,再去改pro的
2、创建消费者项目
3、项目发布
先去发布test环境的dubbo-demo-service
然后去新增域名解析
直接用svc的短域名,走8080,不走ingress,因为dubbo-demo-service和config service 都在一个k8s集群的同一名称空间。不在同一名称空间的话,就加上.名称空间
项目提测,发布流程
更新代码,构建
不用重新打包了。
更多推荐
所有评论(0)