Skip to content

Instantly share code, notes, and snippets.

@broady
Created December 4, 2016 22:21
Show Gist options
  • Save broady/c82ae5cf2919684926b8bcc23d6ccddc to your computer and use it in GitHub Desktop.
Save broady/c82ae5cf2919684926b8bcc23d6ccddc to your computer and use it in GitHub Desktop.
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
labels:
app: readiness-bug
name: readiness-bug
spec:
replicas: 1
template:
metadata:
labels:
app: readiness-bug
spec:
containers:
- name: readiness-bug
image: broady/k8s-readiness-bug:latest
imagePullPolicy: Always
ports:
- name: http
containerPort: 8080
env:
- name: ANYTHING
value: something
readinessProbe:
httpGet:
path: /healthz
port: http
timeoutSeconds: 1
---
kind: Service
apiVersion: v1
metadata:
labels:
app: readiness-bug
name: readiness-bug
spec:
type: LoadBalancer
ports:
- name: http
port: 80
targetPort: http
selector:
app: readiness-bug
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"time"
)
var startup = time.Now()
func main() {
http.HandleFunc("/healthz", health)
http.HandleFunc("/", serve)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func serve(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "since startup: %s\n", time.Now().Sub(startup))
for _, e := range os.Environ() {
fmt.Fprintln(w, e)
}
}
func health(w http.ResponseWriter, r *http.Request) {
if time.Now().After(startup.Add(30 * time.Second)) {
io.WriteString(w, "ok")
return
}
http.Error(w, "starting up", http.StatusServiceUnavailable)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment