KubeSphere ks-apiserver本地调试开发
- 环境准备 准备好go环境,在任意环境部署好KubeSphere,参考KubeSphere官网。
- 下载源码
mkdir KubeSphere
cd KubeSphere
git clone https://github.com/kubesphere/kubesphere
-
找到入口函数 cmd/ks-apiserver/apiserver.go
-
可以先试着启动一下,如果直接启动会报找不到配置文件,启动apiserver需要连接我们的KubeSphere的集群。
pkg/apiserver/config/config.go
const (
// DefaultConfigurationName is the default name of configuration
defaultConfigurationName = "kubesphere"
// DefaultConfigurationPath the default location of the configuration file
defaultConfigurationPath = "/etc/kubesphere"//将这个地方改成你自己的目录
在这个目录下导入你KubeSphere集群ks-apiserver服务的/etc/kubesphere位置下的yaml文件。当然你也可以自己写
authentication:
authenticateRateLimiterMaxTries: 10
authenticateRateLimiterDuration: 10m0s
loginHistoryRetentionPeriod: 168h
maximumClockSkew: 10s
multipleLogin: True
kubectlImage: registry.cn-beijing.aliyuncs.com/kubesphereio/kubectl:v1.18.0
jwtSecret: "xxxx"
network:
ippoolType: none
monitoring:
endpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090
还有另一个地方的配置文件
pkg/models/routers/routers.go
const (
servicemeshEnabled = "servicemesh.kubesphere.io/enabled"
sidecarInject = "sidecar.istio.io/inject"
ingressControllerFolder = "etc/kubesphere/ingress-controller"//改成你自己的目录
ingressControllerPrefix = "kubesphere-router-"
ingressControllerNamespace = "kubesphere-controls-system"
configMapSuffix = "-nginx"
)
同理,导入集群里的配置。
5. 这时候你可以启动了,但是访问接口会报403。在集群里使用如下命令。
kubectl create clusterrolebinding cluster-system-anonymous --clusterrole=cluster-admin --user=system:anonymous
这样就可以访问api了。接下来你可以自己开发调试了。
ks-apiserver 源码解析
后续更新。