替换镜像地址配置
OSC需替换values.yaml或者*.clusterserviceversion.yaml中的镜像地址,mapping.yaml文件确定OSC在values.yaml或者*.clusterserviceversion.yaml中哪些字段用于配置镜像地址。mapping.yaml有多种不同的字段替换方式,镜像根据实际情况选择对应字段,会将镜像分隔成不同内容回填到配置文件中。
instance: # helm文件镜像替换描述 - image: xxxxx # 定义推送到仓库后的镜像名称,名称必须符合docker镜像命名规范 tag: xxx # 定义推送到仓库后的镜像版本tag address: # 定义value.yaml中用于替换到目标key值的路径以及替换的镜像结果内容 fullAddress: xxxx # 替换内容1,xxxx指代的value.yaml文件中最外层到替换镜像值的全路径,以点号相连 repository: xxx # 替换内容2 prefixAddress: xxx # 替换内容3 repo: xxx # 替换内容4 endpoint: xxx # 替换内容5 tag: xxx # 替换内容6 package: # 定义替换上面address字段中的镜像路径是来自images目录中的镜像tar包 x86_64: xxx.tar # 声明使用x86格式的镜像tar包替换 aarch64: xxx.tar # 声明使用arm格式的镜像tar包替换
对于一个服务,如果是单CPU架构,则只需要配置x86_64或者aarch64之一即可,如果是多CPU架构,则x86_64和aarch64都需配置,osc服务会将两个服务制作成共架构服务包并将最终镜像地址回填到部署文件中。以下分别通过一个Helm服务和Operator服务举例说明,以镜像swr.cn-east-3.myhuaweicloud.com/osc-opensource/redis:0.0.1为例,address中的字段含义如下所示:
swr.cn-east-3.myhuaweicloud.com/osc-opensource/redis:0.0.1
- fullAddress:swr.cn-east-3.myhuaweicloud.com/osc-opensource/redis:0.0.1
- repository:swr.cn-east-3.myhuaweicloud.com/osc-opensource/redis
- prefixAddress:swr.cn-east-3.myhuaweicloud.com/osc-opensource
- repo: osc-opensource/redis
- endpoint:swr.cn-east-3.myhuaweicloud.com
- tag:0.0.1
配置对应值,OSC服务会将推送后的镜像拉取地址对应回填到部署文件中的全量路径key对应的地址中去。
Helm服务示例
image: exampleservice:1.0.0 kafka: image: registry: docker.io repository: bitnami/kafka tag: 2.5.0 zookeeper: image: repository: docker.io/bitnami/zookeeper tag: 3.4.0 mariadb: image: registry: docker.io repository: bitnami/mariadb tag: 10.5.8-debian-10-r46 redis: image: docker.io/bitnami/redis:6.0.10
mapping.yaml配置为:
instance: - image: kafka tag: 2.5.0 address: endpoint: kafka.image.registry repo: kafka.image.repository tag: kafka.image.tag package: x86_64: kafka-2.5.0.tar - image: mariadb tag: 10.5.8-debian-10-r46 address: endpoint: mariadb.image.registry repo: mariadb.image.repository tag: mariadb.image.tag package: x86_64: mariadb-10.5.8.tar - image: zookeeper tag: 3.4.0 address: repository: zookeeper.image.repository tag: zookeeper.image.tag package: x86_64: zookeeper-3.4.14.tar - image: redis tag: 6.0.10 address: fullAddress: redis.image package: x86_64: exampleservice-1.0.0-x86.tar aarch64: exampleservice-1.0.0-arm64.tar
Operator服务示例
Operator服务镜像配置在*.clusterserviceversion.yaml文件中,分布在两处:
- 作为Operator运维功能的实例镜像,其默认配置在spec.install中。
- 作为真正提供服务功能的实例镜像,其默认配置在metadata.annotations.alm-examples中。
开发者在mapping.yaml中指定需要在*.clusterserviceversion.yaml中替换的镜像地址,以etcd operator为例:
apiVersion: operators.coreos.com/v1alpha1 kind: ClusterServiceVersion metadata: annotations: alm-examples: "[ { "apiVersion": "etcd.database.coreos.com/v1beta2", "kind": "EtcdCluster", "metadata": { "name": "example" }, "spec": { "size": 3, "version": "3.2.13", "cluster": { "registry": "quay.io/coreos/“, "repo": "etcd-operator@sha256", "tag": 66a37fd61a06a43969854ee6d3e21087a98b93838e284a6086b13917f96b0d9b" }, } }, { "apiVersion": "etcd.database.coreos.com/v1beta2", "kind": "EtcdRestore", "metadata": { "name": "example-etcd-cluster-restore" }, "spec": { "etcdCluster": { "name": "example-etcd-cluster" }, "backupStorageType": "S3", "restore": { "repo": "quay.io/coreos/etcd-operator@sha256", "tag": 66a37fd61a06a43969854ee6d3e21087a98b93838e284a6086b13917f96b0d9b" }, "s3": { "path": "<full-s3-path>", "awsSecret": "<aws-secret>"' } } }, { "apiVersion": "etcd.database.coreos.com/v1beta2", "kind": "EtcdBackup", "metadata": { "name": "example-etcd-cluster-backup" }, "spec": { "etcdEndpoints": ["<etcd-cluster-endpoints>"], "storageType":"S3", "image": "quay.io/coreos/etcd-operator@sha256:66a37fd61a06a43969854ee6d3e21087a98b93838e284a6086b13917f96b0d9b", "s3": { "path": "<full-s3-path>", "awsSecret": "<aws-secret>" } } } ]" capabilities: Full Lifecycle categories: Database containerImage: quay.io/coreos/etcd-operator@sha256:66a37fd61a06a43969854ee6d3e21087a98b93838e284a6086b13917f96b0d9b createdAt: 2019-02-28 01:03:00 description: Create and maintain highly-available etcd clusters on Kubernetes repository: https://github.com/coreos/etcd-operator tectonic-visibility: ocs name: etcdoperator.v0.9.4 namespace: placeholder spec: install: spec: deployments: - name: etcd-operator spec: replicas: 1 selector: matchLabels: name: etcd-operator-alm-owned template: metadata: labels: name: etcd-operator-alm-owned name: etcd-operator-alm-owned spec: containers: - command: - etcd-operator - --create-crd=false env: - name: MY_POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: MY_POD_NAME valueFrom: fieldRef: fieldPath: metadata.name image: quay.io/coreos/etcd-operator@sha256:66a37fd61a06a43969854ee6d3e21087a98b93838e284a6086b13917f96b0d9b name: etcd-operator - command: - etcd-backup-operator - --create-crd=false env: - name: MY_POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: MY_POD_NAME valueFrom: fieldRef: fieldPath: metadata.name image: quay.io/coreos/etcd-operator@sha256:66a37fd61a06a43969854ee6d3e21087a98b93838e284a6086b13917f96b0d9b name: etcd-backup-operator - command: - etcd-restore-operator - --create-crd=false env: - name: MY_POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: MY_POD_NAME valueFrom: fieldRef: fieldPath: metadata.name image: quay.io/coreos/etcd-operator@sha256:66a37fd61a06a43969854ee6d3e21087a98b93838e284a6086b13917f96b0d9b name: etcd-restore-operator serviceAccountName: etcd-operator
etcd operator中包含多个镜像,etcd-operator-x86-0.9.4.tar, etcd-operator-arm64-0.9.4.tar, etcd-backup-operator-x86-0.9.4.tar, etcd-backup-operator-arm64-0.9.4.tar, etcd-restore-operator-x86-0.9.4.tar, etcd-restore-operator-arm64-0.9.4.tar,除了instances字段,operator服务的mapping.yaml还多了一个operator字段。
lifecycle: - deployment: etcd-operator containers: - type: container name: etcd-operator image: etcd-operator tag: 0.9.4 package: x86_64: etcd-operator-0.9.4.tar aarch64: etcd-operator-0.9.4.tar - type: container name: etcd-backup-operator image: etcd-backup-operator tag: 0.9.4 package: x86_64: etcd-backup-operator-x86-0.9.4.tar aarch64: etcd-backup-operator-arm64-0.9.4.tar - type: container name: etcd-restore-operator image: etcd-restore-operator tag: 0.9.4 package: x86_64: etcd-restore-operator-x86-0.9.4.tar aarch64: etcd-restore-operator-arm64-0.9.4.tar instance: - kind: EtcdCluster image: etcd tag: 0.9.4 address: endpoint: spec.cluster.registry repo: spec.cluster.repo tag: spec.cluster.tag package: x86_64: etcd-x86-0.9.4.tar aarch64: etcd-operator-arm64-0.9.4.tar - kind: EtcdRestore image: etcd-restore tag: 0.9.4 address: repository: spec.restore.repo tag: spec.restore.tag package: x86_64: etcd-x86-0.9.4.tar aarch64: etcd-operator-arm64-0.9.4.tar - kind: EtcdBackup image: etcd-restore tag: 0.9.5 address: fullAddress: spec.image package: x86_64: etcd-restore-x86-0.9.6.tar aarch64: etcd-restore-arm64-0.9.4.tar
mapping.yaml中instances字段支持列表形式,根据*.clusterserviceversion.yaml中的alm-example来配置,每个kind对应instances字段下一个列表元素。mapping.yaml中operator字段也支持列表的形式,对应*.clusterserviceversion.yaml中的spec.install.spec.deployments下的deployment列表。
*.clusterserviceversion.yaml中spec.install.spec.deployments每个deployment的镜像配置都只能配置完整的镜像地址,不能再以fullAddress,repository,tag等字段的方式来拼接,因此无需再指定被替换的镜像地址,osc根据package字段中的内容来回填的image, type分为initContainer/container/ephemeralContainer三种类型,对应deployment中支持的三种container类型场景状态。
上述例子中lifecycle字段只是部分配置,deployment元素的完整配置如下:
lifecycle: - deployment: xxx # deployment的名字 containers: - type: initContainer # deployment下的container类型,主要分为initContainer/container/ephemeralContainer三种 name: xxx # container类型的name值 image: xxx # 定义推送到仓库后的镜像名称,名称必须符合docker镜像命名规范 tag: xxx # 定义推送到仓库后的镜像版本tag package: x86_64: xxx.tar aarch64: xxx.tar env: # container env字段下变量中涉及需要进行镜像地址替换的声明,没有可不填 - name: XXX # env中环境name变量的名称 image: xxx # 定义推送到仓库后的镜像名称,名称必须符合docker镜像命名规范 tag: xxx # 定义推送到仓库后的镜像版本tag package: x86_64: xxx.tar aarch64: xxx.tar - type: container name: xxx image: xxx tag: xxx package: x86_64: xxx.tar aarch64: xxx.tar env: # container env字段下变量中涉及需要进行镜像地址替换的声明,没有可不填 - name: XXX # env中环境name变量的名称 image: xxx # 定义推送到仓库后的镜像名称,名称必须符合docker镜像命名规范 tag: xxx # 定义推送到仓库后的镜像版本tag package: x86_64: xxx.tar aarch64: xxx.tar - type: ephemeralContainer name: xxx image: xxx tag: xxx package: x86_64: xxx.tar aarch64: xxx.tar env: # container env字段下变量中涉及需要进行镜像地址替换的声明,没有可不填 - name: XXX # env中环境name变量的名称 image: xxx # 定义推送到仓库后的镜像名称,名称必须符合docker镜像命名规范 tag: xxx # 定义推送到仓库后的镜像版本tag package: x86_64: xxx.tar aarch64: xxx.tar
- operator.deployment.containers下每个name对应的配置,如果是单CPU架构,x86_64和aarch64二选一,多架构则都配置,每种容器启动的镜像只能有一个。
- initContainers,containers,ephemeralContainers都是可选项,这些字段是*.clusterserviceversion.yaml中用来配置容器初始化的,根据实际情况配置,如果没有可以不配置。