Skip to content

Commit

Permalink
regenrate kubelet kubeconfig to have server as node ip instead of vip (
Browse files Browse the repository at this point in the history
…#165)

Signed-off-by: Piyush Kumar <[email protected]>
  • Loading branch information
kpiyush17 authored Jan 8, 2025
1 parent 3357ed9 commit 1109a69
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 4 additions & 0 deletions scripts/kube-reconfigure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ regenerate_apiserver_certs_sans() {

regenerate_kubelet_envs() {
echo "$kubelet_envs" > /var/lib/kubelet/kubeadm-flags.env

mv /etc/kubernetes/kubelet.conf /etc/kubernetes/kubelet.conf.bak
kubeadm init phase kubeconfig kubelet

systemctl restart kubelet
}

Expand Down
12 changes: 6 additions & 6 deletions stages/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func GetInitYipStagesV1Beta3(clusterCtx *domain.ClusterContext, kubeadmConfig do
getKubeadmPostInitStage(clusterCtx.RootPath),
getKubeadmInitUpgradeStage(clusterCtx),
getKubeadmInitCreateClusterConfigStage(&kubeadmConfig.ClusterConfiguration, &kubeadmConfig.InitConfiguration, clusterCtx.RootPath),
getKubeadmInitCreateKubeletConfigStage(kubeadmConfig.KubeletConfiguration, clusterCtx.RootPath),
getKubeadmInitCreateKubeletConfigStage(&kubeadmConfig.ClusterConfiguration, &kubeadmConfig.KubeletConfiguration, clusterCtx.RootPath),
getKubeadmInitReconfigureStage(clusterCtx),
}
}
Expand All @@ -68,7 +68,7 @@ func GetInitYipStagesV1Beta4(clusterCtx *domain.ClusterContext, kubeadmConfig do
getKubeadmPostInitStage(clusterCtx.RootPath),
getKubeadmInitUpgradeStage(clusterCtx),
getKubeadmInitCreateClusterConfigStage(&kubeadmConfig.ClusterConfiguration, &kubeadmConfig.InitConfiguration, clusterCtx.RootPath),
getKubeadmInitCreateKubeletConfigStage(kubeadmConfig.KubeletConfiguration, clusterCtx.RootPath),
getKubeadmInitCreateKubeletConfigStage(&kubeadmConfig.ClusterConfiguration, &kubeadmConfig.KubeletConfiguration, clusterCtx.RootPath),
getKubeadmInitReconfigureStage(clusterCtx),
}
}
Expand Down Expand Up @@ -133,8 +133,8 @@ func getKubeadmInitCreateClusterConfigStage(clusterCfgObj, initCfgObj runtime.Ob
return utils.GetFileStage("Generate Cluster Config File", filepath.Join(rootPath, configurationPath, "cluster-config.yaml"), getUpdatedInitClusterConfig(clusterCfgObj, initCfgObj))
}

func getKubeadmInitCreateKubeletConfigStage(kubeletCfg kubeletv1beta1.KubeletConfiguration, rootPath string) yip.Stage {
return utils.GetFileStage("Generate Kubelet Config File", filepath.Join(rootPath, configurationPath, "kubelet-config.yaml"), getUpdatedKubeletConfig(kubeletCfg))
func getKubeadmInitCreateKubeletConfigStage(clusterCfgObj, kubeletCfg runtime.Object, rootPath string) yip.Stage {
return utils.GetFileStage("Generate Kubelet Config File", filepath.Join(rootPath, configurationPath, "kubelet-config.yaml"), getUpdatedKubeletConfig(clusterCfgObj, kubeletCfg))
}

func getKubeadmInitReconfigureStage(clusterCtx *domain.ClusterContext) yip.Stage {
Expand Down Expand Up @@ -229,8 +229,8 @@ func getUpdatedInitClusterConfig(clusterCfgObj, initCfgObj runtime.Object) strin
return printObj([]runtime.Object{clusterCfgObj, initCfgObj})
}

func getUpdatedKubeletConfig(kubeletCfg kubeletv1beta1.KubeletConfiguration) string {
return printObj([]runtime.Object{&kubeletCfg})
func getUpdatedKubeletConfig(clusterCfgObj, kubeletCfg runtime.Object) string {
return printObj([]runtime.Object{clusterCfgObj, kubeletCfg})
}

func printObj(objects []runtime.Object) string {
Expand Down
10 changes: 4 additions & 6 deletions stages/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (

"github.com/kairos-io/kairos/provider-kubeadm/domain"

kubeletv1beta1 "k8s.io/kubelet/config/v1beta1"

"github.com/kairos-io/kairos-sdk/clusterplugin"
"github.com/kairos-io/kairos/provider-kubeadm/utils"
yip "github.com/mudler/yip/pkg/schema"
Expand All @@ -36,7 +34,7 @@ func GetJoinYipStagesV1Beta3(clusterCtx *domain.ClusterContext, kubeadmConfig do
if clusterCtx.NodeRole != clusterplugin.RoleWorker {
joinStg = append(joinStg,
getKubeadmJoinCreateClusterConfigStage(&kubeadmConfig.ClusterConfiguration, &kubeadmConfig.InitConfiguration, &kubeadmConfig.JoinConfiguration, clusterCtx.RootPath),
getKubeadmJoinCreateKubeletConfigStage(kubeadmConfig.KubeletConfiguration, clusterCtx.RootPath))
getKubeadmJoinCreateKubeletConfigStage(&kubeadmConfig.ClusterConfiguration, &kubeadmConfig.KubeletConfiguration, clusterCtx.RootPath))
}

return append(joinStg, getKubeadmJoinReconfigureStage(clusterCtx))
Expand All @@ -58,7 +56,7 @@ func GetJoinYipStagesV1Beta4(clusterCtx *domain.ClusterContext, kubeadmConfig do
if clusterCtx.NodeRole != clusterplugin.RoleWorker {
joinStg = append(joinStg,
getKubeadmJoinCreateClusterConfigStage(&kubeadmConfig.ClusterConfiguration, &kubeadmConfig.InitConfiguration, &kubeadmConfig.JoinConfiguration, clusterCtx.RootPath),
getKubeadmJoinCreateKubeletConfigStage(kubeadmConfig.KubeletConfiguration, clusterCtx.RootPath))
getKubeadmJoinCreateKubeletConfigStage(&kubeadmConfig.ClusterConfiguration, &kubeadmConfig.KubeletConfiguration, clusterCtx.RootPath))
}

return append(joinStg, getKubeadmJoinReconfigureStage(clusterCtx))
Expand Down Expand Up @@ -198,8 +196,8 @@ func getKubeadmJoinCreateClusterConfigStage(clusterCfgObj, initCfgObj, joinCfgOb
return utils.GetFileStage("Generate Cluster Config File", filepath.Join(rootPath, configurationPath, "cluster-config.yaml"), getUpdatedJoinClusterConfig(clusterCfgObj, initCfgObj, joinCfgObj))
}

func getKubeadmJoinCreateKubeletConfigStage(kubeletCfg kubeletv1beta1.KubeletConfiguration, rootPath string) yip.Stage {
return utils.GetFileStage("Generate Kubelet Config File", filepath.Join(rootPath, configurationPath, "kubelet-config.yaml"), getUpdatedKubeletConfig(kubeletCfg))
func getKubeadmJoinCreateKubeletConfigStage(clusterCfgObj, kubeletCfg runtime.Object, rootPath string) yip.Stage {
return utils.GetFileStage("Generate Kubelet Config File", filepath.Join(rootPath, configurationPath, "kubelet-config.yaml"), getUpdatedKubeletConfig(clusterCfgObj, kubeletCfg))
}

func getKubeadmJoinReconfigureStage(clusterCtx *domain.ClusterContext) yip.Stage {
Expand Down

0 comments on commit 1109a69

Please sign in to comment.