Skip to content

Commit c1a72f2

Browse files
authored
Merge pull request #368 from dmitchsplunk/main
Updates to profiling workshop
2 parents 6f5e8e4 + 99700d3 commit c1a72f2

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

workshop/profiling/2-deploy-mysql.sh

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,8 @@ while [[ $(kubectl get pods -l app=mysql -o 'jsonpath={..status.conditions[?(@.t
2929
sleep 1
3030
done
3131

32-
echo Capturing the pod name
33-
export POD_NAME=`kubectl get pod -l app=mysql -o name --no-headers=true`
34-
35-
echo Copying sample data and scripts to the pod
36-
# Copy the sample data files to the database pod for import
37-
kubectl cp ./mysql/users.csv ${POD_NAME:4}:/var/lib/mysql-files/users.csv
38-
kubectl cp ./mysql/organizations.csv ${POD_NAME:4}:/var/lib/mysql-files/organizations.csv
39-
kubectl cp ./mysql/populate_db.txt ${POD_NAME:4}:/tmp/populate_db.txt
40-
kubectl cp ./mysql/populate_db.sh ${POD_NAME:4}:/tmp/populate_db.sh
41-
42-
echo Waiting for the database to be ready
43-
while ! kubectl exec -it ${POD_NAME:4} -- mysqladmin ping -p"$MYSQL_ROOT_PASSWORD" --silent; do
44-
sleep 5
45-
done
46-
47-
# added extra sleep as issues occur when we attempt
48-
# to connect to the database too quickly
49-
sleep 5
50-
51-
echo Creating tables and application data
52-
kubectl exec -it ${POD_NAME:4} -- /tmp/populate_db.sh
32+
echo Creating a config map for the sample data
33+
kubectl create configmap mysql-data --from-file=./mysql/users.csv --from-file=./mysql/organizations.csv --from-file=./mysql/populate_db.txt
5334

5435
echo ""
5536
echo Deployed the MySQL database

workshop/profiling/doorgame/doorgame.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ spec:
1414
tolerations:
1515
nodeSelector:
1616
terminationGracePeriodSeconds: 5
17+
# use init containers to first ensure the MySQL database is available, then populate it with
18+
# data required by the application
19+
initContainers:
20+
- name: wait-for-mysql
21+
image: busybox:1.31
22+
command: [ 'sh', '-c', 'echo -e "Checking for the availability of the MySQL database"; while ! nc -z mysql 3306; do sleep 1; printf "-"; done; echo -e " >> MySQL database is ready";' ]
23+
- name: populate-app-data
24+
image: mysql:8.3.0
25+
env:
26+
- name: MYSQL_ROOT_PASSWORD
27+
valueFrom:
28+
secretKeyRef:
29+
name: db-user-pass
30+
key: MYSQL_ROOT_PASSWORD
31+
volumeMounts:
32+
- name: mysql-data
33+
mountPath: /tmp
34+
command: [ 'sh', '-c', 'echo -e "Populating the application data"; mysql --host=mysql.default.svc.cluster.local --password=''$(MYSQL_ROOT_PASSWORD)'' --local-infile=1 < /tmp/populate_db.txt' ]
1735
containers:
1836
- name: doorgame
1937
image: docker.io/library/doorgame:latest
@@ -49,6 +67,17 @@ spec:
4967
limits:
5068
cpu: 300m
5169
memory: 4096Mi
70+
volumes:
71+
- name: mysql-data
72+
configMap:
73+
name: mysql-data
74+
items:
75+
- key: users.csv
76+
path: users.csv
77+
- key: organizations.csv
78+
path: organizations.csv
79+
- key: populate_db.txt
80+
path: populate_db.txt
5281
---
5382
apiVersion: v1
5483
kind: Service
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
SET GLOBAL local_infile=1;
2+
13
CREATE DATABASE IF NOT EXISTS DoorGameDB;
24
USE DoorGameDB;
35

@@ -7,6 +9,6 @@ CREATE TABLE Users (UserId VARCHAR(20), FirstName VARCHAR(100), LastName VARCHAR
79
DROP TABLE IF EXISTS Organizations;
810
CREATE TABLE Organizations (OrgId VARCHAR(256), Name VARCHAR(256), Country VARCHAR(256), Founded INT, NumEmployees INT);
911

10-
LOAD DATA INFILE '/var/lib/mysql-files/users.csv' INTO TABLE DoorGameDB.Users FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS;
12+
LOAD DATA LOCAL INFILE '/tmp/users.csv' INTO TABLE DoorGameDB.Users FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS;
1113

12-
LOAD DATA INFILE '/var/lib/mysql-files/organizations.csv' INTO TABLE DoorGameDB.Organizations FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;
14+
LOAD DATA LOCAL INFILE '/tmp/organizations.csv' INTO TABLE DoorGameDB.Organizations FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;

0 commit comments

Comments
 (0)