实战发布dubbo连接Apollo到不同环境

创建项目 portal.od.com

现在也可以看到环境列表有两个了

测试环境新增配置项,并发布

生产环境新增配置项,并发布

service配置好了,再配置consumer

测试环境新增配置项,并发布

生产环境新增配置项,并发布

# 200机器,制作测试环境service:
cd /data/k8s-yaml/test/dubbo-demo-service/
dubbo-demo-service]# cp -a /data/k8s-yaml/dubbo-demo-service/*.yaml .
# 修改三处
dubbo-demo-service]# vi dp.yaml
  namespace: test
        env:
        - name: JAR_BALL
          value: dubbo-server.jar
        - name: C_OPTS
          value: -Denv=fat -Dapollo.meta=http://config-test.od.com
# 应用,22机器:
~]# kubectl apply -f http://k8s-yaml.od.com/test/dubbo-demo-service/dp.yaml

# 200机器,制作测试环境consumer:
cd /data/k8s-yaml/test/dubbo-demo-consumer/
dubbo-demo-consumer]# cp -a /data/k8s-yaml/dubbo-demo-consumer/*.yaml .
# 修改三处
dubbo-demo-consumer]# vi dp.yaml
  namespace: test
        - name: JAR_BALL
          value: dubbo-client.jar
        - name: C_OPTS
          value: -Denv=fat -Dapollo.meta=http://config-test.od.com
# 修改一处
dubbo-demo-consumer]# vi svc.yaml
  namespace: test
# 修改一处
dubbo-demo-consumer]# vi ingress.yaml
  namespace: test
  - host: demo-test.od.com
# 11机器,新增解析:
~]# vi /var/named/od.com.zone
serial 前滚一位
demo-test          A    10.4.7.10
~]# systemctl restart named

# 应用,22机器:
~]# kubectl apply -f http://k8s-yaml.od.com/test/dubbo-demo-consumer/dp.yaml
~]# kubectl apply -f http://k8s-yaml.od.com/test/dubbo-demo-consumer/svc.yaml
~]# kubectl apply -f http://k8s-yaml.od.com/test/dubbo-demo-consumer/ingress.yaml

查看dashboard的启动情况

此时的monitor还是zk2,我们改成zk-test

update然后删掉对应的pod让它自动重启

# 浏览器输入:demo-test.od.com/hello?name=test

开始做生产环境

# 11机器,新增解析:
~]# vi /var/named/od.com.zone
serial 前滚一位
demo-prod          A    10.4.7.10
~]# systemctl restart named

# 200机器,制作生产环境service:
cd /data/k8s-yaml/prod/dubbo-demo-service/
dubbo-demo-service]# cp -a ../../test/dubbo-demo-service/*.yaml .
# 共修改三处
dubbo-demo-service]# vi dp.yaml
  namespace: prod
        env:
        - name: JAR_BALL
          value: dubbo-server.jar
        - name: C_OPTS
          value: -Denv=pro -Dapollo.meta=http://apollo-configservice:8080
# 应用,22机器:
~]# kubectl apply -f http://k8s-yaml.od.com/prod/dubbo-demo-service/dp.yaml

你还可以去LOGS日志里面看看

# 200机器,制作生产环境consumer:
cd /data/k8s-yaml/prod/dubbo-demo-consumer/
dubbo-demo-consumer]# cp -a /data/k8s-yaml/dubbo-demo-consumer/*.yaml .
# 共修改三处
dubbo-demo-consumer]# vi dp.yaml
  namespace: prod
        env:
        - name: JAR_BALL
          value: dubbo-client.jar
        - name: C_OPTS
          value: -Denv=pro -Dapollo.meta=http://apollo-configservice:8080
        imagePullPolicy: IfNotPresent
# 共修改一处
dubbo-demo-consumer]# vi svc.yaml
  namespace: prod
# 共修改两处
dubbo-demo-consumer]# vi ingress.yaml
  namespace: prod
spec:
  rules:
  - host: demo-prod.od.com
# 应用,22机器:
~]# kubectl apply -f http://k8s-yaml.od.com/prod/dubbo-demo-consumer/dp.yaml
~]# kubectl apply -f http://k8s-yaml.od.com/prod/dubbo-demo-consumer/svc.yaml
~]# kubectl apply -f http://k8s-yaml.od.com/prod/dubbo-demo-consumer/ingress.yaml
# 浏览器输入:demo-prod.od.com/hello?name=prod

报错:

我去LOGS里面看了一下,发现我Apollo配得port写错了,写成了dubbo-port,应该是dubbo.port,改回来就可以了,删掉service得pod重新启动,删掉consumer的pod重新启动

实战演示项目提测,发版流程

模拟项目提测到发布上线,这里用得GitLab,你有可以了解一下GitLab是长什么样子的,还有怎么操作的。修改源代码,并commit

GitLab跟gittee在更新代码的编号有所区别

Jenkins构建

# 填入对应参数,然后build
app_name: dubbo-demo-consumer
image_name: app/dubbo-demo-consumer
git_repo: http://gitlab.od.com:10000/909336740/dubbo-demo-web.git
git_ver: 535826b1239fedba0df3799b7b3b8585d56e9e18
add_tag: 200304_1730
target_dir: ./dubbo-client/target
base_image: base/jre8:8u112

先到测试环境发布,修改tag

重启成功,刷新测试环境的页面,查看情况

刷新生产环境的页面,查看情况,还没改变

我们来修改prod的,这时候已经不需要再去Jenkins打包镜像了

更新完启动pod后,再来刷新生产环境的页面