kubernetes实战-交付dubbo服务到k8s集群(六)使用blue ocean流水线构建dubbo-consumer服务
我们这里的dubbo-consumer是dubbo-demo-service的消费者:
我们之前已经在jenkins配置好了流水线,只需要填写参数就行了。
由于dubbo-consumer用的gitee的私有仓库,需要添加公钥,这里大家可以自己找个client服务来做实验。
下面是我们通过jenkins构建的镜像,已经上传到我们的harbor私有仓库当中了:
这里我们构建了两次,构建了两个镜像,11bb9cd这个用来做模拟生产发版更新实验。
准备资源配置清单:
1、dp.yaml 红色部分根据实际镜像tag修改
# mkdir /data/k8s-yaml/dubbo-consumer
# cd /data/k8s-yaml/dubbo-consumer
# vi dp.yaml
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:master_191201_1600 ports: - containerPort: 8080 protocol: TCP - containerPort: 20880 protocol: TCP env: - name: JAR_BALL value: dubbo-client.jar 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
2、svc.yaml
# vi svc.yaml
kind: Service apiVersion: v1 metadata: name: dubbo-demo-consumer namespace: app spec: ports: - protocol: TCP port: 8080 targetPort: 8080 selector: app: dubbo-demo-consumer
3、ingress.yaml
# vi ingress.yaml
kind: Ingress apiVersion: extensions/v1beta1 metadata: name: dubbo-demo-consumer namespace: app spec: rules: - host: demo.od.com http: paths: - path: / backend: serviceName: dubbo-demo-consumer servicePort: 8080
应用资源配置清单:
# kubectl apply -f http://k8s-yaml.od.com/dubbo-consumer/dp.yaml # kubectl apply -f http://k8s-yaml.od.com/dubbo-consumer/svc.yaml # kubectl apply -f http://k8s-yaml.od.com/dubbo-consumer/ingress.yaml
# kubectl get pod -n app
查看log,是否启动成功:
# kubectl logs dubbo-demo-consumer-f8d5f5f74-dgmqd -n app
检查dubbo-monitor是否已经注册成功:
添加个dns解析,来验证:
# vi /var/named/od.com.zone
# systemctl restart named
浏览器访问http://demo.od.com/hello?name=slim
接下来我们模拟升级发版,我们提前修改了代码,并提交到了git仓库,发版的前提是使用jenkins提前构建了镜像并且上传到了我们的私有harbor仓库中,具体的构建流程不在赘述,只需要将远程git仓库的版本修改后构建就行了。
修改dp.yaml资源配置清单,修改harbor镜像仓库中对应的tag版本:
# vi dp.yaml
应用修改后的资源配置清单,当然也可以在dashboard中进行在线修改:
# kubectl apply -f http://k8s-yaml.od.com/dubbo-consumer/dp.yaml
已经启动起来了,使用浏览器验证:http://demo.od.com/hello?name=slim
至此,我们一套完成的dubbo服务就已经交付到k8s集群当中了,并且也演示了如何发版。