Skip to content

Commit a697e2c

Browse files
committed
devapp: add healthz endpoint and configure k8s readiness probe
This will allow for zero-downtime deployments, which will be important for when services start relying on the /owners endpoint. Change-Id: I4671dbbbf473ba07dbab585222d12832c3193fac Reviewed-on: https://go-review.googlesource.com/127036 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent b9f5d4d commit a697e2c

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

devapp/deployment-prod.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Deployment
33
metadata:
44
name: devapp-deployment
55
spec:
6-
replicas: 1
6+
replicas: 2
77
template:
88
metadata:
99
labels:
@@ -17,6 +17,10 @@ spec:
1717
image: gcr.io/symbolic-datum-552/devapp:latest
1818
imagePullPolicy: Always
1919
command: ["/devapp", "-listen=:80", "-autocert-bucket=golang-devapp-autocert"]
20+
readinessProbe:
21+
httpGet:
22+
path: /healthz
23+
port: 80
2024
ports:
2125
- containerPort: 80
2226
- containerPort: 443

devapp/deployment-staging.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Deployment
33
metadata:
44
name: devapp-deployment
55
spec:
6-
replicas: 1
6+
replicas: 2
77
template:
88
metadata:
99
labels:
@@ -17,6 +17,10 @@ spec:
1717
image: gcr.io/go-dashboard-dev/devapp:latest
1818
imagePullPolicy: Always
1919
command: ["/devapp", "-listen=:80", "-autocert-bucket=golang-devapp-dev-autocert"]
20+
readinessProbe:
21+
httpGet:
22+
path: /healthz
23+
port: 80
2024
ports:
2125
- containerPort: 80
2226
- containerPort: 443

devapp/devapp.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func main() {
7878
}
7979

8080
func redirectHTTP(w http.ResponseWriter, r *http.Request) {
81+
if r.URL.Path == "/healthz" {
82+
handleHealthz(w, r)
83+
return
84+
}
8185
if r.TLS != nil || r.Host == "" {
8286
http.NotFound(w, r)
8387
return

devapp/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func newServer(mux *http.ServeMux, staticDir, templateDir string) *server {
6060
userMapping: map[int]*maintner.GitHubUser{},
6161
}
6262
s.mux.Handle("/", http.FileServer(http.Dir(s.staticDir)))
63+
s.mux.HandleFunc("/healthz", handleHealthz)
6364
s.mux.HandleFunc("/favicon.ico", s.handleFavicon)
6465
s.mux.HandleFunc("/release", s.withTemplate("/release.tmpl", s.handleRelease))
6566
s.mux.HandleFunc("/reviews", s.withTemplate("/reviews.tmpl", s.handleReviews))
@@ -186,6 +187,11 @@ func (s *server) filteredHelpWantedIssues(pkgs ...string) []issueData {
186187
return issues
187188
}
188189

190+
func handleHealthz(w http.ResponseWriter, r *http.Request) {
191+
w.WriteHeader(http.StatusOK)
192+
w.Write([]byte("ok"))
193+
}
194+
189195
func (s *server) handleFavicon(w http.ResponseWriter, r *http.Request) {
190196
// Need to specify content type for consistent tests, without this it's
191197
// determined from mime.types on the box the test is running on

0 commit comments

Comments
 (0)