configMap管理应用配置
deployment缩容副本集为0
[root@ceshi-130 ~]# kubectl scale --replicas=0 deployment/dubbo-demo-consumer -n app
deployment.extensions/dubbo-demo-consumer scaled
[root@ceshi-130 ~]# kubectl scale --replicas=0 deployment/dubbo-demo-service -n app
deployment.extensions/dubbo-demo-service scaled
[root@ceshi-130 ~]# kubectl scale --replicas=0 deployment/dubbo-monitor -n infra
deployment.extensions/dubbo-monitor scaled
配置2台zk(测试/生产)
节点128 129(两台单机版zk,分别用来注册生产/测试环境)
测试
[root@ceshi-128 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
生产
[root@ceshi-129 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
资源配置清单(dubbo-monitor)
节点 132
[root@ceshi-132 dubbo-monitor]# cat cm.yaml
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=boy
dubbo.registry.address=zookeeper://zk1.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
[root@ceshi-132 dubbo-monitor]# cat dp.yaml
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: dubbo-monitor
namespace: infra
labels:
name: dubbo-monitor
spec:
replicas: 1
selector:
matchLabels:
name: dubbo-monitor
template:
metadata:
labels:
app: dubbo-monitor
name: dubbo-monitor
spec:
containers:
- name: dubbo-monitor
image: harbor.od.com/infra/dubbo-monitor:latest
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 20880
protocol: TCP
imagePullPolicy: IfNotPresent
-------------------------------------------------------
volumeMounts: 挂载
- name: configmap-volume 挂载名
mountPath: /dubbo-monitor-simple/conf 挂载路径
volumes:
- name: configmap-volume 卷
configMap: 配置类型
name: dubbo-monitor-cm 卷名
-------------------------------------------------------
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
对于比较复杂格式不太规范,陈述式资源管理方法配置configmap
创建
[root@ceshi-130 conf]# kubectl create cm test-config --from-file=./msg.properties
configmap/test-config created
[root@ceshi-130 conf]# kubectl get cm
NAME DATA AGE
his-config 1 3m22s
kubelet-configmap 1 9m45s
test-config 1 5s
yaml格式查看
[root@ceshi-130 conf]# kubectl get cm test-config -o yaml
apiVersion: v1
data:
msg.properties: "#hl7 message\r\nmsg.send.switch=0\r\n#send msg use mq\r\nmsg.send.mq=0\r\n##Send
message server settings\r\nmsg.send.host=127.0.0.1\r\nmsg.send.port=2100\r\n##timeout
set\r\nmsg.send.timeout=1000\r\n#real time\r\nmsg.send.rt=1\r\n#save hl7 file\r\nmsg.save.file=1\r\n#msg
save path\r\nmsg.save.path=c://hl7//\r\n#custom message separator\r\nmsg.split.char=#\r\n#message
separator num\r\nmsg.split.num=100\r\n\r\nmsg.send.sendSize=3000\r\n\r\n#webservice\\u670d\\u52a1\\u5730\\u5740\r\ndict.address=http\\://192.168.2.52\\:7004/Dictaderjc/oyevcWritMgrxSrie?wsdl\r\nserviceClass,service\\u5b9e\\u73b0\\u7c7b\\u7684@Service\\u6ce8\\u89e3\\u540d\\u79f0\r\nmsg.processClass=OlaFrSndService\r\n\r\n"
kind: ConfigMap
metadata:
creationTimestamp: "2021-09-09T03:44:59Z"
name: test-config
namespace: default
resourceVersion: "4192332"
selfLink: /api/v1/namespaces/default/configmaps/test-config
uid: cc94a324-f9f9-47cf-b878-3865a4bf8d18
应用配置
节点 130
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/dubbo-monitor/cm.yaml
configmap/dubbo-monitor-cm created
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/dubbo-monitor/dp.yaml
deployment.extensions/dubbo-monitor configured
配置字典
configMap(专用来集中管理应用的配置)
类似将配置文件提前输出然后挂载到容器指定的配置路径使其生效,进入容器后查看mountPath路径中的文件和cm.yaml中data.dubbo.properties中配置一致
[root@ceshi-130 ~]# kubectl exec -it dubbo-monitor-6676dd74cc-26gtg bash -n infra
bash-4.3# cd dubbo-monitor-simple/conf/
bash-4.3# cat dubbo.properties
dubbo.container=log4j,spring,registry,jetty
dubbo.application.name=simple-monitor
dubbo.application.owner=boy
dubbo.registry.address=zookeeper://zk1.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
apollo安装配置
安装MySQL
节点 128 版本> 5.6
传送门:初始化configdb
传送门:初始化portaldb
[root@ceshi-128 ~]# cat /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/
gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
[root@ceshi-128 ~]# yum install MariaDB-server -y
设置字符集
[root@ceshi-128 ~]# vi /etc/my.cnf
[mysqld]
character_set_server = utf8mb4
collation_server = utf8mb4_general_ci
init_connect = "SET NAMES 'utf8mb4'"
[root@ceshi-128 ~]# vi /etc/my.cnf.d/mysql-clients.cnf
[mysql]
default-character-set = utf8mb4
启动服务
[root@ceshi-128 ~]# systemctl start mariadb
[root@ceshi-128 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
设置密码
[root@ceshi-128 ~]# mysqladmin -u root password
New password:
Confirm new password:
导入初始化脚本
[root@ceshi-128 ~]# mysql -u root -p < V1.0.0__initialization.sql
Enter password:
授权用户
MariaDB [ApolloConfigDB]> grant insert,delete,update,select on ApolloConfigDB.* to 'apolloconfig'@'10.1.133.%' identified by 'linux';
Query OK, 0 rows affected (0.002 sec)
修改数据库eureka.service.url为域名,为了让ingress识别
MariaDB [ApolloConfigDB]> update ApolloConfigDB.ServerConfig set ServerConfig.Value="http://config.od.com/eureka" where ServerConfig.Key='eureka.service.url';
Query OK, 1 row affected (0.003 sec)
Rows matched: 1 Changed: 1 Warnings: 0
添加DNSconfig.od.com域名解析
[root@ceshi-128 ~]# vi /var/named/od.com.zone
config A 10.1.133.94
[root@ceshi-128 ~]# systemctl restart named
安装apollo
传送门:apollo三件套
节点 132
1. 安装configservice
下载
[root@ceshi-132 ~]# wget https://github.com/apolloconfig/apollo/releases/download/v1.5.1/apollo-adminservice-1.5.1-github.zip
[root@ceshi-132 ~]# wget https://github.com/apolloconfig/apollo/releases/download/v1.5.1/apollo-configservice-1.5.1-github.zip
[root@ceshi-132 ~]# wget https://github.com/apolloconfig/apollo/releases/download/v1.5.1/apollo-portal-1.5.1-github.zip
解压
[root@ceshi-132 ~]# mkdir /data/dockerfile/apollo-cconfigserver
[root@ceshi-132 ~]# unzip -o apollo-configservice-1.5.1-github.zip -d /data/dockerfile/apollo-cconfigserver/
修改数据库连接地址
[root@ceshi-132 config]# vi /data/dockerfile/apollo-cconfigserver/config/application-github.properties
spring.datasource.url = jdbc:mysql://mysql.od.com:3306/ApolloConfigDB?characterEncoding=utf8
spring.datasource.username = apolloConfig
spring.datasource.password = linux
替换官网使用的startup-kubernetes.sh脚本
apollo/scripts/apollo-on-kubernetes/apollo-config-server/scripts/startup-kubernetes.sh
新增一行
APOLLO_CONFIG_SERVICE_NAME=$(hostname -i)
!!!替换startup.sh脚本,用原有的脚本容器起不来
传送门:修改后启动脚本
创建dockerfile
dockerfile
[root@ceshi-132 apollo-cconfigserver]# cat Dockerfile
FROM harbor.od.com/base/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"]
构建
[root@ceshi-132 apollo-cconfigserver]# docker build -t harbor.od.com/infra/apollo-configservice:v1.5.1 .
Sending build context to Docker daemon 62MB
Step 1/7 : FROM harbor.od.com/base/jre8:8u112
---> 7f36e75aac28
Step 2/7 : ENV VERSION 1.5.1
---> Running in 3b46a2979202
Removing intermediate container 3b46a2979202
---> d3b00d8b1303
Step 3/7 : RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
---> Running in 0e8d2998eab2
Removing intermediate container 0e8d2998eab2
---> a2f12a980e83
Step 4/7 : ADD apollo-configservice-${VERSION}.jar /apollo-configservice/apollo-configservice.jar
---> 1edb309e318a
Step 5/7 : ADD config/ /apollo-configservice/config
---> 353b9cb9001e
Step 6/7 : ADD scripts/ /apollo-configservice/scripts
---> 2fd958075524
Step 7/7 : CMD ["/apollo-configservice/scripts/startup.sh"]
---> Running in fdecf51ab421
Removing intermediate container fdecf51ab421
---> b456c112e963
Successfully built b456c112e963
Successfully tagged harbor.od.com/infra/apollo-configservice:v1.5.1
提交仓库
[root@ceshi-132 apollo-cconfigserver]# docker push harbor.od.com/infra/apollo-configservice:v1.5.1
The push refers to repository [harbor.od.com/infra/apollo-configservice]
b766522b9581: Pushed
070b171cd88d: Pushed
创建资源配置清单
[root@ceshi-132 apollo-cconfigserver]# cd /data/k8s-yaml/
[root@ceshi-132 k8s-yaml]# mkdir apollo-configservice
[root@ceshi-132 k8s-yaml]# cd apollo-configservice/
service
[root@ceshi-132 apollo-configservice]# cat svc.yaml
kind: Service
apiVersion: v1
metadata:
name: apollo-configservice
namespace: infra
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8080
selector:
app: apollo-configservice
deployment
[root@ceshi-132 apollo-configservice]# cat 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
ingress
[root@ceshi-132 apollo-configservice]# cat 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
configmap
[root@ceshi-132 apollo-configservice]# cat 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 = linux
eureka.service.url = http://config.od.com/eureka
app.properties: |
appId=100003171
交付
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-configservice/cm.yaml
configmap/apollo-configservice-cm created
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-configservice/dp.yaml
deployment.extensions/apollo-configservice created
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-configservice/svc.yaml
service/apollo-configservice created
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-configservice/ingress.yaml
ingress.extensions/apollo-configservice created
2. 安装adminservice
传送门:修改后启动脚本
[root@ceshi-132 ~]# unzip apollo-adminservice-1.5.1-github.zip -d /data/dockerfile/apollo-adminservice/
修改项
SERVER_PORT=8080
APOLLO_ADMIN_SERVICE_NAME=$(hostname -i)
!!!替换startup.sh脚本,用原有的脚本容器起不来
创建dockerfile
[root@ceshi-132 apollo-adminservice]# cat Dockerfile
FROM harbor.od.com/base/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"]
构建
[root@ceshi-132 apollo-adminservice]# docker build -t harbor.od.com/infra/apollo-adminservice:v1.5.1 .
Sending build context to Docker daemon 58.37MB
Step 1/7 : FROM harbor.od.com/base/jre8:8u112
---> 7f36e75aac28
Step 2/7 : ENV VERSION 1.5.1
---> Using cache
---> d3b00d8b1303
Step 3/7 : RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
---> Using cache
---> a2f12a980e83
Step 4/7 : ADD apollo-adminservice-${VERSION}.jar /apollo-adminservice/apollo-adminservice.jar
---> Using cache
---> 428b4d63a24a
Step 5/7 : ADD config/ /apollo-adminservice/config
---> Using cache
---> b83cec197ec9
Step 6/7 : ADD scripts/ /apollo-adminservice/scripts
---> Using cache
---> 0d68eac40cbc
Step 7/7 : CMD ["/apollo-adminservice/scripts/startup.sh"]
---> Using cache
---> 3c28c0492238
Successfully built 3c28c0492238
Successfully tagged harbor.od.com/infra/apollo-adminservice:v1.5.1
[root@ceshi-132 apollo-adminservice]# docker push harbor.od.com/infra/apollo-adminservice:v1.5.1
The push refers to repository [harbor.od.com/infra/apollo-adminservice]
de938321b1b9: Pushed
5b3ee80237bd: Pushed
57dbdfbc6a4e: Pushed
创建资源配置清单
[root@ceshi-132 k8s-yaml]# mkdir apollp-adminservice
[root@ceshi-132 k8s-yaml]# cd apollo-adminservice/
configmap
[root@ceshi-132 apollo-adminservice]# cat cm.yaml
apiVersion: 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 = linux
eureka.service.url = http://config.od.com/eureka
app.properties: |
appId=100003172
deployment
[root@ceshi-132 apollo-adminservice]# cat dp.yaml
kind: 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: 8090
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
交付
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-adminservice/cm.yaml
configmap/apollo-adminservice-cm created
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-adminservice/dp.yaml
deployment.extensions/apollo-adminservice created
2. 安装portal
传送门:初始化sql
[root@ceshi-128 ~]# mysql -u root -p < portaldb.sql
Enter password:
授权用户
MariaDB [ApolloPortalDB]> grant insert,select,delete,update on ApolloPortalDB.* to 'ApolloPortal'@'10.1.133.%' identified by 'linux';
Query OK, 0 rows affected (0.002 sec)
MariaDB [ApolloPortalDB]> update ServerConfig set Value='[{"orgId":"boy01","orgName":"ceshi1"},{"orgId":"TEST2","boy02":"ceshi2"}]' where Id=2
创建dockerfile
[root@ceshi-132 apollo-portal]# cat Dockerfile
FROM harbor.od.com/base/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"]
构建
[root@ceshi-132 apollo-portal]# docker build . -t harbor.od.com/infra/apollo-portal:v1.5.1
Sending build context to Docker daemon 42.35MB
Step 1/7 : FROM harbor.od.com/base/jre8:8u112
---> 7f36e75aac28
Step 2/7 : ENV VERSION 1.5.1
---> Using cache
---> d3b00d8b1303
Step 3/7 : RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
---> Using cache
---> a2f12a980e83
Step 4/7 : ADD apollo-portal-${VERSION}.jar /apollo-portal/apollo-portal.jar
---> 85400ad84e91
Step 5/7 : ADD config/ /apollo-portal/config
---> b9960bb50d06
Step 6/7 : ADD scripts/ /apollo-portal/scripts
---> ac767c453086
Step 7/7 : CMD ["/apollo-portal/scripts/startup.sh"]
---> Running in a39734ef093b
Removing intermediate container a39734ef093b
---> 519f9cc7243a
Successfully built 519f9cc7243a
Successfully tagged harbor.od.com/infra/apollo-portal:v1.5.1
[root@ceshi-132 apollo-portal]# docker push harbor.od.com/infra/apollo-portal:v1.5.1
The push refers to repository [harbor.od.com/infra/apollo-portal]
35a0e6130ff2: Pushed
fe303f90ec07: Pushed
创建资源配置清单
[root@ceshi-132 k8s-yaml]# mkdir apollo-portal
[root@ceshi-132 k8s-yaml]# cd apollo-portal/
configmap
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 = linux
app.properties: |
appId=100003173
apollo-env.properties: |
dev.meta=http://config.od.com dev(测试环境url)
deployment
kind: 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: 8070
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
service
kind: Service
apiVersion: v1
metadata:
name: apollo-portal
namespace: infra
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8070
selector:
app: apollo-portal
ingress
kind: 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
交付
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-portal/cm.yaml
configmap/apollo-portal-cm created
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-portal/dp.yaml
deployment.extensions/apollo-portal created
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-portal/svc.yaml
service/apollo-portal created
[root@ceshi-130 ~]# kubectl apply -f http://k8s-yaml.od.com/apollo-portal/ingress.yaml
ingress.extensions/apollo-portal created
修改NDS
[root@ceshi-128 ~]# vi /var/named/od.com.zone
portal A 10.1.133.94
[root@ceshi-128 ~]# systemctl restart named
区分环境
创建test/prod名称空间
[root@ceshi-130 kube-scheduler]# kubectl create ns test
namespace/test created
授权私有仓库
[root@ceshi-130 kube-scheduler]# kubectl create secret docker-registry harbor --docker-server=harbor.od.com --docker-username=admin --docker-password=12345 -n test
secret/harbor created
[root@ceshi-130 kube-scheduler]# kubectl create ns prod
namespace/prod created
[root@ceshi-130 kube-scheduler]# kubectl create secret docker-registry harbor --docker-server=harbor.od.com --docker-username=admin --docker-password=12345 -n prod
secret/harbor created
交付apollo到K8S,不同的环境各自有apollo-adminservice和apollo-configservice插件
测试环境
修改原初始化sql新建表ApolloConfigTestDB
[root@ceshi-128 ~]# vi V1.0.0__initialization.sql
CREATE DATABASE IF NOT EXISTS ApolloConfigTestDB DEFAULT CHARACTER SET = utf8mb4;
Use ApolloConfigTestDB;
更新数据库配置
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.015 sec)
Rows matched: 1 Changed: 1 Warnings: 0
授权
MariaDB [ApolloConfigProdDB]> grant insert,select,delete,update on ApolloConfigTestDB.* to 'apolloconfig'@'10.1.133.%' identified by 'linux';
Query OK, 0 rows affected (0.003 sec)
生产环境
修改原初始化sql新建表ApolloConfigProdDB
[root@ceshi-128 ~]# vi V1.0.0__initialization.sql
CREATE DATABASE IF NOT EXISTS ApolloConfigProdDB DEFAULT CHARACTER SET = utf8mb4;
Use ApolloConfigProdDB ;
更新数据库配置
MariaDB [ApolloConfigTestDB]> update ApolloConfigProdDB.ServerConfig set ServerConfig.Value="http://config-prod.od.com/eureka" where ServerConfig.Key="eureka.service.url";
Query OK, 1 row affected (0.015 sec)
Rows matched: 1 Changed: 1 Warnings: 0
授权
MariaDB [ApolloConfigProdDB]> grant insert,select,delete,update on ApolloConfigProdDB.* to 'apolloconfig'@'10.1.133.%' identified by 'linux';
Query OK, 0 rows affected (0.019 sec)
修改ApolloPortalDB可支持列表加入不同环境
MariaDB [ApolloPortalDB]> update ApolloPortalDB.ServerConfig set Value='fat,pro' where Id=1;
修改portal configmap配置
apollo-env.properties: |
fat.meta=http://config-test.od.com
pro.meta=http://config-prod.od.com
重新加载配置
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/apollo-portal/cm.yaml
configmap/apollo-portal-cm configured
test资源配置文件
apollo-configservice
[root@ceshi-132 apollo-portal]# mkdir -p /data/k8s-yaml/test/{apollo-adminservice,apollo-configservice,dubbo-demo-server,dubbo-demo-consumer}
[root@ceshi-132 apollo-portal]# mkdir -p /data/k8s-yaml/prod/{apollo-adminservice,apollo-configservice,dubbo-demo-server,dubbo-demo-consumer}
[root@ceshi-132 test]# cd apollo-configservice/
[root@ceshi-132 apollo-configservice]# cp /data/k8s-yaml/apollo-configservice/* .
修改各配置文件namespace为test
[root@ceshi-132 apollo-configservice]# vi cm.yaml
[root@ceshi-132 apollo-configservice]# vi dp.yaml
[root@ceshi-132 apollo-configservice]# vi ingress.yaml
[root@ceshi-132 apollo-configservice]# vi svc.yaml
增加DNS
config-test A 10.1.133.94
config-prod A 10.1.133.94
交付文件
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-configservice/cm.yaml
configmap/apollo-configservice-cm created
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-configservice/dp.yaml
deployment.extensions/apollo-configservice created
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-configservice/svc.yaml
service/apollo-configservice created
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-configservice/ingress.yaml
ingress.extensions/apollo-configservice created
apollo-adminservice
[root@ceshi-132 apollo-adminservice]# cp /data/k8s-yaml/apollo-adminservice/*.yaml .
修改namespace名称test
[root@ceshi-132 apollo-adminservice]# vi cm.yaml
[root@ceshi-132 apollo-adminservice]# vi dp.yaml
交付
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-adminservice/cm.yaml
configmap/apollo-adminservice-cm created
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/test/apollo-adminservice/dp.yaml
deployment.extensions/apollo-adminservice created
prod资源配置文件
[root@ceshi-132 apollo-configservice]# cp ../../test/apollo-configservice/* .
修改各配置文件namespace为prod
[root@ceshi-132 apollo-configservice]# vi cm.yaml
[root@ceshi-132 apollo-configservice]# vi dp.yaml
[root@ceshi-132 apollo-configservice]# vi ingress.yaml
[root@ceshi-132 apollo-configservice]# vi svc.yaml
交付文件
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-configservice/cm.yaml
configmap/apollo-configservice-cm created
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-configservice/dp.yaml
deployment.extensions/apollo-configservice created
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-configservice/svc.yaml
service/apollo-configservice created
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-configservice/ingress.yaml
ingress.extensions/apollo-configservice created
apollo-adminservice
[root@ceshi-132 apollo-adminservice]# cp /data/k8s-yaml/test/apollo-adminservice/*.yaml .
修改namespace名称prod
[root@ceshi-132 apollo-adminservice]# vi cm.yaml
[root@ceshi-132 apollo-adminservice]# vi dp.yaml
交付
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-adminservice/cm.yaml
configmap/apollo-adminservice-cm created
[root@ceshi-130 kube-scheduler]# kubectl apply -f http://k8s-yaml.od.com/prod/apollo-adminservice/dp.yaml
deployment.extensions/apollo-adminservice created
删除原创建dev空间
MariaDB [ApolloPortalDB]> truncate App;
Query OK, 0 rows affected (0.037 sec)
MariaDB [ApolloPortalDB]> truncate AppNamespace;
Query OK, 0 rows affected (0.029 sec)