Skip to content

Commit

Permalink
[deployment] feat: add deployment readiness tutorial.
Browse files Browse the repository at this point in the history
  • Loading branch information
guangzhengli committed Aug 26, 2022
1 parent c5e1b3b commit d486ef2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
16 changes: 16 additions & 0 deletions deployment/readiness/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Dockerfile
FROM golang:1.16-buster AS builder
RUN mkdir /src
ADD . /src
WORKDIR /src

RUN go env -w GO111MODULE=auto
RUN go build -o main .

FROM gcr.io/distroless/base-debian10

WORKDIR /

COPY --from=builder /src/main /main
EXPOSE 3000
ENTRYPOINT ["/main"]
27 changes: 27 additions & 0 deletions deployment/readiness/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: hellok8s-deployment
spec:
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
replicas: 3
selector:
matchLabels:
app: hellok8s
template:
metadata:
labels:
app: hellok8s
spec:
containers:
- image: guangzhengli/hellok8s:bad
name: hellok8s-container
readinessProbe:
httpGet:
path: /healthz
port: 3000
initialDelaySeconds: 1
successThreshold: 5
19 changes: 19 additions & 0 deletions deployment/readiness/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"io"
"net/http"
)

func hello(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "[v2] Hello, Kubernetes!")
}

func main() {
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(500)
})

http.HandleFunc("/", hello)
http.ListenAndServe(":3000", nil)
}

0 comments on commit d486ef2

Please sign in to comment.