Kubernetes集群支持VPC多路由表

背景

Kubernetes通过CloudProvider(又称CCM)组件在VPC路由表中添加合适的路由来打通集群中Pod之间的网络连接。
近期VPC发布了对多个路由表的支持能力,让用户可以自行选择ECS关联哪些路由表,为用户提供了丰富的路由管理能力。由于CCM早期版本中仅提供了VPC单路由表的支持,因此您需要将CCM镜像升级到registry.cn-hangzhou.aliyuncs.com/acs/cloud-controller-manager-amd64:v1.9.3.82-g274b1b5-aliyun来使用多路由表支持。并且CCM通过--cloud-config配置文件(routeTableIDs)指定需要使用哪些路由表。

前置条件

您需要有一个容器服务控制台创建的k8s集群。通过容器服务控制台创建一个k8s集群。 参考

配置CloudProvider组件

配置多路由表支持,需要您对CCM部署文件做如下修改。

  1. 创建cloud-config的ConfigMap。将其中的${ROUTE_TABLES_IDS}替换成您的VPC路由表id, 支持多个路由表列表,使用逗号分隔。 示例: vtb-t4n7k6u3m0n8407o7k1t7,vtb-t4n7k6u3m0n8407999999
apiVersion: v1
kind: ConfigMap
metadata:
  name: cloud-config
  namespace: kube-system
data:
  cloud-config.conf: |-
    {
        Global: {
            "routeTableIDs": "${ROUTE_TABLES_IDS}"
        }
    }
  1. 使用命令行kubectl edit ds -n kube-system cloud-controller-manager修改CCM部署文件。 添加
    1). Volume声明,引用刚刚创建的cloud-config ConfigMap.
   volumes:
   - name: cloud-config
     configMap:
       name: cloud-config
       items:
       - key: cloud-config.conf

2). 引用cloud-config 卷。

     volumeMounts:
     - name: cloud-config
       mountPath: /etc/kubernetes/config

3). 变更镜像版本到v1.9.3.82-g274b1b5-aliyun
4). 修改CCM启动参数,添加- --cloud-config=/etc/kubernetes/config/cloud-config.conf

保存退出。如果CCM的Pod没有自动更新,可以尝试手动删除CCM Pod,强制更新。
配置完成后的CCM部署yaml文件请参考附件。
此时您的CCM可以通过配置支持VPC多路由表能力了。

附件:示例CCM部署。

apiVersion: v1
kind: ConfigMap
metadata:
  name: cloud-config
  namespace: kube-system
data:
  cloud-config.conf: |-
    {
        Global: {
            "routeTableIDs": "${ROUTE_TABLES_IDS}"
        }
    }
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  labels:
    app: cloud-controller-manager
    tier: control-plane
  name: cloud-controller-manager
  namespace: kube-system
spec:
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: cloud-controller-manager
      tier: control-plane
  template:
    metadata:
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ""
      creationTimestamp: null
      labels:
        app: cloud-controller-manager
        tier: control-plane
    spec:
      containers:
      - command:
        - /cloud-controller-manager
        - --kubeconfig=/etc/kubernetes/cloud-controller-manager.conf
        - --address=127.0.0.1
        - --allow-untagged-cloud=true
        - --leader-elect=true
        - --cloud-provider=alicloud
        - --allocate-node-cidrs=true
        - --cluster-cidr=${CLUSTER_CIDR}
        - --use-service-account-credentials=true
        - --route-reconciliation-period=3m
        - --v=5
        - --cloud-config=/etc/kubernetes/config/cloud-config.conf
        - --feature-gates=ServiceNodeExclusion=true
        image: registry.cn-hangzhou.aliyuncs.com/acs/cloud-controller-manager-amd64:v1.9.3.82-g274b1b5-aliyun
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 8
          httpGet:
            host: 127.0.0.1
            path: /healthz
            port: 10253
            scheme: HTTP
          initialDelaySeconds: 15
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 15
        name: cloud-controller-manager
        volumeMounts:
        - mountPath: /etc/kubernetes/
          name: k8s
          readOnly: true
        - mountPath: /etc/ssl/certs
          name: certs
        - mountPath: /etc/pki
          name: pki
        - name: cloud-config
          mountPath: /etc/kubernetes/config
      dnsPolicy: ClusterFirst
      hostNetwork: true
      nodeSelector:
        node-role.kubernetes.io/master: ""
      restartPolicy: Always
      serviceAccount: cloud-controller-manager
      serviceAccountName: cloud-controller-manager
      tolerations:
      - operator: Exists
      volumes:
      - hostPath:
          path: /etc/kubernetes
          type: ""
        name: k8s
      - hostPath:
          path: /etc/ssl/certs
          type: ""
        name: certs
      - hostPath:
          path: /etc/pki
          type: ""
        name: pki
      - name: cloud-config
        configMap:
          name: cloud-config
          items:
          - key: cloud-config.conf
  updateStrategy:
    rollingUpdate:
      maxUnavailable: 1
    type: RollingUpdate

猜你喜欢

转载自yq.aliyun.com/articles/695256