mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-17 07:03:31 +00:00
Add support for binaries to run as Windows services
This patch adds support for kubernetes to integrate with Windows SCM. As a first step both `kubelet` and `kube-proxy` can be registered as a service. To create the service: PS > sc.exe create <component_name> binPath= "<path_to_binary> --service <other_args>" CMD > sc create <component_name> binPath= "<path_to_binary> --service <other_args>" Please note that if the arguments contain spaces, it must be escaped. Example: PS > sc.exe create kubelet binPath= "C:\kubelet.exe --service --hostname-override 'minion' <other_args>" CMD > sc create kubelet binPath= "C:\kubelet.exe --service --hostname-override 'minion' <other_args>" Example to start the service: PS > Start-Service kubelet; Start-Service kube-proxy CMD > net start kubelet && net start kube-proxy Example to stop the service: PS > Stop-Service kubelet (-Force); Stop-Service kube-proxy (-Force) CMD > net stop kubelet && net stop kube-proxy Example to query the service: PS > Get-Service kubelet; Get-Service kube-proxy; CMD > sc.exe queryex kubelet && sc qc kubelet && sc.exe queryex kube-proxy && sc.exe qc kube-proxy Signed-off-by: Alin Balutoiu <abalutoiu@cloudbasesolutions.com> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org> Co-authored-by: Alin Gabriel Serdean <aserdean@ovn.org>
This commit is contained in:
@@ -13,36 +13,47 @@ go_library(
|
||||
"server.go",
|
||||
] + select({
|
||||
"@io_bazel_rules_go//go/platform:android": [
|
||||
"init_others.go",
|
||||
"server_others.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:darwin": [
|
||||
"init_others.go",
|
||||
"server_others.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:dragonfly": [
|
||||
"init_others.go",
|
||||
"server_others.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:freebsd": [
|
||||
"init_others.go",
|
||||
"server_others.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"init_others.go",
|
||||
"server_others.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:nacl": [
|
||||
"init_others.go",
|
||||
"server_others.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:netbsd": [
|
||||
"init_others.go",
|
||||
"server_others.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:openbsd": [
|
||||
"init_others.go",
|
||||
"server_others.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:plan9": [
|
||||
"init_others.go",
|
||||
"server_others.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:solaris": [
|
||||
"init_others.go",
|
||||
"server_others.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:windows": [
|
||||
"init_windows.go",
|
||||
"server_windows.go",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
@@ -177,6 +188,7 @@ go_library(
|
||||
"//pkg/proxy/winkernel:go_default_library",
|
||||
"//pkg/proxy/winuserspace:go_default_library",
|
||||
"//pkg/util/netsh:go_default_library",
|
||||
"//pkg/windows/service:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
|
||||
],
|
||||
|
30
cmd/kube-proxy/app/init_others.go
Normal file
30
cmd/kube-proxy/app/init_others.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// +build !windows
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
func initForOS(service bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Options) addOSFlags(fs *pflag.FlagSet) {
|
||||
}
|
40
cmd/kube-proxy/app/init_windows.go
Normal file
40
cmd/kube-proxy/app/init_windows.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// +build windows
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/windows/service"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
const (
|
||||
serviceName = "kube-proxy"
|
||||
)
|
||||
|
||||
func initForOS(windowsService bool) error {
|
||||
if windowsService {
|
||||
return service.InitService(serviceName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Options) addOSFlags(fs *pflag.FlagSet) {
|
||||
fs.BoolVar(&o.WindowsService, "windows-service", o.WindowsService, "Enable Windows Service Control Manager API integration")
|
||||
}
|
@@ -100,6 +100,9 @@ type Options struct {
|
||||
CleanupAndExit bool
|
||||
// CleanupIPVS, when true, makes the proxy server clean up ipvs rules before running.
|
||||
CleanupIPVS bool
|
||||
// WindowsService should be set to true if kube-proxy is running as a service on Windows.
|
||||
// Its corresponding flag only gets registered in Windows builds
|
||||
WindowsService bool
|
||||
// config is the proxy server's configuration object.
|
||||
config *kubeproxyconfig.KubeProxyConfiguration
|
||||
|
||||
@@ -119,6 +122,7 @@ type Options struct {
|
||||
|
||||
// AddFlags adds flags to fs and binds them to options.
|
||||
func (o *Options) AddFlags(fs *pflag.FlagSet) {
|
||||
o.addOSFlags(fs)
|
||||
fs.StringVar(&o.ConfigFile, "config", o.ConfigFile, "The path to the configuration file.")
|
||||
fs.StringVar(&o.WriteConfigTo, "write-config-to", o.WriteConfigTo, "If set, write the default configuration values to this file and exit.")
|
||||
fs.BoolVar(&o.CleanupAndExit, "cleanup-iptables", o.CleanupAndExit, "If true cleanup iptables and ipvs rules and exit.")
|
||||
@@ -344,6 +348,10 @@ with the apiserver API to configure the proxy.`,
|
||||
verflag.PrintAndExitIfRequested()
|
||||
utilflag.PrintFlags(cmd.Flags())
|
||||
|
||||
if err := initForOS(opts.WindowsService); err != nil {
|
||||
glog.Fatalf("failed OS init: %v", err)
|
||||
}
|
||||
|
||||
cmdutil.CheckErr(opts.Complete())
|
||||
cmdutil.CheckErr(opts.Validate(args))
|
||||
cmdutil.CheckErr(opts.Run())
|
||||
|
Reference in New Issue
Block a user