在kubernetes集群里集成Apollo配置中心(5)之dubbo服务消费者连接apollo实战

1.在Apollo的portal创建dubbo消费者项目

(1)添加dubbo消费者项目

image-20200709141046777

(2)在dubbo消费者项目中添加配置项

image-20200709141152341

image-20200709141359126

(3)发布

image-20200709141459422

image-20200709141507940

image-20200709141516052

2.通过jenkins构建dubbo消费者镜像

image-20200709144143422

image-20200709151103574

3.登录私有仓库harbor查看是否已上传

image-20200709151150606

4.修改之前的dubbo消费者的deployment.yaml资源配置清单

在运维主机mfyxw50.mfyxw.com上操作

[root@mfyxw50 ~]# cat > /data/k8s-yaml/dubbo-demo-consumer/deployment.yaml << EOF
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: dubbo-demo-consumer
  namespace: app
  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_20200709_1441
        ports:
        - containerPort: 8080
          protocol: TCP
        - containerPort: 20880
          protocol: TCP
        env:
        - name: JAR_BALL
          value: dubbo-client.jar
        - name: C_OPTS
          value: -Denv=dev -Dapollo.meta=http://config.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

5.重新应用dubbo消费者的deployment.yaml资源配置清单

在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)任意一台执行

[root@mfyxw30 ~]# kubectl get pod -n app
NAME                                   READY   STATUS    RESTARTS   AGE
dubbo-demo-consumer-6c7f6f598b-l2gdx   1/1     Running   12         23d
dubbo-demo-service-6c99776d74-xxkr7    1/1     Running   4          28h
[root@mfyxw30 ~]# 
[root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/dubbo-demo-consumer/deployment.yaml
deployment.extensions/dubbo-demo-consumer configured
[root@mfyxw30 ~]# 
[root@mfyxw30 ~]# kubectl get pod -n app
NAME                                  READY   STATUS    RESTARTS   AGE
dubbo-demo-consumer-ccb4d6549-g6h6k   1/1     Running   0          3s
dubbo-demo-service-6c99776d74-xxkr7   1/1     Running   4          28h

6.查看Apollo的portal是否已经有dubbo消费者实例连接上

image-20200709151927823

7.登录dubbo-monitor查看Apollo的dubbo消费者是否注册进入

image-20200709152208891

image-20200709152215361

8.访问demo.od.com/hello?name=apollo

image-20200709152320881

posted on 2020-07-10 09:17  杨枫哥  阅读(457)  评论(0编辑  收藏  举报