Skip to content

Commit 2ef26ba

Browse files
author
Tamás Hódi
committed
asd
1 parent ec3446e commit 2ef26ba

File tree

9 files changed

+95
-47
lines changed

9 files changed

+95
-47
lines changed

istio_examples/RouteRule/api/deployment.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: api-v1
55
labels:
66
app: api
7+
version: v1
78
spec:
89
replicas: 1
910
template:
@@ -20,13 +21,18 @@ spec:
2021
env:
2122
- name: VERSION
2223
value: "v1"
24+
- name: POD_NAMESPACE
25+
valueFrom:
26+
fieldRef:
27+
fieldPath: metadata.namespace
2328
---
2429
apiVersion: extensions/v1beta1
2530
kind: Deployment
2631
metadata:
2732
name: api-v2
2833
labels:
2934
app: api
35+
version: v2
3036
spec:
3137
replicas: 1
3238
template:
@@ -43,3 +49,7 @@ spec:
4349
env:
4450
- name: VERSION
4551
value: "v2"
52+
- name: POD_NAMESPACE
53+
valueFrom:
54+
fieldRef:
55+
fieldPath: metadata.namespace

istio_examples/RouteRule/api/routerule.yml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@ spec:
1212
- labels:
1313
version: v1
1414
weight: 100
15-
---
16-
apiVersion: config.istio.io/v1alpha2
17-
kind: RouteRule
18-
metadata:
19-
name: api-v2
20-
labels:
21-
app: api
22-
spec:
23-
destination:
24-
name: api
25-
precedence: 2
26-
match:
27-
request:
28-
headers:
29-
version:
30-
exact: "v2"
31-
route:
3215
- labels:
3316
version: v2
17+
weight: 0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: config.istio.io/v1alpha2
2+
kind: RouteRule
3+
metadata:
4+
name: api-v2
5+
labels:
6+
app: api
7+
spec:
8+
destination:
9+
name: api
10+
precedence: 2
11+
match:
12+
request:
13+
headers:
14+
version:
15+
exact: v2
16+
route:
17+
- labels:
18+
version: v2

istio_examples/RouteRule/api/src/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
FROM node:8.9.4-alpine
22

3+
RUN apk update
4+
RUN apk add curl
5+
RUN apk add wget
6+
37
ENV PORT 5000
48

59
COPY package.json package.json
@@ -8,4 +12,5 @@ RUN npm install
812
COPY . .
913

1014
CMD ["node", "."]
15+
1116
EXPOSE $PORT

istio_examples/RouteRule/api/src/server.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ const PORT = process.env.PORT
77
const VERSION = process.env.VERSION
88

99
app.get('/healthz', (req, res) => res.sendStatus(200))
10-
app.get('/api', (req, res) => {
11-
console.log(JSON.stringify(req.headers))
12-
res.json(`Hello World! ${VERSION} ... header version received from ui: ${req.headers.version}`)
13-
})
10+
app.get('/api', (req, res) => res.json({
11+
requestedVersion: req.headers.version,
12+
version: VERSION
13+
}))
1414

1515
app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`))
16+
17+
// TODO: remove this part
18+
setInterval(() => {
19+
require('request')(`http://api.default.svc.cluster.local/api`, (error, response, body) => {
20+
console.log(error || body)
21+
})
22+
}, 1000)

istio_examples/RouteRule/deploy.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ kubectl patch deployment ui --patch '{"spec": {"template": {"spec": {"containers
1818

1919
kubectl delete routerule -l app=api
2020
kubectl apply -f <(istioctl kube-inject -f $DIR/api/routerule.yml)
21+
22+
minikube service ui

istio_examples/RouteRule/ui/src/src/App.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ class App extends Component {
2929
render() {
3030
return (
3131
<div className="App">
32-
<button onClick={this.callAPIv1}>Call API</button>
33-
<button onClick={this.callAPIv2}>Call API with v2 header</button>
34-
<div className="data">{this.state.data}</div>
32+
<button onClick={this.callAPIv1}>Call API v1</button>
33+
<button onClick={this.callAPIv2}>Call API v2</button>
34+
<p></p>
35+
<div className="data">Requested: <b>{this.state.data.requestedVersion}</b></div>
36+
<div className="data">Response: <b>{this.state.data.version}</b></div>
3537
</div>
3638
);
3739
}

post.md

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,63 @@ http://blog.christianposta.com/istio-workshop/slides/#/agenda
44
- microservices architecture shifts complexity from the space of code design and implementation into system operations
55
- pushing the complexity from one place (software design and development) to another (operations) is just like hiding some tricky parts in somewhere else
66
- k8s lets you to automate things and solve the problems easily
7+
- istio gives the rest of the needed tools
8+
- use helm to automate things
79

810
!["MS meme by Martin Fowler"](https://martinfowler.com/bliki/images/microservicePrerequisites/sketch.png)
911

1012
# Problems
1113

14+
## Communication
15+
16+
### Direct communication
17+
- client never calls the service
18+
- use API gateway
19+
- handle auth, etc
20+
21+
### Slow communication
22+
- use cache for GET
23+
- fail fast when POST, PUT, DEL
24+
- envoy will be sidecar which can be configured somehow
25+
26+
### Security (NEED TO TEST)
27+
- kubernetes has NetworkPolicy
28+
- whats does istio give for us?
29+
- ingress/egress
30+
31+
## Improve reliability
32+
33+
### Healthz
34+
- proper timeouts
35+
36+
### Graceful start / shutdown
37+
- tear down connections in the good order (to avoid data loss)
38+
- idempotency
39+
- avoid draining connection pool -> graceful stop is important
40+
41+
### Circuit breaker & rate limitation (NEED TO TEST)
42+
- limit the impact of failures, latency spikes, and other undesirable network effects
43+
1244
## Change management
13-
- rapid provisioning of new resources
1445
- services can come and go
46+
- rapid provisioning of new resources
1547
- should be able to deploy a new service quickly
48+
- automate everything (repo, ci, deployment)
49+
- use helm to pack/deploy apps
1650

1751
### Deployment strategies
1852
- k8s deployment `.spec.strategy.type==Recreate` will kill all pods before new ones are created
1953
- 0 downtime deployment - `.spec.strategy.type==RollingUpdate` controls the process with `maxUnavailable` and `maxSurge`
2054
- blue/green
21-
- canary
22-
23-
### Bootstrapping
24-
- graceful start / shutdown (app skeleton)
25-
- automate setup (repo, ci, deployment)
26-
27-
## Communication
28-
29-
### Slow communication
30-
- use cache for GET
31-
- fail fast when POST, PUT, DEL
32-
33-
### Direct communication
34-
- client never calls the service
35-
- use API gateway
36-
37-
### + Scaling
38-
- persistent problem for MS and monoliths
39-
- HPA
40-
- heapster
41-
- rate limitation
55+
- canary (monitoring needed, allows to test in production, dark launch -> flippers)
56+
- use versioned deployments with istio request routing
4257

43-
### Monitoring
58+
### Monitoring (NEED TO TEST)
4459
- loosely-coupled services collaborating
4560
- detect serious problems
61+
- fail and detect problems fast -> write test where it is necessary
62+
- prometheus
63+
- HPA + heapster
4664

4765
### Fault injection
4866
- test resilience of your application

services/deploy.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ done
1313

1414
API_URL=$(minikube service api --url)
1515
kubectl patch deployment ui --patch '{"spec": {"template": {"spec": {"containers": [{"name": "ui", "env":[{"name": "REACT_APP_API_URL", "value": "'$API_URL'"}]}]}}}}'
16+
17+
minikube service ui

0 commit comments

Comments
 (0)