kubernetes-learning-playground / multi-clusters Goto Github PK
View Code? Open in Web Editor NEW简易型k8s多集群控制器
简易型k8s多集群控制器
实现多集群查询功能。
实现命令行工具,提供类似 kube-mutli-cluster get pods -c cluster1 的功能
目前无法展示多集群中有多少集群资源对象,需要开发新的命令 如:kubectl-multicluster list cluster
ex: 新增 annotation 改变副本数等等
支持 apply delete 等 kubectl 原生功能,增强用户对 kubectl-multicluster 命令行的依赖,不至于查询的时候使用 kubectl-multicluster而创建资源时使用 kubectl 。
目前使用gin实现 http server,预计修改为 聚合api server
将启动项目与结构改为接近k8s风格,方便扩展
// FIXME: 目前默认集群状态永远只有 "Running",不会有状态切换
// 预计要定时轮询巡检特定节点集群是否正常
[root@VM-0-16-centos ~]# kubectl-multicluster list clusters
集群名称 状态 是否为主集群
tencent1 Running false
tencent2 Running false
tencent4 Running true
因为marshal时,只获取runtime.object字段,集群名字段没有拿出
➜ cmd git:(main) go run ctl_plugin/main.go deployments
集群名称 DEPLOYMENT NAMESPACE TOTAL AVAILABLE READY
patch-deployment default 2 2 2
kueue-controller-manager kueue-system 1 1 1
dep-test default 5 5 5
testngx default 10 10 10
test-pod-maxnum-scheduler kube-system 1 1 1
testngx default 10 10 10
test-pod-maxnum-scheduler kube-system 1 1 1
预计使用简易版 operator 实现多集群的下发
helm dockerfile yaml等
[root@VM-0-16-centos ~]# kubectl-multicluster list pods
集群名称 NAME NAMESPACE NODE POD IP 状态 容器名 容器镜像
tencent1 multiclusterresource-deployment-75d98bb7bd-d42kz default vm-0-17-centos 10.244.167.205 Running example-container nginx:1.19.0-alpine
tencent4 multiclusterresource-deployment-75d98bb7bd-r5v8p default vm-0-16-centos 10.244.0.195 Running example-container nginx:1.19.0-alpine
tencent4 multiclusterresource-deployment-75d98bb7bd-22tbg default vm-0-16-centos 10.244.0.194 Running example-container nginx:1.19.0-alpine
tencent2 multiclusterresource-deployment-7c6dcfd8dd-xnnsf default vm-0-13-centos 10.244.0.49 Running example-container nginx:latest
计画改成 v1.pods,支持任何 k8s 资源对象输入
[root@VM-0-16-centos ~]# kubectl-multicluster list v1.pods
集群名称 NAME NAMESPACE NODE POD IP 状态 容器名 容器镜像
tencent1 multiclusterresource-deployment-75d98bb7bd-d42kz default vm-0-17-centos 10.244.167.205 Running example-container nginx:1.19.0-alpine
tencent4 multiclusterresource-deployment-75d98bb7bd-r5v8p default vm-0-16-centos 10.244.0.195 Running example-container nginx:1.19.0-alpine
tencent4 multiclusterresource-deployment-75d98bb7bd-22tbg default vm-0-16-centos 10.244.0.194 Running example-container nginx:1.19.0-alpine
tencent2 multiclusterresource-deployment-7c6dcfd8dd-xnnsf default vm-0-13-centos 10.244.0.49 Running example-container nginx:latest
目前启动哪些资源是代码中写死的,预计抽象出配置文件 config.yaml。
把需要启动哪些资源使用配置的方式写出来。
ex:
如果在 server 启动步骤创建 config 文件夹是没有用的
在容器中没有映射
预计使用 bash 脚本的方式创建 config 文件
placement:
clusters:
- name: tencent1
- name: tencent2
- name: tencent4
目前只有简单字段,考虑增加 clusterSelector字段
[root@VM-0-16-centos helm]# kubectl get pods
NAME READY STATUS RESTARTS AGE
multi-cluster-operator-6c6fc9dcc9-xs79f 0/1 Error 1 (1s ago) 2s
[root@VM-0-16-centos helm]# kubectl logs multi-cluster-operator-6c6fc9dcc9-xs79f
F0129 10:02:52.587503 1 mysql_options.go:144] Failed to apply migrations: Dirty database version 1. Fix and force version.
感觉是 go-migrate 使用的问题
之前写代码时忘记加上 ownerReferences ,日后补上!!
目前仅支持单一集群资源入库,未来预计支持多集群模式
操作多集群时,会需要用到各自集群的 restconfig 对象,目前使用配置文件 + volume 挂载的方式,感觉不是特别好。
是否可以做一个服务,专门用于获取不同集群的 restconfig
使用 golang代码完成自动创建表结构
目前的集群没有进行 cr 自定义资源的描述,没有办法进行 describe 命令展示,只有 list。
[root@VM-0-16-centos yaml]# kubectl-multicluster list clusters
集群名称 状态 是否为主集群
tencent4 Running true
tencent1 Running false
tencent2 Running false
考虑采用第三方方案 "Submariner"
karmada kube-ovn 都有相关文档
https://kubeovn.github.io/docs/v1.12.x/advance/with-submariner/
https://submariner.io/operations/deployment/helm/
https://karmada.io/zh/docs/userguide/network/working-with-submariner/
例如:当原集群只有 cluster1时,动态加入cluster2
此时都正常,但是当应用重启后,又只会剩下 cluster1 连接而已
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.