mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-05 19:21:37 +00:00
controller, scheduler, proxy use kubeconfig
--master option still supported. --kubeconfig option added to kube-proxy, kube-scheduler, and kube-controller-manager binaries. Kube-proxy now always makes some kind of API source, since that is its only kind of config. Warn if it is using a default client, which probably won't work. Uses the clientcmd builder.
This commit is contained in:
@@ -22,13 +22,13 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
|
||||
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
@@ -46,7 +46,7 @@ type ProxyServer struct {
|
||||
HealthzBindAddress util.IP
|
||||
OOMScoreAdj int
|
||||
ResourceContainer string
|
||||
Host string
|
||||
Master string
|
||||
Kubeconfig string
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func NewProxyServer() *ProxyServer {
|
||||
// AddFlags adds flags for a specific ProxyServer to the specified FlagSet
|
||||
func (s *ProxyServer) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.Var(&s.BindAddress, "bind_address", "The IP address for the proxy server to serve on (set to 0.0.0.0 for all interfaces)")
|
||||
fs.StringVar(&s.Host, "master", s.Host, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
|
||||
fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
|
||||
fs.IntVar(&s.HealthzPort, "healthz_port", s.HealthzPort, "The port to bind the health check server. Use 0 to disable.")
|
||||
fs.Var(&s.HealthzBindAddress, "healthz_bind_address", "The IP address for the health check server to serve on, defaulting to 127.0.0.1 (set to 0.0.0.0 for all interfaces)")
|
||||
fs.IntVar(&s.OOMScoreAdj, "oom_score_adj", s.OOMScoreAdj, "The oom_score_adj value for kube-proxy process. Values must be within the range [-1000, 1000]")
|
||||
@@ -109,37 +109,32 @@ func (s *ProxyServer) Run(_ []string) error {
|
||||
// are registered yet.
|
||||
|
||||
// define api config source
|
||||
if s.Host != "" || s.Kubeconfig != "" {
|
||||
var kubeconfig *client.Config
|
||||
if s.Kubeconfig != "" {
|
||||
var err error
|
||||
loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||
&clientcmd.ClientConfigLoadingRules{ExplicitPath: s.Kubeconfig},
|
||||
&clientcmd.ConfigOverrides{})
|
||||
kubeconfig, err = loader.ClientConfig()
|
||||
if os.IsNotExist(err) {
|
||||
glog.Fatalf("Could not find kubeconfig file at %s", s.Kubeconfig)
|
||||
}
|
||||
if err != nil {
|
||||
glog.Fatalf("Error loading kubeconfig file \"%s\": %v", s.Kubeconfig, err)
|
||||
}
|
||||
}
|
||||
if s.Host != "" {
|
||||
kubeconfig.Host = s.Host
|
||||
}
|
||||
client, err := client.New(kubeconfig)
|
||||
if err != nil {
|
||||
glog.Fatalf("Invalid API configuration: %v", err)
|
||||
}
|
||||
config.NewSourceAPI(
|
||||
client.Services(api.NamespaceAll),
|
||||
client.Endpoints(api.NamespaceAll),
|
||||
30*time.Second,
|
||||
serviceConfig.Channel("api"),
|
||||
endpointsConfig.Channel("api"),
|
||||
)
|
||||
if s.Kubeconfig == "" && s.Master == "" {
|
||||
glog.Warningf("Neither --kubeconfig nor --master was specified. Using default API client. This might not work.")
|
||||
}
|
||||
|
||||
// This creates a client, first loading any specified kubeconfig
|
||||
// file, and then overriding the Master flag, if non-empty.
|
||||
kubeconfig, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||
&clientcmd.ClientConfigLoadingRules{ExplicitPath: s.Kubeconfig},
|
||||
&clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: s.Master}}).ClientConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := client.New(kubeconfig)
|
||||
if err != nil {
|
||||
glog.Fatalf("Invalid API configuration: %v", err)
|
||||
}
|
||||
|
||||
config.NewSourceAPI(
|
||||
client.Services(api.NamespaceAll),
|
||||
client.Endpoints(api.NamespaceAll),
|
||||
30*time.Second,
|
||||
serviceConfig.Channel("api"),
|
||||
endpointsConfig.Channel("api"),
|
||||
)
|
||||
|
||||
if s.HealthzPort > 0 {
|
||||
go util.Forever(func() {
|
||||
err := http.ListenAndServe(s.HealthzBindAddress.String()+":"+strconv.Itoa(s.HealthzPort), nil)
|
||||
|
Reference in New Issue
Block a user