mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
Kube-proxy learns to read a kubeconfig
--master flag is still supported for distros that need it. But now, --kubeconfig flag can be used instead, or in addition, to specify the auth info, and/or the location of the master. A subsequent PR will change salt to generate a kubeconfig, and to make kube-proxy use it, for salt-based clouds.
This commit is contained in:
parent
508318afc9
commit
6b93e5ba9d
@ -22,11 +22,13 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
@ -40,11 +42,12 @@ import (
|
|||||||
// ProxyServer contains configures and runs a Kubernetes proxy server
|
// ProxyServer contains configures and runs a Kubernetes proxy server
|
||||||
type ProxyServer struct {
|
type ProxyServer struct {
|
||||||
BindAddress util.IP
|
BindAddress util.IP
|
||||||
ClientConfig client.Config
|
|
||||||
HealthzPort int
|
HealthzPort int
|
||||||
HealthzBindAddress util.IP
|
HealthzBindAddress util.IP
|
||||||
OOMScoreAdj int
|
OOMScoreAdj int
|
||||||
ResourceContainer string
|
ResourceContainer string
|
||||||
|
Host string
|
||||||
|
Kubeconfig string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProxyServer creates a new ProxyServer object with default parameters
|
// NewProxyServer creates a new ProxyServer object with default parameters
|
||||||
@ -61,11 +64,12 @@ func NewProxyServer() *ProxyServer {
|
|||||||
// AddFlags adds flags for a specific ProxyServer to the specified FlagSet
|
// AddFlags adds flags for a specific ProxyServer to the specified FlagSet
|
||||||
func (s *ProxyServer) AddFlags(fs *pflag.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.Var(&s.BindAddress, "bind_address", "The IP address for the proxy server to serve on (set to 0.0.0.0 for all interfaces)")
|
||||||
client.BindClientConfigFlags(fs, &s.ClientConfig)
|
fs.StringVar(&s.Host, "master", s.Host, "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.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.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]")
|
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]")
|
||||||
fs.StringVar(&s.ResourceContainer, "resource_container", s.ResourceContainer, "Absolute name of the resource-only container to create and run the Kube-proxy in (Default: /kube-proxy).")
|
fs.StringVar(&s.ResourceContainer, "resource_container", s.ResourceContainer, "Absolute name of the resource-only container to create and run the Kube-proxy in (Default: /kube-proxy).")
|
||||||
|
fs.StringVar(&s.Kubeconfig, "kubeconfig", s.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs the specified ProxyServer. This should never exit.
|
// Run runs the specified ProxyServer. This should never exit.
|
||||||
@ -105,9 +109,25 @@ func (s *ProxyServer) Run(_ []string) error {
|
|||||||
// are registered yet.
|
// are registered yet.
|
||||||
|
|
||||||
// define api config source
|
// define api config source
|
||||||
if s.ClientConfig.Host != "" {
|
if s.Host != "" || s.Kubeconfig != "" {
|
||||||
glog.Infof("Using API calls to get config %v", s.ClientConfig.Host)
|
var kubeconfig *client.Config
|
||||||
client, err := client.New(&s.ClientConfig)
|
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 {
|
if err != nil {
|
||||||
glog.Fatalf("Invalid API configuration: %v", err)
|
glog.Fatalf("Invalid API configuration: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user