diff --git a/artifacts/deploy/karmada-scheduler.yaml b/artifacts/deploy/karmada-scheduler.yaml index e70475f9b..ea0a3dbe6 100644 --- a/artifacts/deploy/karmada-scheduler.yaml +++ b/artifacts/deploy/karmada-scheduler.yaml @@ -26,6 +26,8 @@ spec: command: - /bin/karmada-scheduler - --kubeconfig=/etc/kubeconfig + - --bind-address=0.0.0.0 + - --secure-port=10351 volumeMounts: - name: kubeconfig subPath: kubeconfig diff --git a/cmd/scheduler/app/options/options.go b/cmd/scheduler/app/options/options.go index 20e549727..066375eec 100644 --- a/cmd/scheduler/app/options/options.go +++ b/cmd/scheduler/app/options/options.go @@ -9,6 +9,11 @@ import ( componentbaseconfig "k8s.io/component-base/config" ) +const ( + defaultBindAddress = "0.0.0.0" + defaultPort = 10351 +) + var ( defaultElectionLeaseDuration = metav1.Duration{Duration: 15 * time.Second} defaultElectionRenewDeadline = metav1.Duration{Duration: 10 * time.Second} @@ -20,6 +25,10 @@ type Options struct { LeaderElection componentbaseconfig.LeaderElectionConfiguration KubeConfig string Master string + // BindAddress is the IP address on which to listen for the --secure-port port. + BindAddress string + // SecurePort is the port that the server serves at. + SecurePort int } // NewOptions builds an default scheduler options. @@ -45,4 +54,6 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&o.LeaderElection.ResourceNamespace, "lock-namespace", "", "Define the namespace of the lock object.") fs.StringVar(&o.KubeConfig, "kubeconfig", o.KubeConfig, "Path to a KubeConfig. Only required if out-of-cluster.") fs.StringVar(&o.Master, "master", o.Master, "The address of the Kubernetes API server. Overrides any value in KubeConfig. Only required if out-of-cluster.") + fs.StringVar(&o.BindAddress, "bind-address", defaultBindAddress, "The IP address on which to listen for the --secure-port port.") + fs.IntVar(&o.SecurePort, "secure-port", defaultPort, "The secure port on which to serve HTTPS.") } diff --git a/cmd/scheduler/app/scheduler.go b/cmd/scheduler/app/scheduler.go index 654d6ca4e..c781e1fbf 100644 --- a/cmd/scheduler/app/scheduler.go +++ b/cmd/scheduler/app/scheduler.go @@ -4,6 +4,7 @@ import ( "context" "flag" "fmt" + "net/http" "os" "github.com/google/uuid" @@ -42,6 +43,8 @@ func NewSchedulerCommand(stopChan <-chan struct{}) *cobra.Command { } func run(opts *options.Options, stopChan <-chan struct{}) error { + go serveHealthz(fmt.Sprintf("%s:%d", opts.BindAddress, opts.SecurePort)) + resetConfig, err := clientcmd.BuildConfigFromFlags(opts.Master, opts.KubeConfig) if err != nil { return fmt.Errorf("error building kubeconfig: %s", err.Error()) @@ -101,3 +104,12 @@ func run(opts *options.Options, stopChan <-chan struct{}) error { return nil } + +func serveHealthz(address string) { + http.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte("ok")) + }) + + klog.Fatal(http.ListenAndServe(address, nil)) +}