Skip to content

Commit f886914

Browse files
committed
Merge branch 'master' of github.com:twogg-git/k8s-workshop into 1.1-rolling
2 parents a7189f3 + 31f5719 commit f886914

File tree

9 files changed

+123
-7
lines changed

9 files changed

+123
-7
lines changed

k8s/k8s.go

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
"net/http"
77
)
88

9+
var (
10+
bannedIp = "0.0.0.0"
11+
)
12+
913
func getServerIP() string {
1014
conn, err := net.Dial("udp", "8.8.8.8:80")
1115
if err != nil {
@@ -15,18 +19,54 @@ func getServerIP() string {
1519
return conn.LocalAddr().(*net.UDPAddr).IP.String()
1620
}
1721

22+
func getHTML(status string) string {
23+
message := "DevOps, Mr. Cat speaking, how can I help you?"
24+
image := "1.3.0"
25+
color := "orange"
26+
if status == "alive" {
27+
message = "High five budy, I'm healthy as ever!"
28+
image = "1.3.1"
29+
color = "green"
30+
}
31+
if status == "dead" {
32+
message = "I don't want to die Mr. Stark..."
33+
image = "1.3.2"
34+
color = "red"
35+
}
36+
return `<!DOCTYPE html><html><body><center>
37+
<img src="https://raw.githubusercontent.com/twogg-git/k8s-workshop/master/src/` + image + `.png">
38+
<h1 style="color:` + color + `">` + message + `</h3>
39+
<h2 style="color:green">Playing with Kubernetes</h1>
40+
<h2 style="color:blue">Server IP ` + getServerIP() + `</h2>
41+
<h3 style="color:blue">Version twogghub/k8s-workshop:1.3-liveness</h3>
42+
</center></body></html>`
43+
}
44+
1845
func playHome(w http.ResponseWriter, r *http.Request) {
19-
html := `<!DOCTYPE html><html><body><center>
20-
<img src="https://raw.githubusercontent.com/twogg-git/k8s-workshop/master/src/1.1.png">
21-
<h1 style="color:blue">Playing with Kubernetes</h1>
22-
<h2 style="color:purple">Your server IP:` + getServerIP() + `</h2>
23-
<h3 style="color:green">Version: twogghub/k8s-workshop:1.1-rolling</h3>
24-
</center></body></html>`
25-
fmt.Fprintf(w, html)
46+
if bannedIp == getServerIP() {
47+
fmt.Fprintf(w, getHTML("dead"))
48+
} else {
49+
fmt.Fprintf(w, getHTML("home"))
50+
}
51+
}
52+
53+
func playHealth(w http.ResponseWriter, r *http.Request) {
54+
if getServerIP() == bannedIp {
55+
w.WriteHeader(http.StatusServiceUnavailable)
56+
} else {
57+
fmt.Fprintf(w, getHTML("alive"))
58+
}
59+
}
60+
61+
func playKillMe(w http.ResponseWriter, r *http.Request) {
62+
bannedIp = getServerIP()
63+
fmt.Fprintf(w, getHTML("dead"))
2664
}
2765

2866
func main() {
2967
http.HandleFunc("/", playHome)
68+
http.HandleFunc("/health", playHealth)
69+
http.HandleFunc("/killme", playKillMe)
3070
if err := http.ListenAndServe(":8080", nil); err != nil {
3171
panic(err)
3272
}

src/1.1.1.png

199 KB
Loading

src/1.2.1.png

153 KB
Loading
File renamed without changes.

src/1.3.1.png

120 KB
Loading

src/1.3.2.png

158 KB
Loading

yamls/k8sdp.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: k8sdp
5+
spec:
6+
replicas: 3
7+
strategy:
8+
type: RollingUpdate
9+
rollingUpdate:
10+
maxSurge: 1
11+
maxUnavailable: 1
12+
selector:
13+
matchLabels:
14+
env: k8sdp
15+
template:
16+
metadata:
17+
labels:
18+
env: k8sdp
19+
annotations:
20+
kubernetes.io/change-cause: "HttpGet /health return error!"
21+
spec:
22+
containers:
23+
- image: twogghub/k8s-workshop:1.3-liveness
24+
name: k8sdp
25+
livenessProbe:
26+
httpGet:
27+
path: /health
28+
port: 8080
29+
initialDelaySeconds: 5
30+
timeoutSeconds: 1
31+
periodSeconds: 2
32+
failureThreshold: 1
33+
ports:
34+
- name: http
35+
containerPort: 8080

yamls/k8sprod.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: k8sprod
5+
spec:
6+
replicas: 2
7+
strategy:
8+
type: RollingUpdate
9+
rollingUpdate:
10+
maxSurge: 1
11+
maxUnavailable: 1
12+
template:
13+
metadata:
14+
labels:
15+
env: prod
16+
spec:
17+
containers:
18+
- image: twogghub/k8s-workshop:1.2-yaml
19+
name: k8sprod
20+
ports:
21+
- name: http
22+
containerPort: 8080

yamls/k8sqa.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: k8sqa
5+
spec:
6+
replicas: 2
7+
strategy:
8+
type: Recreate
9+
template:
10+
metadata:
11+
labels:
12+
env: qa
13+
spec:
14+
containers:
15+
- image: twogghub/k8s-workshop:1.2-qaonly
16+
name: k8sqa
17+
ports:
18+
- name: http
19+
containerPort: 9090

0 commit comments

Comments
 (0)