码迷,mamicode.com
首页 > Web开发 > 详细

kubernetes实战-配置中心(四)分环境使用apollo配置中心

时间:2019-12-14 18:53:09      阅读:546      评论:0      收藏:0      [点我收藏+]

标签:odi   lin   template   not   rod   需要   otp   coding   grant   

要进行分环境,需要将现有实验环境进行拆分

portal服务,可以各个环境共用,但是apollo-adminservice和apollo-configservice必须要分开。

1、zk环境拆分为test和prod环境

添加dns解析:

# vi /var/named/od.com.zone

zk-test.od.com       A       10.4.7.11

zk-prod.od.com      A       10.4.7.12

技术图片

2、namespace 分环境,创建test 和prod

# kubectl create ns test
# kubectl create ns prod

创建secret:

# kubectl create secret docker-registry harbor --docker-server=harbor.od.com --docker-username=harbor --docker-password=Harbor12345 -n test

# kubectl create secret docker-registry harbor --docker-server=harbor.od.com --docker-username=harbor --docker-password=Harbor12345 -n prod

3、数据库进行拆分,因实验资源有限,故使用分库的形式模拟分环境

修改数据库初始化脚本,分别创建ApolloConfigTestDB和ApolloConfigProdDB

技术图片

 

 

 

技术图片

 

 

 修改数据库中eureka的地址,这里用到了两个新的域名,自行在bind9中添加解析

> update ApolloConfigProdDB.ServerConfig set ServerConfig.Value="http://config-prod.od.com/eureka" where ServerConfig.Key="eureka.service.url";


> grant INSERT,DELETE,UPDATE,SELECT on ApolloConfigProdDB.* to "apolloconfig"@"10.4.7.%" identified by "123456";

> update ApolloConfigTestDB.ServerConfig set ServerConfig.Value="http://config-test.od.com/eureka" where ServerConfig.Key="eureka.service.url";


> grant INSERT,DELETE,UPDATE,SELECT on ApolloConfigTestDB.* to "apolloconfig"@"10.4.7.%" identified by "123456";

技术图片

 

 

修改portal数据,支持fat和pro环境:

> update ServerConfig set Value=fat,pro where Id=1;

修改portal的cm资源配置清单:

# vi /data/k8s-yaml/apollo-portal/cm.yaml

 

技术图片

 

 

# kubectl apply -f http://k8s-yaml.od.com/apollo-portal/cm.yaml

技术图片

 

 

分别创建修改两个环境的资源配置文件:

test:

# cd /data/k8s-yaml
# mkdir -p test/{apollo-adminservice,apollo-configservice,dubbo-demo-server,dubbo-demo-consumer}


# mkdir -p prod/{apollo-adminservice,apollo-configservice,dubbo-demo-server,dubbo-demo-consumer}

将之前的资源配置清单cp到对应环境的目录中,进行修改:

# cd  test/apollo-configservice/
# cp ../../apollo-configservice/* ./

1、cm.yaml 修改ns,数据库库名,eureka地址

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

2、dp.yaml

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

3、svc.yaml

kind: Service
apiVersion: v1
metadata: 
  name: apollo-configservice
  namespace: test 
spec:
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080
  selector: 
    app: apollo-configservice

4、ingress.yaml

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

 

kubernetes实战-配置中心(四)分环境使用apollo配置中心

标签:odi   lin   template   not   rod   需要   otp   coding   grant   

原文地址:https://www.cnblogs.com/slim-liu/p/12040292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!