Skip to content

Commit d486ef2

Browse files
committed
[deployment] feat: add deployment readiness tutorial.
1 parent c5e1b3b commit d486ef2

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

deployment/readiness/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Dockerfile
2+
FROM golang:1.16-buster AS builder
3+
RUN mkdir /src
4+
ADD . /src
5+
WORKDIR /src
6+
7+
RUN go env -w GO111MODULE=auto
8+
RUN go build -o main .
9+
10+
FROM gcr.io/distroless/base-debian10
11+
12+
WORKDIR /
13+
14+
COPY --from=builder /src/main /main
15+
EXPOSE 3000
16+
ENTRYPOINT ["/main"]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: hellok8s-deployment
5+
spec:
6+
strategy:
7+
rollingUpdate:
8+
maxSurge: 1
9+
maxUnavailable: 1
10+
replicas: 3
11+
selector:
12+
matchLabels:
13+
app: hellok8s
14+
template:
15+
metadata:
16+
labels:
17+
app: hellok8s
18+
spec:
19+
containers:
20+
- image: guangzhengli/hellok8s:bad
21+
name: hellok8s-container
22+
readinessProbe:
23+
httpGet:
24+
path: /healthz
25+
port: 3000
26+
initialDelaySeconds: 1
27+
successThreshold: 5

deployment/readiness/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"io"
5+
"net/http"
6+
)
7+
8+
func hello(w http.ResponseWriter, r *http.Request) {
9+
io.WriteString(w, "[v2] Hello, Kubernetes!")
10+
}
11+
12+
func main() {
13+
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
14+
w.WriteHeader(500)
15+
})
16+
17+
http.HandleFunc("/", hello)
18+
http.ListenAndServe(":3000", nil)
19+
}

0 commit comments

Comments
 (0)