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 <leo.kondrashov@gmail.com>
  • Loading branch information
leokondrashov committed Apr 12, 2024
1 parent 41785cd commit bb82821
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
9 changes: 5 additions & 4 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 Expand Up @@ -191,7 +192,7 @@ func WaitForWorkerNodes() error {
var userInput string
var allNodesJoined = false
_, err := fmt.Scanln(&userInput)
if err != nil {
if !utils.CheckErrorWithMsg(err, "Failed to wait for node!\n") {
utils.FatalPrintf("Unexpected Error!\n")
return err
}
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
2 changes: 1 addition & 1 deletion scripts/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func main() {
}

if err != nil {
utils.FatalPrintf("Faild subcommand: %s!\n", subCmd)
utils.FatalPrintf("Failed subcommand: %s!\n", subCmd)
utils.CleanEnvironment()
os.Exit(1)
}
Expand Down
17 changes: 17 additions & 0 deletions scripts/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,20 @@ 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 {
return nodeIP, nil
}

WarnPrintf("Failed to find IP address in 10.0.0.0/8 subnet! Falling back to one of the host IP addresses\n")
nodeIP, err = ExecShellCmd(`hostname -I | awk '{print $1}'`)

if err != nil {
ErrorPrintf("Failed to find host IP address!\n")
return "", err
}

return nodeIP, nil
}

0 comments on commit bb82821

Please sign in to comment.