为什么kube-scheduler启动后https长连接数量是2

k8s v1.19.0

单节点集群2条长连接

编译二进制并调试

cd cmd/kube-scheduler && go build

# vscode launch.json
{
    "name": "Launch",
    "type": "go",
    "request": "launch",
    "mode": "exec",
    "program": "/root/code/gomod/k8s.io/kubernetes/cmd/kube-scheduler/kube-scheduler",
    "env": {},
    "args": ["--authentication-kubeconfig=/etc/kubernetes/scheduler.conf", "--authorization-kubeconfig=/etc/kubernetes/scheduler.conf", "--bind-address=127.0.0.1", "--kubeconfig=/etc/kubernetes/scheduler.conf", "--leader-elect=true", "--port=0"]
}

不同类型client增加2条长连接

基于rest.InClusterConfig()创建第1条长连接

rest.InClusterConfig方法可以获取spec.serviceAccountName对应的token,由informer维持。

cmd/kube-scheduler/app/options/options.go
Config方法

staging/src/k8s.io/apiserver/pkg/authentication/request/headerrequest/requestheader_controller.go
RunOnce方法

基于启动参数kubeconfig创建第2条长连接

所在组和用户,与前面spec.serviceAccountName对应的token不同,由leader-election维持,与设置的user-agent无关。

cmd/kube-scheduler/app/options/options.go
Config方法

staging/src/k8s.io/client-go/discovery/discovery_client.go
ServerResourcesForGroupVersion方法

informer和leaderElector维持2条长连接

cmd/kube-scheduler/app/server.go
Run函数

pkg/scheduler/factory.go
NewPodInformer函数
kube-scheduler只关心status.phase!=Succeeded和Failed的Pod。

posted on 2024-02-06 21:34  王景迁  阅读(13)  评论(0编辑  收藏  举报

导航