Skip to content

Commit

Permalink
Use metrics for readiness/liveness probes
Browse files Browse the repository at this point in the history
Since the existing healthz/readyz don't do much, we
leverage the existing metrics endpoint for the probes to
avoid opening another port (8081) on the host.

Signed-off-by: Ori Braunshtein <[email protected]>
  • Loading branch information
oribon committed Nov 11, 2024
1 parent bfeacb8 commit 5b13edb
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 55 deletions.
1 change: 0 additions & 1 deletion charts/frr-k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Kubernetes: `>= 1.19.0-0`
| frrk8s.frr.resources | object | `{}` | |
| frrk8s.frr.secureMetricsPort | int | `9141` | |
| frrk8s.frrMetrics.resources | object | `{}` | |
| frrk8s.healthPort | int | `8081` | |
| frrk8s.image.pullPolicy | string | `nil` | |
| frrk8s.image.repository | string | `"quay.io/metallb/frr-k8s"` | |
| frrk8s.image.tag | string | `nil` | |
Expand Down
9 changes: 4 additions & 5 deletions charts/frr-k8s/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ spec:
{{- with .Values.frrk8s.logLevel }}
- --log-level={{ . }}
{{- end }}
- --health-probe-bind-address={{.Values.prometheus.metricsBindAddress}}:{{ .Values.frrk8s.healthPort }}
{{- if .Values.frrk8s.alwaysBlock }}
- --always-block={{ .Values.frrk8s.alwaysBlock }}
{{- end }}
Expand All @@ -222,8 +221,8 @@ spec:
{{- if .Values.frrk8s.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: /healthz
port: {{ .Values.frrk8s.healthPort }}
path: /metrics
port: monitoring
host: {{ .Values.prometheus.metricsBindAddress }}
initialDelaySeconds: {{ .Values.frrk8s.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.frrk8s.livenessProbe.periodSeconds }}
Expand All @@ -234,8 +233,8 @@ spec:
{{- if .Values.frrk8s.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: /healthz
port: {{ .Values.frrk8s.healthPort }}
path: /metrics
port: monitoring
host: {{ .Values.prometheus.metricsBindAddress }}
initialDelaySeconds: {{ .Values.frrk8s.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.frrk8s.readinessProbe.periodSeconds }}
Expand Down
13 changes: 8 additions & 5 deletions charts/frr-k8s/templates/webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec:
- "--restart-on-rotator-secret-refresh=true"
{{- end }}
- "--namespace=$(NAMESPACE)"
- --health-probe-bind-address=:8081
- "--metrics-bind-address=:{{ .Values.prometheus.metricsPort }}"
env:
- name: NAMESPACE
valueFrom:
Expand All @@ -59,20 +59,23 @@ spec:
drop:
- ALL
readOnlyRootFilesystem: true
ports:
- containerPort: {{ .Values.prometheus.metricsPort }}
name: monitoring
{{- if .Values.frrk8s.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: /healthz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: {{ .Values.frrk8s.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.frrk8s.livenessProbe.periodSeconds }}
failureThreshold: {{ .Values.frrk8s.livenessProbe.failureThreshold }}
{{- end }}
{{- if .Values.frrk8s.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: /readyz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: {{ .Values.frrk8s.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.frrk8s.readinessProbe.periodSeconds }}
failureThreshold: {{ .Values.frrk8s.readinessProbe.failureThreshold }}
Expand Down
1 change: 0 additions & 1 deletion charts/frr-k8s/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ frrk8s:
podAnnotations: {}
labels:
app: frr-k8s
healthPort: 8081
livenessProbe:
enabled: true
failureThreshold: 3
Expand Down
14 changes: 1 addition & 13 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
Expand Down Expand Up @@ -70,7 +69,6 @@ func init() {
func main() {
var (
metricsAddr string
probeAddr string
logLevel string
nodeName string
namespace string
Expand All @@ -84,7 +82,6 @@ func main() {
)

flag.StringVar(&metricsAddr, "metrics-bind-address", "127.0.0.1:7572", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", "127.0.0.1:8081", "The address the probe endpoint binds to.")
flag.StringVar(&logLevel, "log-level", "info", fmt.Sprintf("log level. must be one of: [%s]", logging.Levels.String()))
flag.StringVar(&nodeName, "node-name", "", "The node this daemon is running on.")
flag.StringVar(&namespace, "namespace", "", "The namespace this daemon is deployed in")
Expand Down Expand Up @@ -114,7 +111,7 @@ func main() {

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
HealthProbeBindAddress: probeAddr,
HealthProbeBindAddress: "", // we use the metrics endpoint for healthchecks
Cache: cache.Options{
ByObject: map[client.Object]cache.ByObject{
&corev1.Secret{}: namespaceSelector,
Expand All @@ -139,15 +136,6 @@ func main() {

//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}

enableWebhook := webhookMode == "onlywebhook"
startListeners := make(chan struct{})
if enableWebhook && !disableCertRotation {
Expand Down
22 changes: 12 additions & 10 deletions config/all-in-one/frr-k8s-prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ spec:
- --log-level=info
- --webhook-mode=onlywebhook
- --namespace=$(NAMESPACE)
- --health-probe-bind-address=:8081
- --metrics-bind-address=:7572
command:
- /frr-k8s
env:
Expand All @@ -975,15 +975,18 @@ spec:
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /healthz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: 15
periodSeconds: 20
name: frr-k8s-webhook-server
ports:
- containerPort: 7572
name: monitoring
readinessProbe:
httpGet:
path: /readyz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: 5
periodSeconds: 10
resources:
Expand Down Expand Up @@ -1107,7 +1110,6 @@ spec:
drop:
- ALL
- args:
- --health-probe-bind-address=127.0.0.1:8081
- --metrics-bind-address=127.0.0.1:7572
- --node-name=$(NODE_NAME)
- --namespace=$(NAMESPACE)
Expand All @@ -1132,8 +1134,8 @@ spec:
livenessProbe:
httpGet:
host: 127.0.0.1
path: /healthz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: 15
periodSeconds: 20
name: frr-k8s
Expand All @@ -1143,8 +1145,8 @@ spec:
readinessProbe:
httpGet:
host: 127.0.0.1
path: /readyz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: 5
periodSeconds: 10
resources:
Expand Down
22 changes: 12 additions & 10 deletions config/all-in-one/frr-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ spec:
- --log-level=info
- --webhook-mode=onlywebhook
- --namespace=$(NAMESPACE)
- --health-probe-bind-address=:8081
- --metrics-bind-address=:7572
command:
- /frr-k8s
env:
Expand All @@ -944,15 +944,18 @@ spec:
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /healthz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: 15
periodSeconds: 20
name: frr-k8s-webhook-server
ports:
- containerPort: 7572
name: monitoring
readinessProbe:
httpGet:
path: /readyz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: 5
periodSeconds: 10
resources:
Expand Down Expand Up @@ -1076,7 +1079,6 @@ spec:
drop:
- ALL
- args:
- --health-probe-bind-address=127.0.0.1:8081
- --metrics-bind-address=127.0.0.1:7572
- --node-name=$(NODE_NAME)
- --namespace=$(NAMESPACE)
Expand All @@ -1101,8 +1103,8 @@ spec:
livenessProbe:
httpGet:
host: 127.0.0.1
path: /healthz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: 15
periodSeconds: 20
name: frr-k8s
Expand All @@ -1112,8 +1114,8 @@ spec:
readinessProbe:
httpGet:
host: 127.0.0.1
path: /readyz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: 5
periodSeconds: 10
resources:
Expand Down
1 change: 0 additions & 1 deletion config/default/frr-k8s_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ spec:
- ALL
- name: frr-k8s
args:
- "--health-probe-bind-address=127.0.0.1:8081"
- "--metrics-bind-address=127.0.0.1:7572"
- "--node-name=$(NODE_NAME)"
- "--namespace=$(NAMESPACE)"
Expand Down
21 changes: 12 additions & 9 deletions config/frr-k8s/frr-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ spec:
readOnlyRootFilesystem: true
livenessProbe:
httpGet:
path: /healthz
port: 8081
path: /metrics
port: monitoring
host: 127.0.0.1
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /readyz
port: 8081
path: /metrics
port: monitoring
host: 127.0.0.1
initialDelaySeconds: 5
periodSeconds: 10
Expand Down Expand Up @@ -243,7 +243,7 @@ spec:
- "--log-level=info"
- "--webhook-mode=onlywebhook"
- "--namespace=$(NAMESPACE)"
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=:7572"
env:
- name: NAMESPACE
valueFrom:
Expand All @@ -258,16 +258,19 @@ spec:
drop:
- ALL
readOnlyRootFilesystem: true
ports:
- containerPort: 7572
name: monitoring
livenessProbe:
httpGet:
path: /healthz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /readyz
port: 8081
path: /metrics
port: monitoring
initialDelaySeconds: 5
periodSeconds: 10
# TODO(user): Configure the resources accordingly based on the project requirements.
Expand Down

0 comments on commit 5b13edb

Please sign in to comment.