github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/sealer/cmd/run.go (about) 1 // Copyright © 2021 Alibaba Group Holding Ltd. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cmd 16 17 import ( 18 "os" 19 20 "github.com/spf13/cobra" 21 22 "github.com/alibaba/sealer/apply" 23 "github.com/alibaba/sealer/logger" 24 "github.com/alibaba/sealer/utils" 25 26 "github.com/alibaba/sealer/common" 27 "github.com/alibaba/sealer/pkg/cert" 28 ) 29 30 var runArgs *common.RunArgs 31 32 var runCmd = &cobra.Command{ 33 Use: "run", 34 Short: "run a cluster with images and arguments", 35 Long: `sealer run registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:v1.19.8 --masters [arg] --nodes [arg]`, 36 Example: ` 37 create cluster to your bare metal server, appoint the iplist: 38 sealer run kubernetes:v1.19.8 --masters 192.168.0.2,192.168.0.3,192.168.0.4 \ 39 --nodes 192.168.0.5,192.168.0.6,192.168.0.7 --passwd xxx 40 41 specify server SSH port : 42 All servers use the same SSH port (default port: 22): 43 sealer run kubernetes:v1.19.8 --masters 192.168.0.2,192.168.0.3,192.168.0.4 \ 44 --nodes 192.168.0.5,192.168.0.6,192.168.0.7 --port 24 --passwd xxx 45 46 Different SSH port numbers exist: 47 sealer run kubernetes:v1.19.8 --masters 192.168.0.2,192.168.0.3:23,192.168.0.4:24 \ 48 --nodes 192.168.0.5:25,192.168.0.6:25,192.168.0.7:27 --passwd xxx 49 50 create a cluster with custom environment variables: 51 sealer run -e DashBoardPort=8443 mydashboard:latest --masters 192.168.0.2,192.168.0.3,192.168.0.4 \ 52 --nodes 192.168.0.5,192.168.0.6,192.168.0.7 --passwd xxx 53 `, 54 Args: cobra.ExactArgs(1), 55 RunE: func(cmd *cobra.Command, args []string) error { 56 applier, err := apply.NewApplierFromArgs(args[0], runArgs) 57 if err != nil { 58 return err 59 } 60 return applier.Apply() 61 }, 62 } 63 64 func init() { 65 runArgs = &common.RunArgs{} 66 rootCmd.AddCommand(runCmd) 67 runCmd.Flags().StringVarP(&runArgs.Provider, "provider", "", "", "set infra provider, example `ALI_CLOUD`, the local server need ignore this") 68 runCmd.Flags().StringVarP(&runArgs.Masters, "masters", "m", "", "set Count or IPList to masters") 69 runCmd.Flags().StringVarP(&runArgs.Nodes, "nodes", "n", "", "set Count or IPList to nodes") 70 runCmd.Flags().StringVar(&runArgs.ClusterName, "cluster-name", "my-cluster", "set cluster name") 71 runCmd.Flags().StringVarP(&runArgs.User, "user", "u", "root", "set baremetal server username") 72 runCmd.Flags().StringVarP(&runArgs.Password, "passwd", "p", "", "set cloud provider or baremetal server password") 73 runCmd.Flags().Uint16Var(&runArgs.Port, "port", 22, "set the sshd service port number for the server (default port: 22)") 74 runCmd.Flags().StringVar(&runArgs.Pk, "pk", cert.GetUserHomeDir()+"/.ssh/id_rsa", "set baremetal server private key") 75 runCmd.Flags().StringVar(&runArgs.PkPassword, "pk-passwd", "", "set baremetal server private key password") 76 runCmd.Flags().StringSliceVar(&runArgs.CMDArgs, "cmd-args", []string{}, "set args for image cmd instruction") 77 runCmd.Flags().StringSliceVarP(&runArgs.CustomEnv, "env", "e", []string{}, "set custom environment variables") 78 err := runCmd.RegisterFlagCompletionFunc("provider", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 79 return utils.ContainList([]string{common.BAREMETAL, common.AliCloud, common.CONTAINER}, toComplete), cobra.ShellCompDirectiveNoFileComp 80 }) 81 if err != nil { 82 logger.Error("provide completion for provider flag, err: %v", err) 83 os.Exit(1) 84 } 85 }