背景

实现 GPU 集群和 CPU 集群,计划两个集群Pod IP 之间可以直接访问。GPU集群跨了两个网络段的。在CPU gateway 节点配置路由规则,路由在同一个主机网络GPU机器。加路由规则比较麻烦,由于GPU机器跨两个网络配置集中部分机器,配置不方便。

两个集群网络直接互联。自动根据对端ETCD网络段变化添加更新集群节点本地路由规则。

配置 cluster mesh

Cilium ds 上 cluster 配置项目

Cilum-ds 上面确认有下面配置[1.2.5] 是在ds上面, 1.8 1.9 版本在cilium-operator-deploy上面

  1. - name: CILIUM_CLUSTERMESH_CONFIG
  2. value: "/var/lib/cilium/clustermesh/"
  3. - name: CILIUM_CLUSTER_NAME
  4. valueFrom:
  5. configMapKeyRef:
  6. key: cluster-name
  7. name: cilium-config
  8. optional: true
  9. - name: CILIUM_CLUSTER_ID
  10. valueFrom:
  11. configMapKeyRef:
  12. key: cluster-id
  13. name: cilium-config
  14. optional: true
  15. volumeMounts:
  16. - name: clustermesh-secrets
  17. mountPath: /var/lib/cilium/clustermesh
  18. readOnly: true
  19. volumes:
  20. ....
  21. - name: clustermesh-secrets
  22. secret:
  23. defaultMode: 420
  24. optional: true
  25. secretName: cilium-clustermesh
  • CILIUM_CLUSTERMESH_CONFIG: 挂载 etcd 证书位置
  • CILIUM_CLUSTER_ID : mesh id, 每个节点都必须唯一

    注意:

    1. Cluster ID不要随意修改,如果修改以后导致就 workloadpod 无法访问,需要重新启动以后才可以访问。必须慎重。

Cilium configmap 上需要有

  1. ---
  2. apiVersion: v1
  3. kind: ConfigMap
  4. metadata:
  5. name: cilium-config
  6. namespace: kube-system
  7. data:
  8. ####
  9. # .....
  10. ####
  11. # 增加下面两个配置
  12. cluster-name: "cluster<id>" # 命名 需要集群唯一
  13. cluster-id: "<id>" # id: 1 ~ 255 全集群唯一

配置Secretfile

每个集群需要四个问题,以集群cluster-1cluster2集群互联为例子。cluster-1, cluster-2 必须和填写在cluster-name名字一致,否则互联失败。

集群描述文件, 描述就此集群配置文件路径
cluster1

  1. endpoints:
  2. - https://172.xx.xx.xx:2379 # IP以实际具体为准
  3. ca-file: '/var/lib/cilium/clustermesh/cluster2.etcd-client-ca.crt'
  4. key-file: '/var/lib/cilium/clustermesh/cluster2.etcd-client.key'
  5. cert-file: '/var/lib/cilium/clustermesh/cluster2.etcd-client.crt'

cluster1, cluster1.etcd-client.key, cluster1.etcd-client.crt, cluster1.etcd-client-ca.crt 连接 etcd 三个key文件

注意: TLS和集群etcd配置必须按照这个命名规则

  1. - 配置文件:<cluster-name>
  2. - TLS相关文件 <cluster-name>.etcd-client.key, <cluster-name>.etcd-client.crt, <cluster-name>.etcd-client-ca.crt

加入文件到cluster2集群上面

  1. kubectl --debug create secret generic -n kube-system --from-file=./cluster1 --from-file=./cluster1.etcd-client-ca.crt --from-file=./cluster1.etcd-client.key --from-file=./cluster1.etcd-client.crt

注意 cluster1 配置到cluster2, 统一cluster2文件配置cluster1上。配置以后才可以进行互相访问。

挂载以后如下:

  1. (cluster2 cilium container xx) $ ls /var/lib/cilium/clustermesh/
  2. cluster
  3. cluster1.etcd-client-ca.crt
  4. cluster1.etcd-client.crt
  5. cluster1.etcd-client.key
  6. (cluster2 node1) $ cat /var/lib/cilium/clustermesh/cluster1
  7. endpoints:
  8. - https://172.xx.xx.xx:2379 # IP以实际具体为准
  9. ca-file: '/var/lib/cilium/clustermesh/cluster1.etcd-client-ca.crt'
  10. key-file: '/var/lib/cilium/clustermesh/cluster1.etcd-client.key'
  11. cert-file: '/var/lib/cilium/clustermesh/cluster1.etcd-client.crt'

测试

Verify clustermesh syncing

Check cluster status:

  1. (cluster1 node1) $ cilium status
  2. KVStore: Ok etcd: ...
  3. Kubernetes: Ok 1.17+ (v1.17.6-3) [linux/amd64]
  4. ...
  5. ClusterMesh: 2/2 clusters ready, 0 global-services

More verbose:

  1. (cluster1 node1) $ cilium status --verbose
  2. KVStore: Ok etcd: ...
  3. Kubernetes: Ok 1.17+ (v1.17.6-3) [linux/amd64]
  4. ...
  5. ClusterMesh: 1/1 clusters ready, 0 global-services
  6. cluster2: ready, xx nodes, xx identities, 0 services, 0 failures (last: never)
  7. etcd: 1/1 connected, ...

List all nodes of all clusters in the mesh:

  1. (cluster1 node1) $ cilium node list
  2. Name IPv4 Address Endpoint CIDR IPv6 Address Endpoint CIDR
  3. cluster1/node1 10.xx.xx.xx 10.xx.xx.xx/24
  4. cluster1/node2 10.xx.xx.xx 10.xx.xx.xx/24
  5. ...
  6. cluster2/node1 10.xx.xx.xx 10.xx.xx.xx/24
  7. cluster2/node2 10.xx.xx.xx 10.xx.xx.xx/24
  8. ...

cilium 网络包追踪

  1. (cluster1 node1) cilium monitor

参考

kubernetes multi-cluster
https://arthurchiao.art/blog/cilium-clustermesh/