Skip to content

Commit b872cfd

Browse files
committed
k8s additions
1 parent c3b192a commit b872cfd

File tree

6 files changed

+72
-19
lines changed

6 files changed

+72
-19
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Let's build the front end:
9595

9696
To deploy locally, we need to link to `demo-mysql` and add environmental variables with `-e`:
9797

98-
docker run --name my-first-app -d -p 8080:8080 --link demo-mysql:remote-mysql -e MYSQL_USER=root -e MYSQL_PASS=<PASSWORD> webapp
98+
docker run --name my-first-app -d -p 8080:8080 --link demo-mysql:remote-mysql -e MYSQL_USER=root -e MYSQL_PASS=<PASSWORD> -e MYSQL_SERVER=remote-mysql webapp
9999

100100
Now you can access in your browser at [http://localhost:8080](http://localhost:8080)
101101

@@ -139,6 +139,6 @@ In this case you need to expose 8080 to 80 and use the correct image name
139139
docker run --name my-first-app -d -p 80:8080 --link demo-mysql:remote-mysql -e MYSQL_USER=root -e MYSQL_PASS=<PASSWORD> mgckind/my-demo-app:1.0.0
140140

141141

142-
## Deployment -- the less simple way but still easy
142+
## Deployment on Kubernetes -- the less simple way but still easy
143143

144-
Using [Kubernetes](https://kubernetes.io/), note that GKE and AWS provide Kubernetes cluster as a Service.
144+
Using [Kubernetes](https://kubernetes.io/), note that GKE and AWS provide Kubernetes cluster as a Service. See [folder](kubernetes/)

kubernetes/demo-app-ing.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ metadata:
44
name: demo-app
55
annotations:
66
#ingress.kubernetes.io/ssl-redirect: "false"
7-
kubernetes.io/ingress.class: "nginx"
7+
kubernetes.io/ingress.class: "deslabs"
88
spec:
99
rules:
1010
- http:
1111
paths:
1212
- path: /demo
1313
backend:
1414
serviceName: demo-app
15-
servicePort: 8080
15+
servicePort: 8081
1616

kubernetes/mysql.yaml

+50-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,42 @@
11
apiVersion: v1
2+
kind: Secret
3+
data:
4+
passwd: bGluZWE=
5+
metadata:
6+
name: mysql-secret
7+
namespace: default
8+
type: Opaque
9+
---
10+
kind: PersistentVolume
11+
apiVersion: v1
12+
metadata:
13+
name: remote-mysql
14+
spec:
15+
storageClassName: manual
16+
capacity:
17+
storage: 30Gi
18+
accessModes:
19+
- ReadWriteMany
20+
hostPath:
21+
path: /home/matias/kubedata/external/demo_mysql
22+
23+
---
24+
kind: PersistentVolumeClaim
25+
apiVersion: v1
26+
metadata:
27+
name: remote-mysql
28+
namespace: default
29+
spec:
30+
storageClassName: manual
31+
accessModes:
32+
- ReadWriteMany
33+
resources:
34+
requests:
35+
storage: 30Gi
36+
volumeName: remote-mysql
37+
38+
---
39+
apiVersion: v1
240
kind: Service
341
metadata:
442
name: remote-mysql
@@ -9,13 +47,14 @@ spec:
947
selector:
1048
app: mysql
1149
---
12-
apiVersion: apps/v1beta1
50+
apiVersion: apps/v1
1351
kind: Deployment
1452
metadata:
1553
name: mysql
1654
spec:
17-
strategy:
18-
type: Recreate
55+
selector:
56+
matchLabels:
57+
app: mysql
1958
template:
2059
metadata:
2160
labels:
@@ -34,3 +73,11 @@ spec:
3473
ports:
3574
- containerPort: 3306
3675
name: mysql
76+
volumeMounts:
77+
- name: mysql-persistent-storage
78+
mountPath: /var/lib/mysql
79+
volumes:
80+
- name: mysql-persistent-storage
81+
persistentVolumeClaim:
82+
claimName: remote-mysql
83+

kubernetes/website.yaml

+11-6
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@ metadata:
55
spec:
66
type: NodePort
77
ports:
8-
- port: 8080
8+
- port: 8081
99
selector:
1010
app: demo-app
1111
---
12-
apiVersion: apps/v1beta1
12+
apiVersion: apps/v1
1313
kind: Deployment
1414
metadata:
1515
name: demo-app
1616
spec:
17-
strategy:
18-
type: Recreate
17+
selector:
18+
matchLabels:
19+
app: demo-app
1920
template:
2021
metadata:
2122
labels:
2223
app: demo-app
2324
spec:
2425
containers:
25-
- image: mgckind/my-demo-app:kube-1.0
26+
- image: mgckind/demo-app-pie:1.1
2627
imagePullPolicy: IfNotPresent
2728
name: demo-app
2829
env:
@@ -33,6 +34,10 @@ spec:
3334
key: passwd
3435
- name: MYSQL_USER
3536
value: "root" ## <----
37+
- name: MYSQL_SERVER
38+
value: "remote-mysql"
39+
- name: MYSQL_PORT
40+
value: "3306"
3641
ports:
37-
- containerPort: 8080
42+
- containerPort: 8081
3843
name: demo-app

webpage/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RUN pip install --no-cache-dir tornado gviz_api mysqlclient
55
# Create a demo folder
66
RUN mkdir demo
77
# Copy all the files inside the demo folder
8-
COPY . /demo
8+
ADD . /demo
99
# Change to /demo at run-time
1010
WORKDIR /demo
1111
# Execute this command when running the container, can be override

webpage/main.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111
# Configuration parameters to connect to MYSQL
1212
CONF={}
13-
CONF['host'] = 'remote-mysql' #'127.0.0.1'
14-
CONF['port'] = int('3306')
13+
CONF['host'] = os.environ['MYSQL_SERVER'] # 'remote-mysql' #'127.0.0.1'
14+
CONF['port'] = int('3306') # 3306
1515
CONF['user'] = os.environ['MYSQL_USER']
1616
CONF['passwd'] = os.environ['MYSQL_PASS']
1717

1818
# schema for google pie chart
1919
schema = {"topic": ("string", "Topic"), "times": ("number", "Times")}
2020

21-
# will run by default on port 8080
22-
define("port", default=8080, help="run on the given port", type=int)
21+
# will run by default on port 8081
22+
define("port", default=8081, help="run on the given port", type=int)
2323

2424
def init_table():
2525
"""
@@ -78,6 +78,7 @@ def get_data():
7878

7979
class MainHandler(tornado.web.RequestHandler):
8080
def get(self):
81+
init_table()
8182
self.render("main.html", hostname=platform.node())
8283

8384
class GetDataHandler(tornado.web.RequestHandler):

0 commit comments

Comments
 (0)