云容器实例 CCI-镜像地址替换:配置场景一

时间:2024-10-29 16:37:49

配置场景一

原Pod中所有容器镜像均使用同一镜像仓库与组织,配置一条替换策略即可。

示例:将所有容器镜像"harbor.domain/a/b/c/d"前缀都替换为SWR的镜像前缀"swr.cn-north-4.myhuaweicloud.com/org"。

替换策略:

"coordinator.cci.io/image-replacement": '[{"repositoryPrefix":"harbor.domain/a/b/c/d","replaceWith":"swr.cn-north-4.myhuaweicloud.com/org"}]'

替换前:

      containers:
        - name: container-0
          image: 'harbor.domain/a/b/c/d/ubuntu:latest'
        - name: container-1
          image: 'harbor.domain/a/b/c/d/nginx:latest'

替换后:

      containers:
        - name: container-0
          image: 'swr.cn-north-4.myhuaweicloud.com/org/ubuntu:latest'
        - name: container-1
          image: 'swr.cn-north-4.myhuaweicloud.com/org/nginx:latest'

示例Deployment:

apiVersion: apps/v1 
kind: Deployment 
metadata: 
  name: test-vk 
  labels: 
    virtual-kubelet.io/burst-to-cci: 'auto' 
spec: 
  replicas: 20 
  selector: 
    matchLabels: 
      app: test-vk 
  template: 
    metadata: 
      labels: 
        app: test-vk
      annotations: 
        coordinator.cci.io/image-replacement: '[{"repositoryPrefix":"harbor.domain/a/b/c/d","replaceWith":"swr.cn-north-4.myhuaweicloud.com/org"}]'
    spec: 
      containers: 
      - name: container-0 
        image: harbor.domain/a/b/c/d/ubuntu:latest 
        resources: 
          limits: 
            cpu: 500m 
            memory: 1024Mi 
          requests: 
             cpu: 500m 
             memory: 1024Mi 
        command: 
          - /bin/bash 
          - '-c' 
          - sleep 10000 
      - name: container-1 
        image: harbor.domain/a/b/c/d/nginx:latest 
        resources: 
          limits: 
            cpu: 500m 
            memory: 1024Mi 
          requests: 
             cpu: 500m 
             memory: 1024Mi 
        command: 
          - /bin/bash 
          - '-c' 
          - sleep 10000
support.huaweicloud.com/bestpractice-cci/cci_04_0059.html