diff --git a/cmd/ipvs.go b/cmd/ipvs.go index dfdd85420..f5368f732 100644 --- a/cmd/ipvs.go +++ b/cmd/ipvs.go @@ -26,15 +26,23 @@ var ipvsCmd = &cobra.Command{ Use: "ipvs", Short: "sealos create or care local ipvs lb", Run: func(cmd *cobra.Command, args []string) { + if clean { + // do clean things + + return + } install.Ipvs.VsAndRsCare() }, } +var clean bool + func init() { rootCmd.AddCommand(ipvsCmd) // Here you will define your flags and configuration settings. ipvsCmd.Flags().BoolVar(&install.Ipvs.RunOnce, "run-once", false, "is run once mode") + ipvsCmd.Flags().BoolVarP(&clean, "clean","c", false, " clean Vip ipvs rule before join node, if Vip has no ipvs rule do nothing.") ipvsCmd.Flags().StringVar(&install.Ipvs.VirtualServer, "vs", "", "virturl server like 10.54.0.2:6443") ipvsCmd.Flags().StringSliceVar(&install.Ipvs.RealServer, "rs", []string{}, "virturl server like 192.168.0.2:6443") diff --git a/install/join.go b/install/join.go index f3cc7f26b..45ebf8fe3 100644 --- a/install/join.go +++ b/install/join.go @@ -139,6 +139,7 @@ func (s *SealosInstaller) JoinNodes() { for _, master := range s.Masters { masters += fmt.Sprintf(" --rs %s:6443", IpFormat(master)) } + ipvsCleanCmd := "sealos ipvs --clean" ipvsCmd := fmt.Sprintf("sealos ipvs --vs %s:6443 %s --health-path /healthz --health-schem https --run-once", VIP, masters) for _, node := range s.Nodes { @@ -157,6 +158,9 @@ func (s *SealosInstaller) JoinNodes() { SSHConfig.CmdToString(node, addRouteCmd, "") } + // clean Vip ipvs rule before join node, if Vip has no ipvs rule do nothing. + _ = SSHConfig.CmdAsync(node, ipvsCleanCmd) + _ = SSHConfig.CmdAsync(node, ipvsCmd) // create ipvs rules before we join node cmd := s.Command(Version, JoinNode) //create lvscare static pod