// NewAPIServerCommand provides a CLI handler for the 'apiserver' command func NewAPIServerCommand(name, fullName string, out io.Writer) *cobra.Command { apiServerOptions := apiserveroptions.NewAPIServer() cmd := &cobra.Command{ Use: name, Short: "Launch Kubernetes apiserver (kube-apiserver)", Long: apiserverLong, Run: func(c *cobra.Command, args []string) { startProfiler() util.InitLogs() defer util.FlushLogs() if err := apiserverapp.Run(apiServerOptions); err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) } }, } cmd.SetOutput(out) flags := cmd.Flags() flags.SetNormalizeFunc(util.WordSepNormalizeFunc) flags.AddGoFlagSet(flag.CommandLine) apiServerOptions.AddFlags(flags) return cmd }
func StartAPIServer(lk LocalkubeServer) func() error { config := options.NewAPIServer() config.BindAddress = lk.APIServerAddress config.SecurePort = lk.APIServerPort config.InsecureBindAddress = lk.APIServerInsecureAddress config.InsecurePort = lk.APIServerInsecurePort config.ClientCAFile = lk.GetPublicKeyCertPath() config.TLSCertFile = lk.GetPublicKeyCertPath() config.TLSPrivateKeyFile = lk.GetPrivateKeyCertPath() config.AdmissionControl = "NamespaceLifecycle,LimitRanger,ServiceAccount,ResourceQuota" // use localkube etcd config.StorageConfig = storagebackend.Config{ServerList: KubeEtcdClientURLs} // set Service IP range config.ServiceClusterIPRange = lk.ServiceClusterIPRange // defaults from apiserver command config.EnableProfiling = true config.EnableWatchCache = true config.MinRequestTimeout = 1800 config.AllowPrivileged = true return func() error { return apiserver.Run(config) } }
// Start starts the apiserver, returns when apiserver is ready. func (a *APIServer) Start() error { config := options.NewServerRunOptions() config.Etcd.StorageConfig.ServerList = []string{getEtcdClientURL()} // TODO: Current setup of etcd in e2e-node tests doesn't support etcd v3 // protocol. We should migrate it to use the same infrastructure as all // other tests (pkg/storage/etcd/testing). config.Etcd.StorageConfig.Type = "etcd2" _, ipnet, err := net.ParseCIDR(clusterIPRange) if err != nil { return err } config.ServiceClusterIPRange = *ipnet config.AllowPrivileged = true errCh := make(chan error) go func() { defer close(errCh) err := apiserver.Run(config) if err != nil { errCh <- fmt.Errorf("run apiserver error: %v", err) } }() err = readinessCheck("apiserver", []string{apiserverHealthCheckURL}, errCh) if err != nil { return err } return nil }
// NewKubeAPIServer creates a new hyperkube Server object that includes the // description and flags. func NewKubeAPIServer() *Server { s := options.NewAPIServer() hks := Server{ SimpleUsage: hyperkube.CommandApiserver, Long: "The main API entrypoint and interface to the storage system. The API server is also the focal point for all authorization decisions.", Run: func(_ *Server, _ []string) error { return app.Run(s) }, } s.AddFlags(hks.Flags()) return &hks }
func (b *bootkube) Run() error { errch := make(chan error) go func() { errch <- apiapp.Run(b.apiServer) }() go func() { errch <- cmapp.Run(b.controller) }() go func() { errch <- schedapp.Run(b.scheduler) }() go func() { if err := CreateAssets(filepath.Join(b.assetDir, asset.AssetPathManifests), assetTimeout); err != nil { errch <- err } }() go func() { errch <- WaitUntilPodsRunning(requiredPods, assetTimeout) }() // If any of the bootkube services exit, it means it is unrecoverable and we should exit. return <-errch }
func main() { rand.Seed(time.Now().UTC().UnixNano()) s := options.NewAPIServer() s.AddFlags(pflag.CommandLine) flag.InitFlags() logs.InitLogs() defer logs.FlushLogs() verflag.PrintAndExitIfRequested() if err := app.Run(s); err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) } }
// Start starts the apiserver, returns when apiserver is ready. func (a *APIServer) Start() error { config := options.NewAPIServer() config.StorageConfig.ServerList = []string{getEtcdClientURL()} _, ipnet, err := net.ParseCIDR(clusterIPRange) if err != nil { return err } config.ServiceClusterIPRange = *ipnet config.AllowPrivileged = true errCh := make(chan error) go func() { defer close(errCh) err := apiserver.Run(config) if err != nil { errCh <- fmt.Errorf("run apiserver error: %v", err) } }() err = readinessCheck([]string{apiserverHealthCheckURL}, errCh) if err != nil { return err } return nil }