KubeSphere ks-apiserver本地调试开发及源码解析

KubeSphere ks-apiserver本地调试开发

  1. 环境准备 准备好go环境,在任意环境部署好KubeSphere,参考KubeSphere官网。
  2. 下载源码
 mkdir KubeSphere
 cd KubeSphere
 git clone https://github.com/kubesphere/kubesphere 
  1. 找到入口函数 cmd/ks-apiserver/apiserver.go

  2. 可以先试着启动一下,如果直接启动会报找不到配置文件,启动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 源码解析

后续更新。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值