背景
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 部署文件做如下修改.
创建 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}"
- }
- }
使用命令行
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
来源: https://yq.aliyun.com/articles/695256