Skip to content

Commit be88b97

Browse files
author
Mano Marks
authored
Merge pull request dockersamples#107 from lucj/master
Add k8s specifications
2 parents e3eb2db + 0fd383c commit be88b97

10 files changed

+155
-1
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ Once you have your swarm, in this directory run:
2121
docker stack deploy --compose-file docker-stack.yml vote
2222
```
2323

24+
Run the app in Kubernetes
25+
-------------------------
26+
27+
The folder k8s-specifications contains the yaml specifications of the Voting App's services.
28+
29+
Run the following command to create the deployments and services objects:
30+
```
31+
$ kubectl create -f k8s-specifications/
32+
deployment "db" created
33+
service "db" created
34+
deployment "redis" created
35+
service "redis" created
36+
deployment "result" created
37+
service "result" created
38+
deployment "vote" created
39+
service "vote" created
40+
deployment "worker" created
41+
```
42+
43+
The vote interface is then available on port 31000 on each host of the cluster, the result one is available on port 31001.
44+
2445
Architecture
2546
-----
2647

@@ -36,4 +57,4 @@ Architecture
3657
Note
3758
----
3859

39-
The voting application only accepts one vote per client. It does not register votes if a vote has already been submitted from a client.
60+
The voting application only accepts one vote per client. It does not register votes if a vote has already been submitted from a client.

k8s-specifications/db-deployment.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: db
5+
spec:
6+
replicas: 1
7+
template:
8+
metadata:
9+
labels:
10+
app: db
11+
spec:
12+
containers:
13+
- image: postgres:9.4
14+
name: db
15+
volumeMounts:
16+
- mountPath: /var/lib/postgresql/data
17+
name: db-data
18+
volumes:
19+
- name: db-data
20+
emptyDir: {}

k8s-specifications/db-service.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: db
5+
spec:
6+
type: ClusterIP
7+
ports:
8+
- port: 5432
9+
targetPort: 5432
10+
selector:
11+
app: db
12+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: redis
5+
spec:
6+
replicas: 1
7+
template:
8+
metadata:
9+
labels:
10+
app: redis
11+
spec:
12+
containers:
13+
- image: redis:alpine
14+
name: redis
15+
volumeMounts:
16+
- mountPath: /data
17+
name: redis-data
18+
volumes:
19+
- name: redis-data
20+
emptyDir: {}

k8s-specifications/redis-service.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: redis
5+
spec:
6+
type: ClusterIP
7+
ports:
8+
- port: 6379
9+
targetPort: 6379
10+
selector:
11+
app: redis
12+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: result
5+
spec:
6+
replicas: 1
7+
template:
8+
metadata:
9+
labels:
10+
app: result
11+
spec:
12+
containers:
13+
- image: dockersamples/examplevotingapp_result:before
14+
name: result
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: result
5+
spec:
6+
type: NodePort
7+
ports:
8+
- name: "result-service"
9+
port: 5001
10+
targetPort: 80
11+
nodePort: 31001
12+
selector:
13+
app: result
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: vote
5+
spec:
6+
replicas: 1
7+
template:
8+
metadata:
9+
labels:
10+
app: vote
11+
spec:
12+
containers:
13+
- image: dockersamples/examplevotingapp_vote:before
14+
name: vote

k8s-specifications/vote-service.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: vote
5+
spec:
6+
type: NodePort
7+
ports:
8+
- name: "vote-service"
9+
port: 5000
10+
targetPort: 80
11+
nodePort: 31000
12+
selector:
13+
app: vote
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: worker
5+
spec:
6+
replicas: 1
7+
template:
8+
metadata:
9+
labels:
10+
app: worker
11+
spec:
12+
containers:
13+
- image: dockersamples/examplevotingapp_worker
14+
name: worker

0 commit comments

Comments
 (0)