Skip to content

Commit 9140895

Browse files
committed
feat(k3s): update k3s
update k3s Signed-off-by: ysicing <i@ysicing.me>
1 parent 6bf750f commit 9140895

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- v3.3.0
44
- [x] 支持kube resources
5-
- [ ] 支持重建svc
5+
- [x] 优化k3s安装,支持配置podcidr,svccidr
66

77
- v3.2.0
88
- [x] 支持批量执行shell

cmd/kube/k3s.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ func K3sCmd(f factory.Factory) *cobra.Command {
2828
Use: "init",
2929
Short: "init k3s control-plane(master) node",
3030
Long: `example: ergo k3s init --docker`,
31-
Version: "2.6.0",
31+
Version: "3.3.0",
3232
RunE: func(cmd *cobra.Command, args []string) error {
3333
return opt.Init()
3434
},
3535
}
3636
k3s.AddCommand(init)
3737
init.PersistentFlags().StringVar(&opt.KsSan, "san", "ysicing.local", "Add additional hostname or IP as a Subject Alternative Name in the TLS cert")
3838
init.PersistentFlags().BoolVar(&opt.CniNo, "nocni", true, "If true, Use cni none")
39+
init.PersistentFlags().StringVar(&opt.PodCIDR, "pod-cidr", "10.42.0.0/16", "IPv4/IPv6 network CIDRs to use for pod IPs")
40+
init.PersistentFlags().StringVar(&opt.SvcCIDR, "svc-cidr", "10.43.0.0/16", "IPv4/IPv6 network CIDRs to use for service IPs")
41+
init.PersistentFlags().StringVar(&opt.DnSSvcIP, "dns-svcip", "10.43.0.10", " IPv4 Cluster IP for coredns service. Should be in your service-cidr range")
42+
3943
join := &cobra.Command{
4044
Use: "join",
4145
Short: "join k3s cluster",
@@ -65,15 +69,5 @@ func K3sCmd(f factory.Factory) *cobra.Command {
6569
},
6670
}
6771
k3s.AddCommand(getbin)
68-
rebuildService := &cobra.Command{
69-
Use: "rebuild-svc",
70-
Short: "rebuild k3s service",
71-
Version: "3.3.0",
72-
RunE: func(cmd *cobra.Command, args []string) error {
73-
_, err := opt.PreCheckK3sBin()
74-
return err
75-
},
76-
}
77-
k3s.AddCommand(rebuildService)
7872
return k3s
7973
}

pkg/k3s/k3s.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ type Option struct {
2525
CniNo bool `json:"cniNo"`
2626
KsSan string `json:"ksSan"`
2727
EIP string `json:"eip"`
28+
PodCIDR string `json:"podCIDR"`
29+
SvcCIDR string `json:"svcCIDR"`
30+
DnSSvcIP string `json:"dnsSvcIP"`
31+
2832
// Join
2933
KsAddr string `json:"ksAddr"`
3034
KsToken string `json:"ksToken"`
@@ -66,6 +70,7 @@ func (o *Option) Init() error {
6670
}
6771
k3sargs := []string{
6872
"server",
73+
"--tls-san=kapi.k3s.local",
6974
"--disable=servicelb,traefik",
7075
"--disable-helm-controller",
7176
"--kube-proxy-arg=proxy-mode=ipvs",
@@ -153,7 +158,7 @@ func (o *Option) Init() error {
153158
kubectlbin = common.KubectlBinPath
154159
}
155160
if o.CniNo {
156-
o.Klog.Warnf("Cilium is recommended: cilium install --ipv4-native-routing-cidr 10.42.0.0/16 --config cluster-pool-ipv4-cidr=10.42.0.0/16")
161+
o.Klog.Warnf("Cilium is recommended: cilium install --ipv4-native-routing-cidr %s --config cluster-pool-ipv4-cidr=%s", o.PodCIDR, o.PodCIDR)
157162
}
158163
getnodesoutput, err := exec.Command(kubectlbin, "get", "nodes").CombinedOutput()
159164
if err != nil {
@@ -248,6 +253,9 @@ func (o *Option) configArgs() []string {
248253
if len(o.KsSan) != 0 {
249254
args = append(args, fmt.Sprintf("--tls-san=%v", o.KsSan))
250255
}
256+
args = append(args, fmt.Sprintf("--cluster-cidr=%v", o.PodCIDR))
257+
args = append(args, fmt.Sprintf("--service-cidr=%v", o.SvcCIDR))
258+
args = append(args, fmt.Sprintf("--cluster-dns=%v", o.DnSSvcIP))
251259
}
252260

253261
if len(o.EIP) != 0 {

0 commit comments

Comments
 (0)