Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib: update k8s liveness and readiness probes #4405

Merged
merged 2 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions contrib/config/kubernetes/dgraph-ha/dgraph-ha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ spec:
else
exec dgraph zero --my=$(hostname -f):5080 --peer dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080 --idx $idx --replicas 3
fi
livenessProbe:
httpGet:
path: /health
port: 6080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
readinessProbe:
httpGet:
path: /state
port: 6080
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
terminationGracePeriodSeconds: 60
volumes:
- name: datadir
Expand Down Expand Up @@ -285,6 +303,24 @@ spec:
- |
set -ex
dgraph alpha --my=$(hostname -f):7080 --lru_mb 2048 --zero dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080
livenessProbe:
httpGet:
path: /health?live=1
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
terminationGracePeriodSeconds: 600
volumes:
- name: datadir
Expand Down
4 changes: 2 additions & 2 deletions contrib/config/kubernetes/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ zero:
livenessProbe:
enabled: false
port: 6080
path: /state
path: /health
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
Expand Down Expand Up @@ -215,7 +215,7 @@ alpha:
livenessProbe:
enabled: false
port: 8080
path: /health
path: /health?live=1
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
Expand Down
16 changes: 10 additions & 6 deletions dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,17 @@ func grpcPort() int {

func healthCheck(w http.ResponseWriter, r *http.Request) {
x.AddCorsHeaders(w)
if err := x.HealthCheck(); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
_, err = w.Write([]byte(err.Error()))
if err != nil {
glog.V(2).Infof("Error while writing health check response: %v", err)

_, ok := r.URL.Query()["live"]
if !ok {
if err := x.HealthCheck(); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
_, err = w.Write([]byte(err.Error()))
if err != nil {
glog.V(2).Infof("Error while writing health check response: %v", err)
}
return
}
return
}

info := struct {
Expand Down
7 changes: 7 additions & 0 deletions dgraph/cmd/zero/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ func (st *state) getState(w http.ResponseWriter, r *http.Request) {
}
}

func (st *state) pingResponse(w http.ResponseWriter, r *http.Request) {
x.AddCorsHeaders(w)

w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("OK"))
}

func (st *state) serveHTTP(l net.Listener) {
srv := &http.Server{
ReadTimeout: 10 * time.Second,
Expand Down
1 change: 1 addition & 0 deletions dgraph/cmd/zero/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func run() {
st.serveGRPC(grpcListener, store)
st.serveHTTP(httpListener)

http.HandleFunc("/health", st.pingResponse)
http.HandleFunc("/state", st.getState)
http.HandleFunc("/removeNode", st.removeNode)
http.HandleFunc("/moveTablet", st.moveTablet)
Expand Down