全国最大的网页游戏私服排行榜公益平台!
当前位置:主页 > 最新资讯 > 网页游戏 >

Kubernetes集群中基于 CRD 实现分批发布

时间:2020-09-11 15:46来源:未知 作者:页游私服排行 点击:
原文链接:https://yq.aliyun.com/articles/621154?spm=a2c4e.11153940.bloghomeflow.125.4886291anr11dV 分批发布是一种通用的发布方式,但是在Kubernetes集群中,要实现分批发布,需要控制各种状态,维护servic

原文链接: https://yq.aliyun.com/articles/621154?spm=a2c4e.11153940.bloghomeflow.125.4886291anr11dV


分批发布是一种通用的发布方式,但是在Kubernetes集群中,要实现分批发布,需要控制各种状态,维护service流量,以及各种label配置,十分麻烦。阿里云容器服务提供一种基于 CRD 的分批发布方式,大大方便发布流程。

(点击原文链接查看视频)

使用kubectl进行分批发布

新集群默认安装了alicloud-application-controller,老集群请先手动安装,安装方式, 
kubectl create -f alicloud-application-controller.yml

apiVersion: extensions/v1beta1 kind: Deploymentmetadata:   name: alicloud-application-controller   labels:     owner: aliyun     app: alicloud-application-controller   namespace: kube-systemspec:   replicas: 1   selector:     matchLabels:       owner: aliyun       app: alicloud-application-controller   template:     metadata:       labels:         owner: aliyun         app: alicloud-application-controller       annotations:         scheduler.alpha.kubernetes.io/critical-pod: ''     spec:       tolerations:       - effect: NoSchedule         operator: Exists         key: node-role.kubernetes.io/master       - effect: NoSchedule         operator: Exists         key: node.cloudprovider.kubernetes.io/uninitialized       containers:         - name: alicloud-application-controller           image: registry.cn-hangzhou.aliyuncs.com/acs/aliyun-app-lifecycle-manager:0.1-93095ba           imagePullPolicy: IfNotPresent       serviceAccount: admin

我们这里以下面这个 StatefulSet 为例子演示分批发布的流程,

apiVersion: apps/v1 kind: StatefulSetmetadata:   name: webspec:   selector:     matchLabels:       app: nginx # has to match .spec.template.metadata.labels   serviceName: "nginx"   replicas: 3 # by default is 1   template:     metadata:       labels:         app: nginx # has to match .spec.selector.matchLabels     spec:       terminationGracePeriodSeconds: 10       containers:       - name: nginx         image: registry.cn-hangzhou.aliyuncs.com/xianlu/old-nginx         ports:         - containerPort: 80           name: web

这是一个含有三个实例的nginx 实例,为了暴露此容器,我们使用Service来暴露,Service的Yaml如下

apiVersion: v1 kind: Servicemetadata:   name: nginx   labels:     app: nginxspec:   ports:   - port: 80     name: web   selector:     app: nginx   type: LoadBalancer

这里通过SLB 暴露nginx 服务。 
为了保证用户的Yaml安全性,分批发布需要使用Secret来存储最终的yaml,这里需要将yaml执行一下base64操作,再存储。 
这个是 StatefulSet 的Secret Yaml

apiVersion: v1 kind: Secretmetadata:   name: mysts type: Opaquedata:   yaml: YXBpVmVyc2lvbjogYXBwcy92MQpraW5kOiBTdGF0ZWZ1bFNldAptZXRhZGF0YToKICBuYW1lOiB3ZWIKc3BlYzoKICBzZWxlY3RvcjoKICAgIG1hdGNoTGFiZWxzOgogICAgICBhcHA6IG5naW54ICMgaGFzIHRvIG1hdGNoIC5zcGVjLnRlbXBsYXRlLm1ldGFkYXRhLmxhYmVscwogIHNlcnZpY2VOYW1lOiAibmdpbngiCiAgcmVwbGljYXM6IDMgIyBieSBkZWZhdWx0IGlzIDEKICB0ZW1wbGF0ZToKICAgIG1ldGFkYXRhOgogICAgICBsYWJlbHM6CiAgICAgICAgYXBwOiBuZ2lueCAjIGhhcyB0byBtYXRjaCAuc3BlYy5zZWxlY3Rvci5tYXRjaExhYmVscwogICAgc3BlYzoKICAgICAgdGVybWluYXRpb25HcmFjZVBlcmlvZFNlY29uZHM6IDEwCiAgICAgIGNvbnRhaW5lcnM6CiAgICAgIC0gbmFtZTogbmdpbngKICAgICAgICBpbWFnZTogcmVnaXN0cnkuY24taGFuZ3pob3UuYWxpeXVuY3MuY29tL3hpYW5sdS9vbGQtbmdpbngKICAgICAgICBwb3J0czoKICAgICAgICAtIGNvbnRhaW5lclBvcnQ6IDgwCiAgICAgICAgICBuYW1lOiB3ZWI=