-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-writing servies.slide
172 lines (108 loc) · 3.13 KB
/
02-writing servies.slide
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Production-ready microservices with Go and Kubernetes
#ContainerDays
09:00 18 Jun 2018
Elena Grahovac
Senior Go Developer, DCMN
@webdeva
* Production readiness
* Four-layer model of the microservice ecosystem
.image production-readiness.png 450 _
.caption by Susan J. Fowler, Production-Ready Microservices
* Production readiness and Kubernetes
.image production-readiness-kubernetes.png 450 _
* Standartization and requirements
* Standartization
- stability
- reliability
- scalability
- security
- fault tolerance
- observability (logging, metrics, tracing)
- documentation
- some specific requirements
* Source code lifecycle
.image source-code-lifecycle.png 450 _
* Source code lifecycle at the workshop
.image source-code-lifecycle-workshop.png 450 _
* What we should acheive
- Templated Makefile and pipelines
- <demo of CI/CD>
* The Twelve-Factor App
.link https://12factor.net
- codebase revision control
- configuration
- service-based model
- stateless
- startup and shutdown
- logs
- stages and pipelines: build, test, release, run
- staging and prod similarity
* Codebase
* Codebase
- branch model
- events and triggers
* Events and triggers
events:
- commit
- push
- pull request
- merge
triggers:
- run tests and security checks
- build and push image
- start release process
- create tags
* Step 1. Prepare a repo
- create a repo on GitHub
- go get it
- create a branch
* Step 2. Prepare linters and pre-commit hooks (optional)
- gometalinter:
.link https://github.com/alecthomas/gometalinter
- pre-commit:
.link https://pre-commit.com
.link https://github.com/troian/pre-commit-golang
- on-save actions / file watchers:
.link https://code.visualstudio.com/docs/languages/go
.link https://www.jetbrains.com/help/go/settings-tools-file-watchers.html
* Step 3. Write the simplest service
* Step 4. Add a logger
* Step 5. Add a router
- download a dependency: go get -u -v github.com/gorilla/mux
* Step 6. Move handlers to a separated package
* Step 7. Write tests
* Step 8. Configuration
* Define CI/CD pipeline
* Possible deployment pipeline
.image cicd.png 350 _
* Deployment pipeline for the workshop
.image workshop-process.png 450 _
* Step 9. Makefile
* Step 10. Versioning
* Step 11. Health checks
* Step 12. Graceful shutdown
* If you use Windows it might be a little bit tricky
* Step 13. Vendoring
- install go dep
.link https://github.com/golang/dep
* Step 14. Dockerfile
1. FROM scratch
- As small as it possible
- As few possibilities as we need
2. CGO_ENABLED=0
- Disabling cgo to avoid operations with C libraries (the container doesn't have these libraries)
- About cgo:
.link https://dave.cheney.net/2016/01/18/cgo-is-not-go
* Step 14. Dockerfile
3. Certification authority
- Go expects the root CA certificates from /etc/ssl/certs/ca-certificates.crt, so we need to copy this file
- Example:
generate certificates:
.link https://github.com/k8s-community/ui/blob/0.5.0/Makefile#L47
copy cretificates:
.link https://github.com/k8s-community/ui/blob/0.5.0/Dockerfile#L21
4. USER
- "Running with Scissors" by Liz Rice:
.link https://youtu.be/ltrV-Qmh3oY
* Step 15. Prepare Kubernetes configuration