Cluster Management API 简称为 Cluster API,它正是在这种情况下诞生的。对于混合云和多云环境,我们需要使用 Kubernetes 原生方式来帮助用户管理(创建/删除/添加节点/删除节点)不同云提供商的 Kubernetes 集群,如 AWS、Azure、GCE、OpenStack 和 IBM Cloud™。
Cluster API 简介
Cluster API 是一个 Kubernetes 项目,它使用 Kuberentes 原生方式来创建、配置和管理集群。它可在 Kubernetes 核心的基础上提供可选的附加功能。
Cluster API 可被视为通用的 Kubernetes 集群管理框架,但您可能想要基于 Cluster API 实施自己的云提供商服务。现在有许多不同种类的云提供商都以 Cluster API 为基础,如 AWS、Azure、GCE、OpenStack 和 IBM Cloud。您可从 此处 获取云提供商的完整列表。
provider os 用于指定将运行 Kubernetes 的虚拟机的操作系统;当前仅支持 Ubuntu 和 Centos。
在我此处的示例中,我使用以下命令在以 Ubuntu 作为 VM 操作系统的 OpenStack 云中配置自己的 Kubernetes 集群。
1 2
./generate-yaml.sh ./clouds.yaml openstack ubuntu
Show moreShow more icon
完成此命令后,它将生成两个对象:当前目录中名为 out 的文件夹,以及一对新的 SSH 密钥(存储为 $HOME/.ssh/openstack\_tmp 和 $HOME/.ssh/openstack\_tmp.pub)。
out 文件夹将包含三个文件:
1 2 3
root@gyliu-dev1:~/go/src/sigs.k8s.io/cluster-api-provider-openstack/cmd/clusterctl/examples/openstack# ls out cluster.yaml machines.yaml provider-components.yaml
root@liugya-master-cpr5j:/home/cloudusr# kubectl get deploy -n openstack-provider-system NAME READY UP-TO-DATE AVAILABLE AGE clusterapi-controllers 1/1 1 1 3h8m root@liugya-master-cpr5j:/home/cloudusr# kubectl get sts -n system NAME READY AGE controller-manager 1/1 3h9m
Show moreShow more icon
controller-manager 用于管理 Cluster API 的部分通用资源,如 MachineSet、MachineDeployment 和 Node。
root@liugya-master-fx9nn:~# kubectl get clusters NAME AGE test1 33h root@liugya-master-fx9nn:~# kubectl get machines NAME AGE liugya-master-fx9nn 33h liugya-node-qknd7 33h root@liugya-master-cpr5j:~# kubectl get nodes NAME STATUS ROLES AGE VERSION liugya-master-cpr5j Ready master 3h50m v1.14.0 liugya-node-ngw58 Ready <none> 3h47m v1.14.0
root@liugya-master-cpr5j:~# kubectl delete machine liugya-node-ngw58 machine.cluster.k8s.io "liugya-node-ngw58" deleted root@liugya-master-cpr5j:~# kubectl get machines NAME AGE liugya-master-cpr5j 4h38m root@liugya-master-cpr5j:~# kubectl get nodes NAME STATUS ROLES AGE VERSION liugya-master-cpr5j Ready master 4h40m v1.14.0
Show moreShow more icon
可以看到此工作节点现已被删除,如果您转至自己的 OpenStack 仪表板,还可看到工作节点的 VM 同样也被删除。
root@liugya-master-cpr5j:~# kubectl apply -f node.yaml machine.cluster.k8s.io/liugya-node-1 created root@liugya-master-cpr5j:~# kubectl get machines NAME AGE liugya-master-cpr5j 5h24m liugya-node-1 5s
I0404 08:11:32.266191 1 controller.go:114] Running reconcile Machine for liugya-node-1 I0404 08:11:32.274115 1 controller.go:114] Running reconcile Machine for liugya-node-1 I0404 08:11:32.883271 1 controller.go:184] Reconciling machine object liugya-node-1 triggers idempotent create. I0404 08:11:33.898700 1 actuator.go:132] Creating bootstrap token W0404 08:12:21.943293 1 controller.go:186] unable to create machine liugya-node-1: Operation cannot be fulfilled on machines.cluster.k8s.io "liugya-node-1": the object has been modified; please apply your changes to the latest version and try again I0404 08:12:22.944113 1 controller.go:114] Running reconcile Machine for liugya-node-1 I0404 08:12:23.969128 1 controller.go:173] Reconciling machine object liugya-node-1 triggers idempotent update. I0404 08:12:24.639494 1 actuator.go:217] Populating current state for boostrap machine liugya-node-1 I0404 08:12:25.245633 1 controller.go:114] Running reconcile Machine for liugya-node-1 I0404 8:12:26.043068 1 controller.go:173] Reconciling machine object liugya-node-1 triggers idempotent update.
Show moreShow more icon
OpenStack 配置完机器后,您将看到新机器同样已连接到 Kubernetes 集群。
1 2 3 4 5 6 7 8 9
root@liugya-master-cpr5j:~# kubectl get machines kubec NAME AGE liugya-master-cpr5j 5h40m liugya-node-1 16m root@liugya-master-cpr5j:~# kubectl get nodes NAME STATUS ROLES AGE VERSION liugya-master-cpr5j Ready master 5h40m v1.14.0 liugya-node-1 Ready <none> 14m v1.14.0
Reprint policy:
All articles in this blog are used except for special statements
CC BY 4.0
reprint policy. If reproduced, please indicate source
John Doe
!