From 70390d038995d46638fe33d1fc2bfd460df535f6 Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Sun, 12 Mar 2023 00:06:42 +0100 Subject: [PATCH] fix: Probes --- charts/well-known/templates/configmap.yaml | 15 ++++++++++++++ charts/well-known/templates/deployment.yaml | 23 +++++++++++++++++++++ charts/well-known/values.yaml | 22 ++++++++------------ server/main.go | 13 ++++++++++++ 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/charts/well-known/templates/configmap.yaml b/charts/well-known/templates/configmap.yaml index 410dea3..1f54335 100644 --- a/charts/well-known/templates/configmap.yaml +++ b/charts/well-known/templates/configmap.yaml @@ -26,3 +26,18 @@ data: return 200 '{"code":"1", "message": "Unknown Error"}'; } } + server { + listen 8082; + server_name localhost; + root /usr/share/nginx/html; + + access_log off; + allow 127.0.0.1; + deny all; + + location /healthz { + allow 127.0.0.1; + stub_status; + server_tokens on; + } + } diff --git a/charts/well-known/templates/deployment.yaml b/charts/well-known/templates/deployment.yaml index 734c915..2489e38 100644 --- a/charts/well-known/templates/deployment.yaml +++ b/charts/well-known/templates/deployment.yaml @@ -37,6 +37,17 @@ spec: - name: http containerPort: 8080 protocol: TCP + - name: probe + containerPort: 8082 + protocol: TCP + livenessProbe: + httpGet: + path: /healthz + port: probe + readinessProbe: + httpGet: + path: /healthz + port: probe volumeMounts: - name: config mountPath: /etc/nginx/conf.d/default.conf @@ -62,6 +73,18 @@ spec: fieldRef: apiVersion: v1 fieldPath: metadata.name + ports: + - name: probe + containerPort: 8081 + protocol: TCP + livenessProbe: + httpGet: + path: /healthz + port: probe + readinessProbe: + httpGet: + path: /healthz + port: probe resources: {{- toYaml .Values.resources | nindent 12 }} {{- with .Values.nodeSelector }} diff --git a/charts/well-known/values.yaml b/charts/well-known/values.yaml index 00aa888..79195de 100644 --- a/charts/well-known/values.yaml +++ b/charts/well-known/values.yaml @@ -6,26 +6,22 @@ replicaCount: 2 image: repository: ghcr.io/stenic/well-known - pullPolicy: IfNotPresent + pullPolicy: Always # Overrides the image tag whose default is the chart appVersion. tag: "" -resources: {} -# We usually recommend not to specify default resources and to leave this as a conscious -# choice for the user. This also increases chances charts run on environments with little -# resources, such as Minikube. If you do want to specify resources, uncomment the following -# lines, adjust them as necessary, and remove the curly braces after 'resources:'. -# limits: -# cpu: 100m -# memory: 128Mi -# requests: -# cpu: 100m -# memory: 128Mi +resources: + limits: + cpu: 50m + memory: 64Mi + requests: + cpu: 20m + memory: 32Mi webserver: image: repository: nginxinc/nginx-unprivileged - pullPolicy: IfNotPresent + pullPolicy: Always tag: "1.23" resources: limits: diff --git a/server/main.go b/server/main.go index 65ce64e..e72564f 100644 --- a/server/main.go +++ b/server/main.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "flag" + "net/http" "os" "os/signal" "path/filepath" @@ -86,6 +87,18 @@ func main() { }, } + go func() { + http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + klog.Info("Running /healthz endpoint on :8081") + if err := http.ListenAndServe(":8081", nil); err != nil { + klog.Error(err) + os.Exit(1) + } + }() + // start the leader election code loop leaderelection.RunOrDie(ctx, leaderelection.LeaderElectionConfig{ Lock: lock,