@@ -31,6 +31,7 @@ import (
3131 ctrl "sigs.k8s.io/controller-runtime"
3232 "sigs.k8s.io/controller-runtime/pkg/healthz"
3333 "sigs.k8s.io/controller-runtime/pkg/log/zap"
34+ "sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3435 metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3536 "sigs.k8s.io/controller-runtime/pkg/webhook"
3637
@@ -57,14 +58,14 @@ func main() {
5758 var probeAddr string
5859 var secureMetrics bool
5960 var enableHTTP2 bool
60- flag .StringVar (& metricsAddr , "metrics-bind-address" , "0" , "The address the metric endpoint binds to. " +
61- "Use the port :8080. If not set, it will be 0 in order to disable the metrics server " )
61+ flag .StringVar (& metricsAddr , "metrics-bind-address" , "0" , "The address the metrics endpoint binds to. " +
62+ "Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service. " )
6263 flag .StringVar (& probeAddr , "health-probe-bind-address" , ":8081" , "The address the probe endpoint binds to." )
6364 flag .BoolVar (& enableLeaderElection , "leader-elect" , false ,
6465 "Enable leader election for controller manager. " +
6566 "Enabling this will ensure there is only one active controller manager." )
66- flag .BoolVar (& secureMetrics , "metrics-secure" , false ,
67- "If set the metrics endpoint is served securely" )
67+ flag .BoolVar (& secureMetrics , "metrics-secure" , true ,
68+ "If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead. " )
6869 flag .BoolVar (& enableHTTP2 , "enable-http2" , false ,
6970 "If set, HTTP/2 will be enabled for the metrics and webhook servers" )
7071 opts := zap.Options {
@@ -97,10 +98,25 @@ func main() {
9798
9899 mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
99100 Scheme : scheme ,
101+ // Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
102+ // More info:
103+ // - https://pkg.go.dev/sigs.k8s.io/[email protected] /pkg/metrics/server 104+ // - https://book.kubebuilder.io/reference/metrics.html
100105 Metrics : metricsserver.Options {
101106 BindAddress : metricsAddr ,
102107 SecureServing : secureMetrics ,
103- TLSOpts : tlsOpts ,
108+ // TODO(user): TLSOpts is used to allow configuring the TLS config used for the server. If certificates are
109+ // not provided, self-signed certificates will be generated by default. This option is not recommended for
110+ // production environments as self-signed certificates do not offer the same level of trust and security
111+ // as certificates issued by a trusted Certificate Authority (CA). The primary risk is potentially allowing
112+ // unauthorized access to sensitive metrics data. Consider replacing with CertDir, CertName, and KeyName
113+ // to provide certificates, ensuring the server communicates using trusted and secure certificates.
114+ TLSOpts : tlsOpts ,
115+ // FilterProvider is used to protect the metrics endpoint with authn/authz.
116+ // These configurations ensure that only authorized users and service accounts
117+ // can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
118+ // https://pkg.go.dev/sigs.k8s.io/[email protected] /pkg/metrics/filters#WithAuthenticationAndAuthorization 119+ FilterProvider : filters .WithAuthenticationAndAuthorization ,
104120 },
105121 WebhookServer : webhookServer ,
106122 HealthProbeBindAddress : probeAddr ,
0 commit comments