首页 > 解决方案 > Kubernetes 联合部署每个集群的不同镜像 url

问题描述

知道如何定义 Kubernetes 联合部署以使用来自不同注册表的不同图像 url?

我有一个 GKE 集群的联合集群,我希望部署为他们的本地 GCR 拉取。

apiVersion: extensions/v1beta1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
  annotations:
    federation.kubernetes.io/deployment-preferences: |
      {
        "rebalance": true,
        "clusters": {
          "federation-br": {
             "minReplicas": 1,
             "maxReplicas": 1,
             "weight": 1
          },
          "federation-eu": {
              "minReplicas": 3,
              "weight": 1
          },
        }
      }
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 5 # tells deployment to run 2 pods matching the template
  template: # create pods using pod definition in this template
    metadata:
      # unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is
      # generated from the deployment name
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: eu.gcr.io/nginx/proj/app:master.SHAslug
        ports:
        - containerPort: 80

我想根据集群位置使用所有 eu.gcr.io、us.gcr.io、asia.gcr.io。

还是我真的想要?

标签: kubernetesgoogle-kubernetes-enginegoogle-container-registry

解决方案


使用联合部署的目的是为跨多个集群的部署提供一个配置文件。唯一可行的方法是在 YAML 文件中包含一个变量。但是,这似乎不是 YAML 文件的选项。看起来这不是一个选择。


推荐阅读