mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Allow disabling non-necessary kubelet and apiserver endpoints
This commit is contained in:
parent
1a1b0699bc
commit
c0bf974871
@ -66,6 +66,7 @@ var (
|
|||||||
// TODO: Discover these by pinging the host machines, and rip out these flags.
|
// TODO: Discover these by pinging the host machines, and rip out these flags.
|
||||||
nodeMilliCPU = flag.Int("node_milli_cpu", 1000, "The amount of MilliCPU provisioned on each node")
|
nodeMilliCPU = flag.Int("node_milli_cpu", 1000, "The amount of MilliCPU provisioned on each node")
|
||||||
nodeMemory = flag.Int("node_memory", 3*1024*1024*1024, "The amount of memory (in bytes) provisioned on each node")
|
nodeMemory = flag.Int("node_memory", 3*1024*1024*1024, "The amount of memory (in bytes) provisioned on each node")
|
||||||
|
enableLogsSupport = flag.Bool("enable_logs_support", true, "Enables server endpoint for log collection")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -191,6 +192,9 @@ func main() {
|
|||||||
apiserver.NewAPIGroup(m.API_v1beta1()).InstallREST(mux, *apiPrefix+"/v1beta1")
|
apiserver.NewAPIGroup(m.API_v1beta1()).InstallREST(mux, *apiPrefix+"/v1beta1")
|
||||||
apiserver.NewAPIGroup(m.API_v1beta2()).InstallREST(mux, *apiPrefix+"/v1beta2")
|
apiserver.NewAPIGroup(m.API_v1beta2()).InstallREST(mux, *apiPrefix+"/v1beta2")
|
||||||
apiserver.InstallSupport(mux)
|
apiserver.InstallSupport(mux)
|
||||||
|
if *enableLogsSupport {
|
||||||
|
apiserver.InstallLogsSupport(mux)
|
||||||
|
}
|
||||||
ui.InstallSupport(mux)
|
ui.InstallSupport(mux)
|
||||||
|
|
||||||
handler := http.Handler(mux)
|
handler := http.Handler(mux)
|
||||||
|
@ -160,7 +160,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
|||||||
myKubelet := kubelet.NewIntegrationTestKubelet(machineList[0], testRootDir, &fakeDocker1)
|
myKubelet := kubelet.NewIntegrationTestKubelet(machineList[0], testRootDir, &fakeDocker1)
|
||||||
go util.Forever(func() { myKubelet.Run(cfg1.Updates()) }, 0)
|
go util.Forever(func() { myKubelet.Run(cfg1.Updates()) }, 0)
|
||||||
go util.Forever(func() {
|
go util.Forever(func() {
|
||||||
kubelet.ListenAndServeKubeletServer(myKubelet, cfg1.Channel("http"), net.ParseIP("127.0.0.1"), 10250)
|
kubelet.ListenAndServeKubeletServer(myKubelet, cfg1.Channel("http"), net.ParseIP("127.0.0.1"), 10250, true)
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
// Kubelet (machine)
|
// Kubelet (machine)
|
||||||
@ -171,7 +171,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
|||||||
otherKubelet := kubelet.NewIntegrationTestKubelet(machineList[1], testRootDir, &fakeDocker2)
|
otherKubelet := kubelet.NewIntegrationTestKubelet(machineList[1], testRootDir, &fakeDocker2)
|
||||||
go util.Forever(func() { otherKubelet.Run(cfg2.Updates()) }, 0)
|
go util.Forever(func() { otherKubelet.Run(cfg2.Updates()) }, 0)
|
||||||
go util.Forever(func() {
|
go util.Forever(func() {
|
||||||
kubelet.ListenAndServeKubeletServer(otherKubelet, cfg2.Channel("http"), net.ParseIP("127.0.0.1"), 10251)
|
kubelet.ListenAndServeKubeletServer(otherKubelet, cfg2.Channel("http"), net.ParseIP("127.0.0.1"), 10251, true)
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
return apiServer.URL
|
return apiServer.URL
|
||||||
|
@ -66,6 +66,7 @@ var (
|
|||||||
registryPullQPS = flag.Float64("registry_qps", 0.0, "If > 0, limit registry pull QPS to this value. If 0, unlimited. [default=0.0]")
|
registryPullQPS = flag.Float64("registry_qps", 0.0, "If > 0, limit registry pull QPS to this value. If 0, unlimited. [default=0.0]")
|
||||||
registryBurst = flag.Int("registry_burst", 10, "Maximum size of a bursty pulls, temporarily allows pulls to burst to this number, while still not exceeding registry_qps. Only used if --registry_qps > 0")
|
registryBurst = flag.Int("registry_burst", 10, "Maximum size of a bursty pulls, temporarily allows pulls to burst to this number, while still not exceeding registry_qps. Only used if --registry_qps > 0")
|
||||||
runonce = flag.Bool("runonce", false, "If true, exit after spawning pods from local manifests or remote urls. Exclusive with --etcd_servers and --enable-server")
|
runonce = flag.Bool("runonce", false, "If true, exit after spawning pods from local manifests or remote urls. Exclusive with --etcd_servers and --enable-server")
|
||||||
|
enableDebuggingHandlers = flag.Bool("enable_debugging_handlers", true, "Enables server endpoints for log collection and local running of containers and commands")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -217,7 +218,7 @@ func main() {
|
|||||||
// start the kubelet server
|
// start the kubelet server
|
||||||
if *enableServer {
|
if *enableServer {
|
||||||
go util.Forever(func() {
|
go util.Forever(func() {
|
||||||
kubelet.ListenAndServeKubeletServer(k, cfg.Channel("http"), net.IP(address), *port)
|
kubelet.ListenAndServeKubeletServer(k, cfg.Channel("http"), net.IP(address), *port, *enableDebuggingHandlers)
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,12 +121,16 @@ func (g *APIGroup) InstallREST(mux mux, paths ...string) {
|
|||||||
// InstallSupport registers the APIServer support functions into a mux.
|
// InstallSupport registers the APIServer support functions into a mux.
|
||||||
func InstallSupport(mux mux) {
|
func InstallSupport(mux mux) {
|
||||||
healthz.InstallHandler(mux)
|
healthz.InstallHandler(mux)
|
||||||
mux.Handle("/logs/", http.StripPrefix("/logs/", http.FileServer(http.Dir("/var/log/"))))
|
|
||||||
mux.Handle("/proxy/minion/", http.StripPrefix("/proxy/minion", http.HandlerFunc(handleProxyMinion)))
|
mux.Handle("/proxy/minion/", http.StripPrefix("/proxy/minion", http.HandlerFunc(handleProxyMinion)))
|
||||||
mux.HandleFunc("/version", handleVersion)
|
mux.HandleFunc("/version", handleVersion)
|
||||||
mux.HandleFunc("/", handleIndex)
|
mux.HandleFunc("/", handleIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InstallLogsSupport registers the APIServer log support function into a mux.
|
||||||
|
func InstallLogsSupport(mux mux) {
|
||||||
|
mux.Handle("/logs/", http.StripPrefix("/logs/", http.FileServer(http.Dir("/var/log/"))))
|
||||||
|
}
|
||||||
|
|
||||||
// handleVersion writes the server's version information.
|
// handleVersion writes the server's version information.
|
||||||
func handleVersion(w http.ResponseWriter, req *http.Request) {
|
func handleVersion(w http.ResponseWriter, req *http.Request) {
|
||||||
writeRawJSON(http.StatusOK, version.Get(), w)
|
writeRawJSON(http.StatusOK, version.Get(), w)
|
||||||
|
@ -47,9 +47,9 @@ type Server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListenAndServeKubeletServer initializes a server to respond to HTTP network requests on the Kubelet.
|
// ListenAndServeKubeletServer initializes a server to respond to HTTP network requests on the Kubelet.
|
||||||
func ListenAndServeKubeletServer(host HostInterface, updates chan<- interface{}, address net.IP, port uint) {
|
func ListenAndServeKubeletServer(host HostInterface, updates chan<- interface{}, address net.IP, port uint, enableDebuggingHandlers bool) {
|
||||||
glog.V(1).Infof("Starting to listen on %s:%d", address, port)
|
glog.V(1).Infof("Starting to listen on %s:%d", address, port)
|
||||||
handler := NewServer(host, updates)
|
handler := NewServer(host, updates, enableDebuggingHandlers)
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: net.JoinHostPort(address.String(), strconv.FormatUint(uint64(port), 10)),
|
Addr: net.JoinHostPort(address.String(), strconv.FormatUint(uint64(port), 10)),
|
||||||
Handler: &handler,
|
Handler: &handler,
|
||||||
@ -73,26 +73,35 @@ type HostInterface interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewServer initializes and configures a kubelet.Server object to handle HTTP requests.
|
// NewServer initializes and configures a kubelet.Server object to handle HTTP requests.
|
||||||
func NewServer(host HostInterface, updates chan<- interface{}) Server {
|
func NewServer(host HostInterface, updates chan<- interface{}, enableDebuggingHandlers bool) Server {
|
||||||
server := Server{
|
server := Server{
|
||||||
host: host,
|
host: host,
|
||||||
updates: updates,
|
updates: updates,
|
||||||
mux: http.NewServeMux(),
|
mux: http.NewServeMux(),
|
||||||
}
|
}
|
||||||
server.InstallDefaultHandlers()
|
server.InstallDefaultHandlers()
|
||||||
|
if enableDebuggingHandlers {
|
||||||
|
server.InstallDebuggingHandlers()
|
||||||
|
}
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstallDefaultHandlers registers the set of supported HTTP request patterns with the mux.
|
// InstallDefaultHandlers registers the default set of supported HTTP request patterns with the mux.
|
||||||
func (s *Server) InstallDefaultHandlers() {
|
func (s *Server) InstallDefaultHandlers() {
|
||||||
healthz.InstallHandler(s.mux)
|
healthz.InstallHandler(s.mux)
|
||||||
s.mux.HandleFunc("/container", s.handleContainer)
|
|
||||||
s.mux.HandleFunc("/containers", s.handleContainers)
|
|
||||||
s.mux.HandleFunc("/podInfo", s.handlePodInfo)
|
s.mux.HandleFunc("/podInfo", s.handlePodInfo)
|
||||||
s.mux.HandleFunc("/stats/", s.handleStats)
|
s.mux.HandleFunc("/stats/", s.handleStats)
|
||||||
s.mux.HandleFunc("/logs/", s.handleLogs)
|
|
||||||
s.mux.HandleFunc("/spec/", s.handleSpec)
|
s.mux.HandleFunc("/spec/", s.handleSpec)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstallDeguggingHandlers registers the HTTP request patterns that serve logs or run commands/containers
|
||||||
|
func (s *Server) InstallDebuggingHandlers() {
|
||||||
|
// ToDo: /container, /run, and /containers aren't debugging options, should probably be handled separately
|
||||||
|
s.mux.HandleFunc("/container", s.handleContainer)
|
||||||
|
s.mux.HandleFunc("/containers", s.handleContainers)
|
||||||
s.mux.HandleFunc("/run/", s.handleRun)
|
s.mux.HandleFunc("/run/", s.handleRun)
|
||||||
|
|
||||||
|
s.mux.HandleFunc("/logs/", s.handleLogs)
|
||||||
s.mux.HandleFunc("/containerLogs/", s.handleContainerLogs)
|
s.mux.HandleFunc("/containerLogs/", s.handleContainerLogs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ func newServerTest() *serverTestFramework {
|
|||||||
}
|
}
|
||||||
fw.updateReader = startReading(fw.updateChan)
|
fw.updateReader = startReading(fw.updateChan)
|
||||||
fw.fakeKubelet = &fakeKubelet{}
|
fw.fakeKubelet = &fakeKubelet{}
|
||||||
server := NewServer(fw.fakeKubelet, fw.updateChan)
|
server := NewServer(fw.fakeKubelet, fw.updateChan, true)
|
||||||
fw.serverUnderTest = &server
|
fw.serverUnderTest = &server
|
||||||
fw.testHTTPServer = httptest.NewServer(fw.serverUnderTest)
|
fw.testHTTPServer = httptest.NewServer(fw.serverUnderTest)
|
||||||
return fw
|
return fw
|
||||||
|
Loading…
Reference in New Issue
Block a user