mirror of https://github.com/k3s-io/k3s
Merge pull request #78504 from dashpole/deprecate_cadvisor_json
Add kubelet flag to disable cadvisor json apis, and mark it deprecratedk3s-v1.15.3
commit
6b6bdc760a
|
@ -194,6 +194,8 @@ type KubeletFlags struct {
|
||||||
// This flag, if set, instructs the kubelet to keep volumes from terminated pods mounted to the node.
|
// This flag, if set, instructs the kubelet to keep volumes from terminated pods mounted to the node.
|
||||||
// This can be useful for debugging volume related issues.
|
// This can be useful for debugging volume related issues.
|
||||||
KeepTerminatedPodVolumes bool
|
KeepTerminatedPodVolumes bool
|
||||||
|
// EnableCAdvisorJSONEndpoints enables some cAdvisor endpoints that will be removed in future versions
|
||||||
|
EnableCAdvisorJSONEndpoints bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKubeletFlags will create a new KubeletFlags with default values
|
// NewKubeletFlags will create a new KubeletFlags with default values
|
||||||
|
@ -223,7 +225,8 @@ func NewKubeletFlags() *KubeletFlags {
|
||||||
RegisterNode: true,
|
RegisterNode: true,
|
||||||
SeccompProfileRoot: filepath.Join(defaultRootDir, "seccomp"),
|
SeccompProfileRoot: filepath.Join(defaultRootDir, "seccomp"),
|
||||||
// prior to the introduction of this flag, there was a hardcoded cap of 50 images
|
// prior to the introduction of this flag, there was a hardcoded cap of 50 images
|
||||||
NodeStatusMaxImages: 50,
|
NodeStatusMaxImages: 50,
|
||||||
|
EnableCAdvisorJSONEndpoints: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,6 +427,8 @@ func (f *KubeletFlags) AddFlags(mainfs *pflag.FlagSet) {
|
||||||
fs.MarkDeprecated("non-masquerade-cidr", "will be removed in a future version")
|
fs.MarkDeprecated("non-masquerade-cidr", "will be removed in a future version")
|
||||||
fs.BoolVar(&f.KeepTerminatedPodVolumes, "keep-terminated-pod-volumes", f.KeepTerminatedPodVolumes, "Keep terminated pod volumes mounted to the node after the pod terminates. Can be useful for debugging volume related issues.")
|
fs.BoolVar(&f.KeepTerminatedPodVolumes, "keep-terminated-pod-volumes", f.KeepTerminatedPodVolumes, "Keep terminated pod volumes mounted to the node after the pod terminates. Can be useful for debugging volume related issues.")
|
||||||
fs.MarkDeprecated("keep-terminated-pod-volumes", "will be removed in a future version")
|
fs.MarkDeprecated("keep-terminated-pod-volumes", "will be removed in a future version")
|
||||||
|
fs.BoolVar(&f.EnableCAdvisorJSONEndpoints, "enable-cadvisor-json-endpoints", f.EnableCAdvisorJSONEndpoints, "Enable cAdvisor json /spec and /stats/* endpoints.")
|
||||||
|
fs.MarkDeprecated("enable-cadvisor-json-apis", "will be removed in a future version")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1079,13 +1079,13 @@ func RunKubelet(kubeServer *options.KubeletServer, kubeDeps *kubelet.Dependencie
|
||||||
}
|
}
|
||||||
klog.Info("Started kubelet as runonce")
|
klog.Info("Started kubelet as runonce")
|
||||||
} else {
|
} else {
|
||||||
startKubelet(k, podCfg, &kubeServer.KubeletConfiguration, kubeDeps, kubeServer.EnableServer)
|
startKubelet(k, podCfg, &kubeServer.KubeletConfiguration, kubeDeps, kubeServer.EnableCAdvisorJSONEndpoints, kubeServer.EnableServer)
|
||||||
klog.Info("Started kubelet")
|
klog.Info("Started kubelet")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func startKubelet(k kubelet.Bootstrap, podCfg *config.PodConfig, kubeCfg *kubeletconfiginternal.KubeletConfiguration, kubeDeps *kubelet.Dependencies, enableServer bool) {
|
func startKubelet(k kubelet.Bootstrap, podCfg *config.PodConfig, kubeCfg *kubeletconfiginternal.KubeletConfiguration, kubeDeps *kubelet.Dependencies, enableCAdvisorJSONEndpoints, enableServer bool) {
|
||||||
// start the kubelet
|
// start the kubelet
|
||||||
go wait.Until(func() {
|
go wait.Until(func() {
|
||||||
k.Run(podCfg.Updates())
|
k.Run(podCfg.Updates())
|
||||||
|
@ -1093,11 +1093,11 @@ func startKubelet(k kubelet.Bootstrap, podCfg *config.PodConfig, kubeCfg *kubele
|
||||||
|
|
||||||
// start the kubelet server
|
// start the kubelet server
|
||||||
if enableServer {
|
if enableServer {
|
||||||
go k.ListenAndServe(net.ParseIP(kubeCfg.Address), uint(kubeCfg.Port), kubeDeps.TLSOptions, kubeDeps.Auth, kubeCfg.EnableDebuggingHandlers, kubeCfg.EnableContentionProfiling)
|
go k.ListenAndServe(net.ParseIP(kubeCfg.Address), uint(kubeCfg.Port), kubeDeps.TLSOptions, kubeDeps.Auth, enableCAdvisorJSONEndpoints, kubeCfg.EnableDebuggingHandlers, kubeCfg.EnableContentionProfiling)
|
||||||
|
|
||||||
}
|
}
|
||||||
if kubeCfg.ReadOnlyPort > 0 {
|
if kubeCfg.ReadOnlyPort > 0 {
|
||||||
go k.ListenAndServeReadOnly(net.ParseIP(kubeCfg.Address), uint(kubeCfg.ReadOnlyPort))
|
go k.ListenAndServeReadOnly(net.ParseIP(kubeCfg.Address), uint(kubeCfg.ReadOnlyPort), enableCAdvisorJSONEndpoints)
|
||||||
}
|
}
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.KubeletPodResources) {
|
if utilfeature.DefaultFeatureGate.Enabled(features.KubeletPodResources) {
|
||||||
go k.ListenAndServePodResources()
|
go k.ListenAndServePodResources()
|
||||||
|
|
|
@ -193,8 +193,8 @@ type Bootstrap interface {
|
||||||
GetConfiguration() kubeletconfiginternal.KubeletConfiguration
|
GetConfiguration() kubeletconfiginternal.KubeletConfiguration
|
||||||
BirthCry()
|
BirthCry()
|
||||||
StartGarbageCollection()
|
StartGarbageCollection()
|
||||||
ListenAndServe(address net.IP, port uint, tlsOptions *server.TLSOptions, auth server.AuthInterface, enableDebuggingHandlers, enableContentionProfiling bool)
|
ListenAndServe(address net.IP, port uint, tlsOptions *server.TLSOptions, auth server.AuthInterface, enableCAdvisorJSONEndpoints, enableDebuggingHandlers, enableContentionProfiling bool)
|
||||||
ListenAndServeReadOnly(address net.IP, port uint)
|
ListenAndServeReadOnly(address net.IP, port uint, enableCAdvisorJSONEndpoints bool)
|
||||||
ListenAndServePodResources()
|
ListenAndServePodResources()
|
||||||
Run(<-chan kubetypes.PodUpdate)
|
Run(<-chan kubetypes.PodUpdate)
|
||||||
RunOnce(<-chan kubetypes.PodUpdate) ([]RunPodResult, error)
|
RunOnce(<-chan kubetypes.PodUpdate) ([]RunPodResult, error)
|
||||||
|
@ -2202,13 +2202,13 @@ func (kl *Kubelet) ResyncInterval() time.Duration {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenAndServe runs the kubelet HTTP server.
|
// ListenAndServe runs the kubelet HTTP server.
|
||||||
func (kl *Kubelet) ListenAndServe(address net.IP, port uint, tlsOptions *server.TLSOptions, auth server.AuthInterface, enableDebuggingHandlers, enableContentionProfiling bool) {
|
func (kl *Kubelet) ListenAndServe(address net.IP, port uint, tlsOptions *server.TLSOptions, auth server.AuthInterface, enableCAdvisorJSONEndpoints, enableDebuggingHandlers, enableContentionProfiling bool) {
|
||||||
server.ListenAndServeKubeletServer(kl, kl.resourceAnalyzer, address, port, tlsOptions, auth, enableDebuggingHandlers, enableContentionProfiling, kl.redirectContainerStreaming, kl.criHandler)
|
server.ListenAndServeKubeletServer(kl, kl.resourceAnalyzer, address, port, tlsOptions, auth, enableCAdvisorJSONEndpoints, enableDebuggingHandlers, enableContentionProfiling, kl.redirectContainerStreaming, kl.criHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenAndServeReadOnly runs the kubelet HTTP server in read-only mode.
|
// ListenAndServeReadOnly runs the kubelet HTTP server in read-only mode.
|
||||||
func (kl *Kubelet) ListenAndServeReadOnly(address net.IP, port uint) {
|
func (kl *Kubelet) ListenAndServeReadOnly(address net.IP, port uint, enableCAdvisorJSONEndpoints bool) {
|
||||||
server.ListenAndServeKubeletReadOnlyServer(kl, kl.resourceAnalyzer, address, port)
|
server.ListenAndServeKubeletReadOnlyServer(kl, kl.resourceAnalyzer, address, port, enableCAdvisorJSONEndpoints)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenAndServePodResources runs the kubelet podresources grpc service
|
// ListenAndServePodResources runs the kubelet podresources grpc service
|
||||||
|
|
|
@ -136,12 +136,13 @@ func ListenAndServeKubeletServer(
|
||||||
port uint,
|
port uint,
|
||||||
tlsOptions *TLSOptions,
|
tlsOptions *TLSOptions,
|
||||||
auth AuthInterface,
|
auth AuthInterface,
|
||||||
|
enableCAdvisorJSONEndpoints,
|
||||||
enableDebuggingHandlers,
|
enableDebuggingHandlers,
|
||||||
enableContentionProfiling,
|
enableContentionProfiling,
|
||||||
redirectContainerStreaming bool,
|
redirectContainerStreaming bool,
|
||||||
criHandler http.Handler) {
|
criHandler http.Handler) {
|
||||||
klog.Infof("Starting to listen on %s:%d", address, port)
|
klog.Infof("Starting to listen on %s:%d", address, port)
|
||||||
handler := NewServer(host, resourceAnalyzer, auth, enableDebuggingHandlers, enableContentionProfiling, redirectContainerStreaming, criHandler)
|
handler := NewServer(host, resourceAnalyzer, auth, enableCAdvisorJSONEndpoints, enableDebuggingHandlers, enableContentionProfiling, redirectContainerStreaming, criHandler)
|
||||||
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,
|
||||||
|
@ -159,9 +160,9 @@ func ListenAndServeKubeletServer(
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenAndServeKubeletReadOnlyServer initializes a server to respond to HTTP network requests on the Kubelet.
|
// ListenAndServeKubeletReadOnlyServer initializes a server to respond to HTTP network requests on the Kubelet.
|
||||||
func ListenAndServeKubeletReadOnlyServer(host HostInterface, resourceAnalyzer stats.ResourceAnalyzer, address net.IP, port uint) {
|
func ListenAndServeKubeletReadOnlyServer(host HostInterface, resourceAnalyzer stats.ResourceAnalyzer, address net.IP, port uint, enableCAdvisorJSONEndpoints bool) {
|
||||||
klog.V(1).Infof("Starting to listen read-only on %s:%d", address, port)
|
klog.V(1).Infof("Starting to listen read-only on %s:%d", address, port)
|
||||||
s := NewServer(host, resourceAnalyzer, nil, false, false, false, nil)
|
s := NewServer(host, resourceAnalyzer, nil, enableCAdvisorJSONEndpoints, false, false, false, nil)
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: net.JoinHostPort(address.String(), strconv.FormatUint(uint64(port), 10)),
|
Addr: net.JoinHostPort(address.String(), strconv.FormatUint(uint64(port), 10)),
|
||||||
|
@ -212,6 +213,7 @@ func NewServer(
|
||||||
host HostInterface,
|
host HostInterface,
|
||||||
resourceAnalyzer stats.ResourceAnalyzer,
|
resourceAnalyzer stats.ResourceAnalyzer,
|
||||||
auth AuthInterface,
|
auth AuthInterface,
|
||||||
|
enableCAdvisorJSONEndpoints,
|
||||||
enableDebuggingHandlers,
|
enableDebuggingHandlers,
|
||||||
enableContentionProfiling,
|
enableContentionProfiling,
|
||||||
redirectContainerStreaming bool,
|
redirectContainerStreaming bool,
|
||||||
|
@ -226,7 +228,7 @@ func NewServer(
|
||||||
if auth != nil {
|
if auth != nil {
|
||||||
server.InstallAuthFilter()
|
server.InstallAuthFilter()
|
||||||
}
|
}
|
||||||
server.InstallDefaultHandlers()
|
server.InstallDefaultHandlers(enableCAdvisorJSONEndpoints)
|
||||||
if enableDebuggingHandlers {
|
if enableDebuggingHandlers {
|
||||||
server.InstallDebuggingHandlers(criHandler)
|
server.InstallDebuggingHandlers(criHandler)
|
||||||
if enableContentionProfiling {
|
if enableContentionProfiling {
|
||||||
|
@ -278,7 +280,7 @@ func (s *Server) InstallAuthFilter() {
|
||||||
|
|
||||||
// InstallDefaultHandlers registers the default set of supported HTTP request
|
// InstallDefaultHandlers registers the default set of supported HTTP request
|
||||||
// patterns with the restful Container.
|
// patterns with the restful Container.
|
||||||
func (s *Server) InstallDefaultHandlers() {
|
func (s *Server) InstallDefaultHandlers(enableCAdvisorJSONEndpoints bool) {
|
||||||
healthz.InstallHandler(s.restfulCont,
|
healthz.InstallHandler(s.restfulCont,
|
||||||
healthz.PingHealthz,
|
healthz.PingHealthz,
|
||||||
healthz.LogHealthz,
|
healthz.LogHealthz,
|
||||||
|
@ -293,7 +295,7 @@ func (s *Server) InstallDefaultHandlers() {
|
||||||
Operation("getPods"))
|
Operation("getPods"))
|
||||||
s.restfulCont.Add(ws)
|
s.restfulCont.Add(ws)
|
||||||
|
|
||||||
s.restfulCont.Add(stats.CreateHandlers(statsPath, s.host, s.resourceAnalyzer))
|
s.restfulCont.Add(stats.CreateHandlers(statsPath, s.host, s.resourceAnalyzer, enableCAdvisorJSONEndpoints))
|
||||||
s.restfulCont.Handle(metricsPath, prometheus.Handler())
|
s.restfulCont.Handle(metricsPath, prometheus.Handler())
|
||||||
|
|
||||||
// cAdvisor metrics are exposed under the secured handler as well
|
// cAdvisor metrics are exposed under the secured handler as well
|
||||||
|
@ -328,15 +330,17 @@ func (s *Server) InstallDefaultHandlers() {
|
||||||
promhttp.HandlerFor(p, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError}),
|
promhttp.HandlerFor(p, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError}),
|
||||||
)
|
)
|
||||||
|
|
||||||
ws = new(restful.WebService)
|
if enableCAdvisorJSONEndpoints {
|
||||||
ws.
|
ws := new(restful.WebService)
|
||||||
Path(specPath).
|
ws.
|
||||||
Produces(restful.MIME_JSON)
|
Path(specPath).
|
||||||
ws.Route(ws.GET("").
|
Produces(restful.MIME_JSON)
|
||||||
To(s.getSpec).
|
ws.Route(ws.GET("").
|
||||||
Operation("getSpec").
|
To(s.getSpec).
|
||||||
Writes(cadvisorapi.MachineInfo{}))
|
Operation("getSpec").
|
||||||
s.restfulCont.Add(ws)
|
Writes(cadvisorapi.MachineInfo{}))
|
||||||
|
s.restfulCont.Add(ws)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pprofBasePath = "/debug/pprof/"
|
const pprofBasePath = "/debug/pprof/"
|
||||||
|
|
|
@ -338,6 +338,7 @@ func newServerTestWithDebug(enableDebugging, redirectContainerStreaming bool, st
|
||||||
fw.fakeKubelet,
|
fw.fakeKubelet,
|
||||||
stats.NewResourceAnalyzer(fw.fakeKubelet, time.Minute),
|
stats.NewResourceAnalyzer(fw.fakeKubelet, time.Minute),
|
||||||
fw.fakeAuth,
|
fw.fakeAuth,
|
||||||
|
true,
|
||||||
enableDebugging,
|
enableDebugging,
|
||||||
false,
|
false,
|
||||||
redirectContainerStreaming,
|
redirectContainerStreaming,
|
||||||
|
|
|
@ -108,22 +108,29 @@ type handler struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateHandlers creates the REST handlers for the stats.
|
// CreateHandlers creates the REST handlers for the stats.
|
||||||
func CreateHandlers(rootPath string, provider Provider, summaryProvider SummaryProvider) *restful.WebService {
|
func CreateHandlers(rootPath string, provider Provider, summaryProvider SummaryProvider, enableCAdvisorJSONEndpoints bool) *restful.WebService {
|
||||||
h := &handler{provider, summaryProvider}
|
h := &handler{provider, summaryProvider}
|
||||||
|
|
||||||
ws := &restful.WebService{}
|
ws := &restful.WebService{}
|
||||||
ws.Path(rootPath).
|
ws.Path(rootPath).
|
||||||
Produces(restful.MIME_JSON)
|
Produces(restful.MIME_JSON)
|
||||||
|
|
||||||
endpoints := []struct {
|
type endpoint struct {
|
||||||
path string
|
path string
|
||||||
handler restful.RouteFunction
|
handler restful.RouteFunction
|
||||||
}{
|
}
|
||||||
{"", h.handleStats},
|
|
||||||
|
endpoints := []endpoint{
|
||||||
{"/summary", h.handleSummary},
|
{"/summary", h.handleSummary},
|
||||||
{"/container", h.handleSystemContainer},
|
}
|
||||||
{"/{podName}/{containerName}", h.handlePodContainer},
|
|
||||||
{"/{namespace}/{podName}/{uid}/{containerName}", h.handlePodContainer},
|
if enableCAdvisorJSONEndpoints {
|
||||||
|
endpoints = append(endpoints,
|
||||||
|
endpoint{"", h.handleStats},
|
||||||
|
endpoint{"/container", h.handleSystemContainer},
|
||||||
|
endpoint{"/{podName}/{containerName}", h.handlePodContainer},
|
||||||
|
endpoint{"/{namespace}/{podName}/{uid}/{containerName}", h.handlePodContainer},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range endpoints {
|
for _, e := range endpoints {
|
||||||
|
|
Loading…
Reference in New Issue