Skip to content

Commit 223b75f

Browse files
committed
Merge branch 'v2.0.0' of https://github.com/fanux/sealos into v2.0.0
2 parents 84b3441 + 4a72d4e commit 223b75f

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

cmd/clean.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var cleanCmd = &cobra.Command{
2525
Short: "Simplest way to clean your kubernets HA cluster",
2626
Long: `sealos clean --master 192.168.0.2 --master 192.168.0.3 --master 192.168.0.4 --node 192.168.0.5 --user root --passwd your-server-password`,
2727
Run: func(cmd *cobra.Command, args []string) {
28-
i := install.BuildInstaller(install.User, install.Passwd, masters, nodes)
28+
i := install.BuildInstaller(masters, nodes)
2929
i.CleanCluster()
3030
},
3131
}

cmd/init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var initCmd = &cobra.Command{
3030
Short: "Simplest way to init your kubernets HA cluster",
3131
Long: `sealos init --master 192.168.0.2 --master 192.168.0.3 --master 192.168.0.4 --node 192.168.0.5 --user root --passwd your-server-password`,
3232
Run: func(cmd *cobra.Command, args []string) {
33-
i := install.BuildInstaller(install.User, install.Passwd, masters, nodes)
33+
i := install.BuildInstaller(masters, nodes)
3434
i.InstallMaster0()
3535
i.JoinMasters()
3636
i.JoinNodes()
@@ -51,6 +51,7 @@ func init() {
5151
// initCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
5252
initCmd.Flags().StringVar(&install.User, "user", "root", "servers user name for ssh")
5353
initCmd.Flags().StringVar(&install.Passwd, "passwd", "passwd", "password for ssh")
54+
initCmd.Flags().StringVar(&install.VIP, "vip", "10.103.97.2", "virtual ip")
5455

5556
initCmd.Flags().StringSliceVar(&masters, "master", []string{}, "kubernetes masters")
5657
initCmd.Flags().StringSliceVar(&nodes, "node", []string{}, "kubernetes nodes")

install/sealos.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ type Installer interface {
1717

1818
//SealosInstaller is
1919
type SealosInstaller struct {
20-
User string
21-
Passwd string
22-
2320
Masters []string
2421
Nodes []string
2522

@@ -29,10 +26,8 @@ type SealosInstaller struct {
2926
}
3027

3128
//BuildInstaller is
32-
func BuildInstaller(user string, passwd string, masters []string, nodes []string) Installer {
29+
func BuildInstaller(masters []string, nodes []string) Installer {
3330
return &SealosInstaller{
34-
User: user,
35-
Passwd: passwd,
3631
Masters: masters,
3732
Nodes: nodes,
3833
}
@@ -43,7 +38,10 @@ func (s *SealosInstaller) InstallMaster0() {
4338
cmd := fmt.Sprintf("echo %s apiserver.cluster.local >> /etc/hosts", s.Masters[0])
4439
Cmd(s.Masters[0], cmd)
4540

46-
cmd = `kubeadm init --config=kubeadm-config.yaml --experimental-upload-certs`
41+
cmd = "echo \"" + string(Template(s.Masters, VIP)) + "\" > ~/kubeadm-config.yaml"
42+
Cmd(s.Masters[0], cmd)
43+
44+
cmd = `kubeadm init --config=~/kubeadm-config.yaml --experimental-upload-certs`
4745
output := Cmd(s.Masters[0], cmd)
4846
s.decodeOutput(output)
4947

@@ -79,9 +77,9 @@ func (s *SealosInstaller) JoinNodes() {
7977
wg.Add(1)
8078
go func(node string) {
8179
defer wg.Done()
82-
cmdHosts := fmt.Sprintf("echo 10.103.97.2 apiserver.cluster.local >> /etc/hosts")
80+
cmdHosts := fmt.Sprintf("echo %s apiserver.cluster.local >> /etc/hosts", VIP)
8381
Cmd(node, cmdHosts)
84-
cmd := fmt.Sprintf("kubeadm join 10.103.97.2:6443 --token %s --discovery-token-ca-cert-hash %s", s.JoinToken, s.TokenCaCertHash)
82+
cmd := fmt.Sprintf("kubeadm join %s:6443 --token %s --discovery-token-ca-cert-hash %s", VIP, s.JoinToken, s.TokenCaCertHash)
8583
cmd += masters
8684
Cmd(node, cmd)
8785
}(node)

install/utils.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package install
22

33
import (
4+
"bytes"
45
"fmt"
6+
"html/template"
57
"net"
68
"time"
79

@@ -12,6 +14,7 @@ import (
1214
var (
1315
User string
1416
Passwd string
17+
VIP string
1518
)
1619

1720
//Cmd is
@@ -76,3 +79,37 @@ func Connect(user, passwd, host string) (*ssh.Session, error) {
7679

7780
return session, nil
7881
}
82+
83+
//Template is
84+
func Template(masters []string, vip string) []byte {
85+
var templateText = string(`apiVersion: kubeadm.k8s.io/v1beta1
86+
kind: ClusterConfiguration
87+
kubernetesVersion: v1.14.0
88+
controlPlaneEndpoint: "apiserver.cluster.local:6443"
89+
apiServer:
90+
certSANs:
91+
- 127.0.0.1
92+
- apiserver.cluster.local
93+
{{range .Masters -}}
94+
- {{.}}
95+
{{end -}}
96+
- {{.VIP}}
97+
---
98+
apiVersion: kubeproxy.config.k8s.io/v1alpha1
99+
kind: KubeProxyConfiguration
100+
mode: "ipvs"
101+
ipvs:
102+
excludeCIDRs:
103+
- "{{.VIP}}/32"`)
104+
tmpl, err := template.New("text").Parse(templateText)
105+
if err != nil {
106+
fmt.Println("template parse failed:", err)
107+
panic(1)
108+
}
109+
var envMap = make(map[string]interface{})
110+
envMap["VIP"] = vip
111+
envMap["Masters"] = masters
112+
var buffer bytes.Buffer
113+
_ = tmpl.Execute(&buffer, envMap)
114+
return buffer.Bytes()
115+
}

0 commit comments

Comments
 (0)