本文将介绍如何使用 KubeFATE 在两个 Kubernetes 集群上部署互通的两个FATE 实例。这两个 FATE 可以完成各种联邦学习的任务。
完成后将会得到下图的结构:
先决条件
- 两个独立的 Kubernetes 集群 v1.16.0 ;
- 两个集群都可以连接互联网也可以互通;
- 两个部署机器,分别可以执行两个集群的 kubectl 命令;
- 两个 Kubernetes 都已经部署了 ingress-controller ;
本教程的两个 Kubernetes 集群我们分别称为【A集群】和【B集群】
部署的两个 FATE 实例分别称为【PartyA】和【PartyB】
开始
检查集群
A集群的信息
代码语言:javascript复制[deploy-A]$ kubectl get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master Ready master 191d v1.17.3 192.168.10.1 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.5
node-0 Ready <none> 191d v1.17.3 192.168.10.2 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.3
node-1 Ready <none> 191d v1.17.3 192.168.10.3 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.3
B集群的信息
代码语言:javascript复制[deploy-B]$ kubectl get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master Ready master 191d v1.17.3 192.168.9.1 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.5
node-0 Ready <none> 191d v1.17.3 192.168.9.2 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.5
node-1 Ready <none> 191d v1.17.3 192.168.9.3 <none> CentOS Linux 7 (Core) 3.10.0-1062.12.1.el7.x86_64 docker://19.3.5
下载KubeFATE:
Kubefate 的开源地址https://github.com/FederatedAI/KubeFATE
打开链接https://github.com/FederatedAI/KubeFATE/releases
Kubefate是容器化部署FATE的最佳实践,项目更新较快,建议使用最新的releases。
下载 The KubeFATE release pack ,得到kubefate-k8s-v1.3.0-a.tar.gz
这个文件,解压下载的这个文件,得到一个可执行文件和四个 yaml 文件
# A集群解压
[deploy-A]$ tar -zxvf kubefate-k8s-v1.3.0-a.tar.gz
kubefate
cluster.yaml
config.yaml
kubefate.yaml
rbac-config.yaml
# B集群解压
[deploy-B]$ tar -zxvf kubefate-k8s-v1.3.0-a.tar.gz
kubefate
cluster.yaml
config.yaml
kubefate.yaml
rbac-config.yaml
在 Kubernetes 上安装 KubeFATE server
分别创建 KubeFATE server 的 namespace 和 RBAC 权限
在A集群和B集群分别部署rbac-config.yaml
# A集群
[deploy-A]$ kubectl apply -f ./rbac-config.yaml
namespace/kube-fate created
serviceaccount/kubefate-admin created
clusterrolebinding.rbac.authorization.k8s.io/kubefate created
# B集群
[deploy-B]$ kubectl apply -f ./rbac-config.yaml
namespace/kube-fate created
serviceaccount/kubefate-admin created
clusterrolebinding.rbac.authorization.k8s.io/kubefate created
部署 KubeFATE server
在A集群和B集群分别部署kubefate.yaml
# A集群
[deploy-A]$ kubectl apply -f ./kubefate.yaml
deployment.apps/kubefate created
deployment.apps/mongo created
service/mongo created
service/kubefate created
ingress.extensions/kubefate created
# B集群
[deploy-B]$ kubectl apply -f ./kubefate.yaml
deployment.apps/kubefate created
deployment.apps/mongo created
service/mongo created
service/kubefate created
ingress.extensions/kubefate created
查看部署结果
代码语言:javascript复制# A集群
[deploy-A]$ kubectl get pod,ingress -n kube-fate
NAME READY STATUS RESTARTS AGE
pod/kubefate-5465d889bb-4hwz6 1/1 Running 0 3m54s
pod/mongo-7b66bf7d87-hdl5c 1/1 Running 0 3m54s
NAME HOSTS ADDRESS PORTS AGE
ingress.extensions/kubefate kubefate.net 10.184.104.151 80 3m53s
# B集群
[deploy-B]$ kubectl get pod,ingress -n kube-fate
NAME READY STATUS RESTARTS AGE
pod/kubefate-64d57cb855-lks2f 1/1 Running 0 3m54s
pod/mongo-56684d6c86-96s96 1/1 Running 0 3m54s
NAME HOSTS ADDRESS PORTS AGE
ingress.extensions/kubefate kubefate.net 10.184.104.151 80 3m53s
如果两个pod的状态都是Running说明kubefate server已经部署成功了。
配置ingress host
分别在AB两个部署机配置 kubefate.net 的 ingress 解析
代码语言:javascript复制# A集群
# 查看ingress的pod运行的的node的名称
[deploy-A]$ kubectl get pod -A -o wide | grep ingress
kube-system nginx-ingress-controller-6fc5bcc8c9-l2vnx 1/1 Running 3 41h 172.17.0.2 node-0 <none> <none>
# B集群
# 查看ingress的pod运行的的node的名称
[deploy-B]$ kubectl get pod -A -o wide | grep ingress
kube-system nginx-ingress-controller-6d747b878f-9cdxt 1/1 Running 2 40h 172.17.0.2 node-0 <none> <none>
可以看到两边对应的 node 都是node-0
这个节点,通过前面查看的集群信息可以知道:
- A集群
node-0
的 ip 是192.168.10.2
- B集群
node-0
的 ip是192.168.9.2
分别设置对应的host
代码语言:javascript复制# A集群
[deploy-A]$ echo "192.168.10.2 kubefate.net" >> /etc/hosts
# B集群
[deploy-B]$ echo "192.168.9.2 kubefate.net" >> /etc/hosts
测试 kubefate 命令行工具与 KubeFATE server 的互通性
安装 kubefate 命令行工具
代码语言:javascript复制# A集群
[deploy-A]$ chmod x ./kubefate && sudo mv ./kubefate /usr/local/bin/kubefate
# B集群
[deploy-B]$ chmod x ./kubefate && sudo mv ./kubefate /usr/local/bin/kubefate
查看是否连通
代码语言:javascript复制# A集群
[deploy-A]$ kubefate version
* kubefate service version=v1.0.2 # 出现这一行表示kubefate server连通成功
* kubefate commandLine version=v1.0.2
# B集群
[deploy-B]$ kubefate version
* kubefate service version=v1.0.2 # 出现这一行表示kubefate server连通成功
* kubefate commandLine version=v1.0.2
分别修改需要部署的 PartyA 和 PartyB 的配置文件
cluster.yaml是 KubeFATE 部署 FATE 实例的部署配置文件,包含了 FATE 实例的一些基本信息,详细的介绍可以查看这里(https://github.com/FederatedAI/KubeFATE/blob/master/docs/configurations/FATE_cluster_configuration.md)。
PartyA的配置文件cluster-A.yaml
# A集群
name: fate-10000
namespace: fate-10000
chartName: fate
chartVersion: v1.3.0-a
partyId: 10000
modules:
- proxy
- egg
- federation
- metaService
- mysql
- redis
- roll
- python
proxy:
type: NodePort
nodePort: 30010
partyList:
- partyId: 9999
partyIp: 192.168.9.3
partyPort: 30009
egg:
count: 3
PartyB的配置文件cluster-B.yaml
# B集群
name: fate-9999
namespace: fate-9999
chartName: fate
chartVersion: v1.3.0-a
partyId: 9999
modules:
- proxy
- egg
- federation
- metaService
- mysql
- redis
- roll
- python
proxy:
type: NodePort
nodePort: 30009
partyList:
- partyId: 10000
partyIp: 192.168.10.3
partyPort: 30010
egg:
count: 3
创建需要的namespace
代码语言:javascript复制# A集群
[deploy-A]$ kubectl create namespace fate-10000
namespace/fate-10000 created
# B集群
[deploy-B]$ kubectl create namespace fate-9999
namespace/fate-9999 created
部署FATE
使用kubefate命令行工具部署FATE:
代码语言:javascript复制# A集群
[deploy-A]$ kubefate cluster install -f ./cluster-A.yaml
create job success, job id=5b37a5a3-f33b-4967-ae0c-73bea5770c49
# B集群
[deploy-B]$ kubefate cluster install -f ./cluster-B.yaml
create job success, job id=5b1dfdc9-7744-4911-a2e4-009e0fdfcb49
查看部署状态
部署 FATE 的时候会创建一个部署的 job,查看 job 的运行状态可以了解 FATE 是否部署成功。
代码语言:javascript复制# A集群
[deploy-A]$ kubefate job describe 5b37a5a3-f33b-4967-ae0c-73bea5770c49
UUID 5b37a5a3-f33b-4967-ae0c-73bea5770c49
StartTime 2020-04-23 07:06:19
EndTime 2020-04-23 07:06:22
Status Success
Creator admin
ClusterId 0e41ff79-d3be-416d-a53c-af13a7bfdf58
Result Cluster install success
SubJobs []
# B集群
[deploy-B]$ kubefate job describe 5b1dfdc9-7744-4911-a2e4-009e0fdfcb49
UUID 5b1dfdc9-7744-4911-a2e4-009e0fdfcb49
StartTime 2020-04-24 02:58:10
EndTime 2020-04-24 02:58:13
Status Success
Creator admin
ClusterId d8a1f86e-ac9b-4218-b569-b9093b34c911
Result Cluster install success
SubJobs []
查看 FATE 的信息,了解 FATE 的运行状态
代码语言:javascript复制# A集群
[deploy-A]$ kubefate cluster describe 0e41ff79-d3be-416d-a53c-af13a7bfdf58
UUID 0e41ff79-d3be-416d-a53c-af13a7bfdf58
Name fate-10000
NameSpace fate-10000
ChartName fate
ChartVersion v1.3.0-c
Revision 1
Status Running
Values {"chartName":"fate","chartVersion":"v1.3.0-c","egg":{"count":3},"modules":["proxy","egg","federation","metaService","mysql","redis","roll","python","client"],"name":"fate-10000","namespace":"fate-10000","partyId":10000,"proxy":{"nodePort":30010,"partyList":[{"partyId":9999,"partyIp":"192.168.9.3","partyPort":30009}],"type":"NodePort"}}
Config map[chartName:fate chartVersion:v1.3.0-c egg:map[count:3] modules:[proxy egg federation metaService mysql redis roll python client] name:fate-10000 namespace:fate-10000 partyId:10000 proxy:map[nodePort:30010 partyList:[map[partyId:9999 partyIp:192.168.9.3 partyPort:30009]] type:NodePort]]
Info map[dashboard:10000.fateboard.kubefate.net ip:192.168.10.3 modules:[client-6bdb7cd59d-whhx8 egg0-5b44548fbd-dwv7g egg1-685b57d7f5-ftpzg egg2-6687f8486b-f6nwn federation-6d799b5cfd-hrtnp meta-service-54db9f8fbc-6xv9q mysql-6bc77fc46c-fdlhp proxy-8d758c997-v6kq6 python-77bb96fd78-xnjgp redis-9546f56b-jbmxw roll-77dfbb54dc-2q2mb] port:30010]
# B集群
[deploy-B]$ kubefate cluster describe d8a1f86e-ac9b-4218-b569-b9093b34c911
UUID d8a1f86e-ac9b-4218-b569-b9093b34c911
Name fate-9999
NameSpace fate-9999
ChartName fate
ChartVersion v1.3.0-c
Revision 1
Status Running
Values {"chartName":"fate","chartVersion":"v1.3.0-c","egg":{"count":3},"modules":["proxy","egg","federation","metaService","mysql","redis","roll","python","client"],"name":"fate-9999","namespace":"fate-9999","partyId":9999,"proxy":{"nodePort":30009,"partyList":[{"partyId":10000,"partyIp":"192.168.10.3","partyPort":30010}],"type":"NodePort"}}
Config map[chartName:fate chartVersion:v1.3.0-c egg:map[count:3] modules:[proxy egg federation metaService mysql redis roll python client] name:fate-9999 namespace:fate-9999 partyId:9999 proxy:map[nodePort:30009 partyList:[map[partyId:10000 partyIp:192.168.10.3 partyPort:30010]] type:NodePort]]
Info map[dashboard:9999.fateboard.kubefate.net ip:192.168.9.3 modules:[client-7db8b9fb45-7scr7 egg0-79768fbffb-ndmq2 egg1-6bd6b965cf-vrkmz egg2-67d896f78-b7dz8 federation-547dfd8654-xmhcx meta-service-9c74f597f-t9zlw mysql-7788cc95-b24vz proxy-6687bffc77-hjj5x python-68df558bb6-bhxr7 redis-864f95f74-p86pv roll-bf7cf74c9-52qqj] port:30009]
配置 FATEboard 的 host
分别配置双方的 FATEboard 和 notebook 的 host,就像配置kubefate.net一样,我们只需要向hosts文件添加一行记录,就可以在浏览器查看使用 FATEboard 和 notebook
代码语言:javascript复制# A集群
[deploy-A]$ echo "192.168.10.2 10000.fateboard.kubefate.net" >> /etc/hosts
# B集群
[deploy-B]$ echo "192.168.9.2 9999.fateboard.kubefate.net" >> /etc/hosts
配置成功后可以在浏览器打开 FATEBoard 的 url 查看
10000.fateboard.kubefate.net
9999.fateboard.kubefate.net
类似如下的页面:
检查 Party A和 PartyB 双方的互通性
互相连通的两个 party 就可以完成各种联邦学习的任务,接下来我们通过 toy_example 来测试双方的互通性。
打开 PartyA 的 python container,
代码语言:javascript复制# A集群
[deploy-A]$ kubectl exec -it svc/fateflow -c python -n fate-10000 -- bash
(venv) [root@python-77bb96fd78-xnjgp python]
执行 toy_example 脚本,
代码语言:javascript复制(venv) [root@python-77bb96fd78-xnjgp python]# cd examples/toy_example/
(venv) [root@python-77bb96fd78-xnjgp toy_example]# python run_toy_example.py 10000 9999 1
stdout:{
"data": {
"board_url": "http://fateboard:8080/index.html#/dashboard?job_id=202004270647307032491&role=guest&party_id=10000",
"job_dsl_path": "/data/projects/fate/python/jobs/202004270647307032491/job_dsl.json",
"job_runtime_conf_path": "/data/projects/fate/python/jobs/202004270647307032491/job_runtime_conf.json",
"logs_directory": "/data/projects/fate/python/logs/202004270647307032491",
"model_info": {
"model_id": "guest-10000#host-9999#model",
"model_version": "202004270647307032491"
}
},
"jobId": "202004270647307032491",
"retcode": 0,
"retmsg": "success"
}
job status is running
job status is running
job status is running
...
如果出现下面的结果代表双方已经成功互通,
打开 PartyA 的 FATEBoard(10000.fateboard.kubefate.net)可以查看更详细的任务信息。
到这里两个 Kubernetes 分别部署 FATE 实例就完成了,接下就可以使用 notebook 来做自己的联邦学习的任务了。
往期精彩回顾
- 使用KubeFATE快速部署联邦学习实验开发环境(一)
- 使用KubeFATE快速部署联邦学习实验开发环境(二)
- 使用FATE进行图片识别的深度神经网络联邦学习
- 使用KubeFATE在Kubernetes上部署联邦学习集群