Commit 06f3b35f authored by kaiyou's avatar kaiyou
Browse files

Make the kubelet port (10250) configurable

parent 2250a8a3
Pipeline #721 passed with stage
in 2 minutes and 42 seconds
......@@ -466,6 +466,7 @@ func get(envInfo *cmds.Agent) (*config.Node, error) {
os.Setenv("NODE_NAME", nodeConfig.AgentConfig.NodeName)
nodeConfig.AgentConfig.KubeletPort = envInfo.KubeletPort
nodeConfig.AgentConfig.ExtraKubeletArgs = envInfo.ExtraKubeletArgs
nodeConfig.AgentConfig.ExtraKubeProxyArgs = envInfo.ExtraKubeProxyArgs
......
......@@ -23,13 +23,6 @@ import (
"k8s.io/client-go/tools/clientcmd"
)
var (
ports = map[string]bool{
"10250": true,
"10010": true,
}
)
func getAddresses(endpoint *v1.Endpoints) []string {
serverAddresses := []string{}
if endpoint == nil {
......@@ -83,10 +76,12 @@ func Setup(ctx context.Context, config *config.Node, onChange func([]string)) er
disconnect := map[string]context.CancelFunc{}
validPorts := map[string]bool{string(config.Containerd.Port): true, string(config.AgentConfig.KubeletPort): true}
wg := &sync.WaitGroup{}
for _, address := range addresses {
if _, ok := disconnect[address]; !ok {
disconnect[address] = connect(ctx, wg, address, tlsConfig)
disconnect[address] = connect(ctx, wg, address, tlsConfig, validPorts)
}
}
......@@ -134,7 +129,7 @@ func Setup(ctx context.Context, config *config.Node, onChange func([]string)) er
for _, address := range addresses {
validEndpoint[address] = true
if _, ok := disconnect[address]; !ok {
disconnect[address] = connect(ctx, nil, address, tlsConfig)
disconnect[address] = connect(ctx, nil, address, tlsConfig, validPorts)
}
}
......@@ -166,7 +161,7 @@ func Setup(ctx context.Context, config *config.Node, onChange func([]string)) er
return nil
}
func connect(rootCtx context.Context, waitGroup *sync.WaitGroup, address string, tlsConfig *tls.Config) context.CancelFunc {
func connect(rootCtx context.Context, waitGroup *sync.WaitGroup, address string, tlsConfig *tls.Config, validPorts map[string]bool) context.CancelFunc {
wsURL := fmt.Sprintf("wss://%s/v1-k3s/connect", address)
ws := &websocket.Dialer{
TLSClientConfig: tlsConfig,
......@@ -183,7 +178,7 @@ func connect(rootCtx context.Context, waitGroup *sync.WaitGroup, address string,
for {
remotedialer.ClientConnect(ctx, wsURL, nil, ws, func(proto, address string) bool {
host, port, err := net.SplitHostPort(address)
return err == nil && proto == "tcp" && ports[port] && host == "127.0.0.1"
return err == nil && proto == "tcp" && validPorts[port] && host == "127.0.0.1"
}, func(_ context.Context) error {
if waitGroup != nil {
once.Do(waitGroup.Done)
......
......@@ -22,6 +22,7 @@ type Agent struct {
Docker bool
ContainerRuntimeEndpoint string
ContainerdPort int
KubeletPort int
NoFlannel bool
FlannelIface string
FlannelConf string
......@@ -81,6 +82,12 @@ var (
Destination: &AgentConfig.ContainerdPort,
Value: 10010,
}
KubeletPortFlag = cli.IntFlag{
Name: "kubelet-port",
Usage: "(agent/runtime) Specify the kubelet listen port",
Destination: &AgentConfig.KubeletPort,
Value: 10250,
}
PrivateRegistryFlag = cli.StringFlag{
Name: "private-registry",
Usage: "(agent/runtime) Private registry configuration file",
......@@ -178,6 +185,7 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
DockerFlag,
CRIEndpointFlag,
ContainerdPortFlag,
KubeletPortFlag,
PauseImageFlag,
PrivateRegistryFlag,
NodeIPFlag,
......
......@@ -217,6 +217,7 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
DockerFlag,
CRIEndpointFlag,
ContainerdPortFlag,
KubeletPortFlag,
PauseImageFlag,
PrivateRegistryFlag,
NodeIPFlag,
......
......@@ -58,6 +58,7 @@ func startKubeProxy(cfg *config.Agent) {
func startKubelet(cfg *config.Agent) {
argsMap := map[string]string{
"healthz-bind-address": "127.0.0.1",
"port": string(cfg.KubeletPort),
"read-only-port": "0",
"cluster-domain": cfg.ClusterDomain,
"kubeconfig": cfg.KubeConfigKubelet,
......
......@@ -68,6 +68,7 @@ type Agent struct {
ClientCA string
CNIBinDir string
CNIConfDir string
KubeletPort int
ExtraKubeletArgs []string
ExtraKubeProxyArgs []string
PauseImage string
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment