Add a /healthz endpoint to your Go HTTP server that returns a 200 OK status, then configure your Kubernetes Deployment to use a livenessProbe and readinessProbe pointing to that path.
package main
import (
"net/http"
)
func main() {
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
http.ListenAndServe(":8080", nil)
}
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-go-app
spec:
template:
spec:
containers:
- name: app
image: my-go-app:latest
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 5