[融资股票抵押]Kubernetes集群中基于 CRD 实现分批发布

2020-12-07 08:06:16 192 在线配资 Kubernetes,集群,基于,实现,分批,发布

原文链接: 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=

版权保护: 本文由 网上炒股配资-股票配资开户-配资炒股平台-场外在线股票配资公司 原创,转载请保留链接: http://www.dwsfx.com/zxpz/481.html

相关文章

推荐文章

热门文章