Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: specify the host IP as the k8s internal IP #5196

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/runtime/kubernetes/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ func (k *KubeadmRuntime) setAPIServerEndpoint(endpoint string) {
k.kubeadmConfig.JoinConfiguration.Discovery.BootstrapToken.APIServerEndpoint = endpoint
}

func (k *KubeadmRuntime) setJoinInternalIP(nodeIP string) {
k.kubeadmConfig.JoinConfiguration.NodeRegistration.KubeletExtraArgs = map[string]string{
"node-ip": nodeIP,
}
}
func (k *KubeadmRuntime) setInitInternalIP(nodeIP string) {
k.kubeadmConfig.InitConfiguration.NodeRegistration.KubeletExtraArgs = map[string]string{
"node-ip": nodeIP,
}
}

func (k *KubeadmRuntime) setInitAdvertiseAddress(advertiseAddress string) {
k.kubeadmConfig.InitConfiguration.LocalAPIEndpoint.AdvertiseAddress = advertiseAddress
}
Expand Down Expand Up @@ -459,6 +470,7 @@ func (k *KubeadmRuntime) CompleteKubeadmConfig(fns ...func(*KubeadmRuntime) erro
}
}
k.setInitAdvertiseAddress(k.getMaster0IP())
k.setInitInternalIP(k.getMaster0IP())
k.setControlPlaneEndpoint(fmt.Sprintf("%s:%d", k.getAPIServerDomain(), k.getAPIServerPort()))
if k.kubeadmConfig.ClusterConfiguration.APIServer.ExtraArgs == nil {
k.kubeadmConfig.ClusterConfiguration.APIServer.ExtraArgs = make(map[string]string)
Expand All @@ -481,6 +493,7 @@ func (k *KubeadmRuntime) generateJoinNodeConfigs(node string) ([]byte, error) {
}
k.cleanJoinLocalAPIEndPoint()
k.setAPIServerEndpoint(k.getVipAndPort())
k.setJoinInternalIP(iputils.GetHostIP(node))

conversion, err := k.kubeadmConfig.ToConvertedKubeadmConfig()
if err != nil {
Expand All @@ -499,6 +512,7 @@ func (k *KubeadmRuntime) generateJoinMasterConfigs(masterIP string) ([]byte, err
return nil, err
}
k.setJoinAdvertiseAddress(iputils.GetHostIP(masterIP))
k.setJoinInternalIP(iputils.GetHostIP(masterIP))
k.setAPIServerEndpoint(fmt.Sprintf("%s:%d", k.getMaster0IP(), k.getAPIServerPort()))

conversion, err := k.kubeadmConfig.ToConvertedKubeadmConfig()
Expand Down
Loading