-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[deployment] feat: add deployment readiness tutorial.
- Loading branch information
1 parent
c5e1b3b
commit d486ef2
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |