mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +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.
|
||||
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")
|
||||
enableLogsSupport = flag.Bool("enable_logs_support", true, "Enables server endpoint for log collection")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -191,6 +192,9 @@ func main() {
|
||||
apiserver.NewAPIGroup(m.API_v1beta1()).InstallREST(mux, *apiPrefix+"/v1beta1")
|
||||
apiserver.NewAPIGroup(m.API_v1beta2()).InstallREST(mux, *apiPrefix+"/v1beta2")
|
||||
apiserver.InstallSupport(mux)
|
||||
if *enableLogsSupport {
|
||||
apiserver.InstallLogsSupport(mux)
|
||||
}
|
||||
ui.InstallSupport(mux)
|
||||
|
||||
handler := http.Handler(mux)
|
||||
|
@ -160,7 +160,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
||||
myKubelet := kubelet.NewIntegrationTestKubelet(machineList[0], testRootDir, &fakeDocker1)
|
||||
go util.Forever(func() { myKubelet.Run(cfg1.Updates()) }, 0)
|
||||
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)
|
||||
|
||||
// Kubelet (machine)
|
||||
@ -171,7 +171,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
||||
otherKubelet := kubelet.NewIntegrationTestKubelet(machineList[1], testRootDir, &fakeDocker2)
|
||||
go util.Forever(func() { otherKubelet.Run(cfg2.Updates()) }, 0)
|
||||
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)
|
||||
|
||||
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]")
|
||||
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")
|
||||
enableDebuggingHandlers = flag.Bool("enable_debugging_handlers", true, "Enables server endpoints for log collection and local running of containers and commands")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -217,7 +218,7 @@ func main() {
|
||||
// start the kubelet server
|
||||
if *enableServer {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -121,12 +121,16 @@ func (g *APIGroup) InstallREST(mux mux, paths ...string) {
|
||||
// InstallSupport registers the APIServer support functions into a mux.
|
||||
func InstallSupport(mux 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.HandleFunc("/version", handleVersion)
|
||||
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.
|
||||
func handleVersion(w http.ResponseWriter, req *http.Request) {
|
||||
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.
|
||||
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)
|
||||
handler := NewServer(host, updates)
|
||||
handler := NewServer(host, updates, enableDebuggingHandlers)
|
||||
s := &http.Server{
|
||||
Addr: net.JoinHostPort(address.String(), strconv.FormatUint(uint64(port), 10)),
|
||||
Handler: &handler,
|
||||
@ -73,26 +73,35 @@ type HostInterface interface {
|
||||
}
|
||||
|
||||
// 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{
|
||||
host: host,
|
||||
updates: updates,
|
||||
mux: http.NewServeMux(),
|
||||
}
|
||||
server.InstallDefaultHandlers()
|
||||
if enableDebuggingHandlers {
|
||||
server.InstallDebuggingHandlers()
|
||||
}
|
||||
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() {
|
||||
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("/stats/", s.handleStats)
|
||||
s.mux.HandleFunc("/logs/", s.handleLogs)
|
||||
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("/logs/", s.handleLogs)
|
||||
s.mux.HandleFunc("/containerLogs/", s.handleContainerLogs)
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ func newServerTest() *serverTestFramework {
|
||||
}
|
||||
fw.updateReader = startReading(fw.updateChan)
|
||||
fw.fakeKubelet = &fakeKubelet{}
|
||||
server := NewServer(fw.fakeKubelet, fw.updateChan)
|
||||
server := NewServer(fw.fakeKubelet, fw.updateChan, true)
|
||||
fw.serverUnderTest = &server
|
||||
fw.testHTTPServer = httptest.NewServer(fw.serverUnderTest)
|
||||
return fw
|
||||
|
Loading…
Reference in New Issue
Block a user