Skip to content

Commit

Permalink
Change IPs from external to local
Browse files Browse the repository at this point in the history
Signed-off-by: Leonid Kondrashov <[email protected]>
  • Loading branch information
leokondrashov committed Apr 10, 2024
1 parent 5143a83 commit 848c27b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
7 changes: 4 additions & 3 deletions scripts/cluster/create_multinode_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ func CreateMasterKubeletService() error {
if !utils.CheckErrorWithMsg(err, "Failed to create kubelet service!\n") {
return err
}
nodeIP, _ := utils.GetNodeIP()
bashCmd := `sudo sh -c 'cat <<EOF > /etc/default/kubelet
KUBELET_EXTRA_ARGS="--v=%d --runtime-request-timeout=15m --container-runtime-endpoint=unix:///run/containerd/containerd.sock"
KUBELET_EXTRA_ARGS="--v=%d --runtime-request-timeout=15m --container-runtime-endpoint=unix:///run/containerd/containerd.sock --node-ip %s"
EOF'`
_, err = utils.ExecShellCmd(bashCmd, configs.System.LogVerbosity)
_, err = utils.ExecShellCmd(bashCmd, configs.System.LogVerbosity, nodeIP)
if !utils.CheckErrorWithMsg(err, "Failed to create kubelet service!\n") {
return err
}
Expand All @@ -98,7 +99,7 @@ EOF'`
func DeployKubernetes() error {

utils.WaitPrintf("Deploying Kubernetes(version %s)", configs.Kube.K8sVersion)
masterNodeIp, iperr := utils.ExecShellCmd(`ip route | awk '{print $(NF)}' | awk '/^10\..*/'`)
masterNodeIp, iperr := utils.GetNodeIP()
if iperr != nil {
return iperr
}
Expand Down
5 changes: 3 additions & 2 deletions scripts/cluster/setup_worker_kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ func CreateWorkerKubeletService(criSock string) error {
if !utils.CheckErrorWithMsg(err, "Failed to create kubelet service!\n") {
return err
}
nodeIP, _ := utils.GetNodeIP()
bashCmd := `sudo sh -c 'cat <<EOF > /etc/default/kubelet
KUBELET_EXTRA_ARGS="--v=%d --runtime-request-timeout=15m --container-runtime-endpoint=unix://%s"
KUBELET_EXTRA_ARGS="--v=%d --runtime-request-timeout=15m --container-runtime-endpoint=unix://%s --node-ip %s"
EOF'`
_, err = utils.ExecShellCmd(bashCmd, configs.System.LogVerbosity, criSock)
_, err = utils.ExecShellCmd(bashCmd, configs.System.LogVerbosity, criSock, nodeIP)
if !utils.CheckErrorWithMsg(err, "Failed to create kubelet service!\n") {
return err
}
Expand Down
1 change: 1 addition & 0 deletions scripts/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func main() {

if err != nil {
utils.FatalPrintf("Faild subcommand: %s!\n", subCmd)
utils.ErrorPrintf("%v\n", err)
utils.CleanEnvironment()
os.Exit(1)
}
Expand Down
9 changes: 9 additions & 0 deletions scripts/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,12 @@ func InstallYQ() {
_, err := ExecShellCmd(`sudo wget %s -O /usr/bin/yq && sudo chmod +x /usr/bin/yq`, yqUrl)
CheckErrorWithMsg(err, "Failed to add yq!\n")
}

func GetNodeIP() (string, error) {
nodeIP, err := ExecShellCmd(`ip route | awk '{print $(NF)}' | awk '/^10\..*/'`)
if err != nil {
CheckErrorWithMsg(err, "Failed to get node IP!\n")
return "", err
}
return nodeIP, nil
}

0 comments on commit 848c27b

Please sign in to comment.