Skip to content

Commit c037366

Browse files
committed
Adding kubernetes resources
Moving to singles folder each docker and k8s files
1 parent 7432410 commit c037366

File tree

5 files changed

+71
-9
lines changed

5 files changed

+71
-9
lines changed
File renamed without changes.

docker/website/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Docker</title>
5+
</head>
6+
<body><center>
7+
<img src="https://raw.githubusercontent.com/twogg-git/docker-nginx/master/docker.png">
8+
<h1 style="color:blue">Baby steps with docker!</h1>
9+
</center></body>
10+
</html>

k8s/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM golang:1.10-alpine3.7 as builder
2+
WORKDIR /go/src/k8s-workshop/k8s
3+
COPY k8s.go .
4+
RUN go get -d ./... && go build -o k8s .
5+
6+
FROM alpine:3.8
7+
RUN apk --no-cache add ca-certificates
8+
WORKDIR /root/
9+
COPY --from=builder /go/src/k8s-workshop/k8s .
10+
11+
EXPOSE 8080
12+
ENTRYPOINT ./k8s

k8s/k8s.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net"
6+
"net/http"
7+
)
8+
9+
var (
10+
version = "1.0"
11+
bannedIp = "9"
12+
html = `<!DOCTYPE html><html><body><center>
13+
<img src="https://raw.githubusercontent.com/twogg-git/k8s-intro/master/kubernetes_katacoda.png">
14+
<h1 style="color:green">Playing with Kubernetes</h1>
15+
<h2 style="color:blue">Your server IP:` + getServerIP() + `</h2>
16+
<h3 style="color:blue">Version: twogghub/k8s-workshop:` + version + `</h3>
17+
<h3 style="color:red">Banned IP ending number: ` + bannedIp + `</h3>
18+
</center></body></html>`
19+
)
20+
21+
func getServerIP() string {
22+
conn, err := net.Dial("udp", "8.8.8.8:80")
23+
if err != nil {
24+
panic(err)
25+
}
26+
defer conn.Close()
27+
return conn.LocalAddr().(*net.UDPAddr).IP.String()
28+
}
29+
30+
func playHome(w http.ResponseWriter, r *http.Request) {
31+
fmt.Fprintf(w, html)
32+
}
33+
34+
func playWithIP(w http.ResponseWriter, r *http.Request) {
35+
ip := getServerIP()
36+
if ip[len(ip)-1:] == bannedIp {
37+
w.WriteHeader(http.StatusInternalServerError)
38+
} else {
39+
fmt.Fprintf(w, "Play cool, I'm alive!!!")
40+
}
41+
}
42+
43+
func main() {
44+
http.HandleFunc("/", playHome)
45+
http.HandleFunc("/status", playWithIP)
46+
if err := http.ListenAndServe(":8080", nil); err != nil {
47+
panic(err)
48+
}
49+
}

website/index.html

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)