-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathgolang-go
133 lines (112 loc) · 2.68 KB
/
golang-go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# https://gowebexamples.com/hello-world/
docker run --name gowebapp -p 80:80 -id quickbooks2018/goapp:v1
Go Application
---------------
web.go
-------
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello from cloudgeeks.ca")
})
http.ListenAndServe(":80", nil)
}
Dockerfile
----------
FROM golang:alpine
# Set the Current Working Directory inside the container
WORKDIR /usr/src/goapp
# Copy everything from the current directory to the PWD (Present Working Directory) inside the container
COPY web.go /usr/src/goapp/web.go
# This container exposes port 8080 to the outside world
EXPOSE 80
# Run the executable
CMD ["go","run","web.go"]
# Kubernetes
# https://www.youtube.com/watch?v=XqMdrtwRwqw&ab_channel=ContainersfromtheCouch ---> 40min
# https://github.com/aws-samples/amazon-eks-sample-http-service
goapp
------
goapp.yaml with AWS ALB Ingress
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: goapp
labels:
app: goapp
spec:
replicas: 1
selector:
matchLabels:
app: goapp
tier: frontend
template:
metadata:
labels:
app: goapp
tier: frontend
spec:
containers:
- image: quickbooks2018/goapp:v1
imagePullPolicy: Always
name: goapp
ports:
- containerPort: 80
name: http
resources:
limits:
cpu: 500m
memory: 1024Mi
requests:
cpu: 500m
memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
name: goapp
labels:
app: goapp
spec:
ports:
- name: http
port: 80
targetPort: http
selector:
app: goapp
tier: frontend
type: NodePort
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: devops.cloudgeeks.ca
labels:
name: goapp
namespace: default
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
alb.ingress.kubernetes.io/healthcheck-port: traffic-port
alb.ingress.kubernetes.io/healthcheck-path: /
alb.ingress.kubernetes.io/healthcheck-interval-seconds: '15'
alb.ingress.kubernetes.io/healthcheck-timeout-seconds: '5'
alb.ingress.kubernetes.io/success-codes: '200'
alb.ingress.kubernetes.io/healthy-threshold-count: '2'
alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
spec:
rules:
- host: devops.cloudgeeks.ca
http:
paths:
- path: /
backend:
serviceName: goapp
servicePort: 80