Skip to content

Commit c354d84

Browse files
committed
k8s-deployment
1 parent ff525ce commit c354d84

File tree

4 files changed

+100
-88
lines changed

4 files changed

+100
-88
lines changed

deployments/kustomization.yaml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ secretGenerator:
33
- name: mysql-root-pass
44
literals:
55
- password=R00t
6-
- name: mysql-user
6+
- name: mysql-user-pass
77
literals:
8-
- username=callicoder
9-
- name: mysql-pass
10-
literals:
11-
- password=c@ll1c0d3r
12-
- name: mysql-db
13-
literals:
14-
- database=polls
15-
- name: mysql-url
8+
- username=callicoder
9+
- password=c@ll1c0d3r
10+
- name: mysql-db-url
1611
literals:
12+
- database=polls
1713
- url=jdbc:mysql://polling-app-mysql:3306/polls?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
1814
resources:
1915
- mysql-deployment.yaml
2016
- polling-app-server.yaml
21-
- polling-app-client.yaml
17+
- polling-app-client.yaml

deployments/mysql-deployment.yaml

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,97 @@
11
apiVersion: v1
2-
kind: Service
2+
kind: PersistentVolume # Create a PersistentVolume
33
metadata:
4-
name: polling-app-mysql
4+
name: mysql-pv
55
labels:
6-
app: polling-app
6+
type: local
77
spec:
8-
ports:
9-
- port: 3306
10-
selector:
11-
app: polling-app
12-
tier: mysql
13-
clusterIP: None
14-
---
8+
storageClassName: standard # The class of storage. A PV Claim requesting the same storageClass can be bound to this volume.
9+
capacity:
10+
storage: 250Mi
11+
accessModes:
12+
- ReadWriteOnce
13+
hostPath: # hostPath PersistentVolume is used for development and testing. It uses a file/directory on the Node to emulate network-attached storage
14+
path: "/mnt/data"
15+
persistentVolumeReclaimPolicy: Retain # Retain the PersistentVolume even after PersistentVolumeClaim is deleted. The volume is considered “released”. But it is not yet available for another claim because the previous claimant’s data remains on the volume.
16+
---
1517
apiVersion: v1
16-
kind: PersistentVolumeClaim
17-
metadata:
18+
kind: PersistentVolumeClaim # Create a PersistentVolumeClaim to request a PersistentVolume storage
19+
metadata: # Claim name and labels
1820
name: mysql-pv-claim
1921
labels:
2022
app: polling-app
21-
spec:
23+
spec: # Access mode and resource limits
24+
storageClassName: standard # Request a certain storage class
2225
accessModes:
23-
- ReadWriteOnce
26+
- ReadWriteOnce # ReadWriteOnce means the volume can be mounted as read-write by a single Node
2427
resources:
2528
requests:
2629
storage: 250Mi
2730
---
28-
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
29-
kind: Deployment
31+
apiVersion: v1 # API version
32+
kind: Service # Type of kubernetes resource
3033
metadata:
31-
name: polling-app-mysql
32-
labels:
34+
name: polling-app-mysql # Name of the resource
35+
labels: # Labels that will be applied to the resource
36+
app: polling-app
37+
spec:
38+
ports:
39+
- port: 3306
40+
selector: # Selects any Pod with labels `app=polling-app,tier=mysql`
41+
app: polling-app
42+
tier: mysql
43+
clusterIP: None
44+
---
45+
apiVersion: apps/v1
46+
kind: Deployment # Type of the kubernetes resource
47+
metadata:
48+
name: polling-app-mysql # Name of the deployment
49+
labels: # Labels applied to this deployment
3350
app: polling-app
3451
spec:
3552
selector:
36-
matchLabels:
53+
matchLabels: # This deployment applies to the Pods matching the specified labels
3754
app: polling-app
3855
tier: mysql
3956
strategy:
4057
type: Recreate
41-
template:
58+
template: # Template for the Pods in this deployment
4259
metadata:
43-
labels:
60+
labels: # Labels to be applied to the Pods in this deployment
4461
app: polling-app
4562
tier: mysql
46-
spec:
63+
spec: # The spec for the containers that will be run inside the Pods in this deployment
4764
containers:
48-
- image: mysql:5.6
65+
- image: mysql:5.6 # The container image
4966
name: mysql
50-
env:
51-
- name: MYSQL_ROOT_PASSWORD
52-
valueFrom:
67+
env: # Environment variables passed to the container
68+
- name: MYSQL_ROOT_PASSWORD
69+
valueFrom: # Read environment variables from kubernetes secrets
5370
secretKeyRef:
5471
name: mysql-root-pass
5572
key: password
5673
- name: MYSQL_DATABASE
5774
valueFrom:
5875
secretKeyRef:
59-
name: mysql-db
76+
name: mysql-db-url
6077
key: database
6178
- name: MYSQL_USER
6279
valueFrom:
6380
secretKeyRef:
64-
name: mysql-user
81+
name: mysql-user-pass
6582
key: username
6683
- name: MYSQL_PASSWORD
6784
valueFrom:
6885
secretKeyRef:
69-
name: mysql-pass
86+
name: mysql-user-pass
7087
key: password
7188
ports:
72-
- containerPort: 3306
89+
- containerPort: 3306 # The port that the container exposes
7390
name: mysql
7491
volumeMounts:
75-
- name: mysql-persistent-storage
92+
- name: mysql-persistent-storage # This name should match the name specified in `volumes.name`
7693
mountPath: /var/lib/mysql
77-
volumes:
94+
volumes: # A PersistentVolume is mounted as a volume to the Pod
7895
- name: mysql-persistent-storage
7996
persistentVolumeClaim:
80-
claimName: mysql-pv-claim
97+
claimName: mysql-pv-claim

deployments/polling-app-client.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
apiVersion: apps/v1
2-
kind: Deployment
1+
apiVersion: apps/v1 # API version
2+
kind: Deployment # Type of kubernetes resource
33
metadata:
4-
name: polling-app-client
4+
name: polling-app-client # Name of the kubernetes resource
55
spec:
6-
replicas: 1
7-
selector:
8-
matchLabels:
9-
name: polling-app-client
10-
template:
6+
replicas: 1 # No of replicas/pods to run
7+
selector:
8+
matchLabels: # This deployment applies to Pods matching the specified labels
9+
app: polling-app-client
10+
template: # Template for creating the Pods in this deployment
1111
metadata:
12-
labels:
13-
name: polling-app-client
14-
spec:
12+
labels: # Labels that will be applied to all the Pods in this deployment
13+
app: polling-app-client
14+
spec: # Spec for the containers that will run inside the Pods
1515
containers:
1616
- name: polling-app-client
1717
image: callicoder/polling-app-client:1.0.0
1818
imagePullPolicy: IfNotPresent
1919
ports:
2020
- name: http
21-
containerPort: 80
21+
containerPort: 80 # Should match the Port that the container listens on
2222
resources:
2323
limits:
2424
cpu: 0.2
2525
memory: "10Mi"
2626
---
27-
apiVersion: v1
28-
kind: Service
27+
apiVersion: v1 # API version
28+
kind: Service # Type of kubernetes resource
2929
metadata:
30-
name: polling-app-client
30+
name: polling-app-client # Name of the kubernetes resource
3131
spec:
32-
type: NodePort
32+
type: NodePort # Exposes the service by opening a port on each node
3333
selector:
34-
name: polling-app-client
35-
ports:
34+
app: polling-app-client # Any Pod matching the label `app=polling-app-client` will be picked up by this service
35+
ports: # Forward incoming connections on port 80 to the target port 80 in the Pod
3636
- name: http
3737
port: 80
3838
targetPort: 80

deployments/polling-app-server.yaml

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,58 @@
1-
---
2-
apiVersion: apps/v1
3-
kind: Deployment
1+
apiVersion: apps/v1 # API version
2+
kind: Deployment # Type of kubernetes resource
43
metadata:
5-
name: polling-app-server
6-
labels:
4+
name: polling-app-server # Name of the kubernetes resource
5+
labels: # Labels that will be applied to this resource
76
app: polling-app-server
87
spec:
9-
replicas: 1
8+
replicas: 1 # No. of replicas/pods to run in this deployment
109
selector:
11-
matchLabels:
10+
matchLabels: # The deployment applies to any pods mayching the specified labels
1211
app: polling-app-server
13-
template:
12+
template: # Template for creating the pods in this deployment
1413
metadata:
15-
labels:
14+
labels: # Labels that will be applied to each Pod in this deployment
1615
app: polling-app-server
17-
spec:
16+
spec: # Spec for the containers that will be run in the Pods
1817
containers:
1918
- name: polling-app-server
2019
image: callicoder/polling-app-server:1.0.0
2120
imagePullPolicy: IfNotPresent
2221
ports:
2322
- name: http
24-
containerPort: 8080
23+
containerPort: 8080 # The port that the container exposes
2524
resources:
2625
limits:
2726
cpu: 0.2
28-
memory: "256Mi"
29-
env:
30-
- name: SPRING_DATASOURCE_USERNAME
31-
valueFrom:
27+
memory: "200Mi"
28+
env: # Environment variables supplied to the Pod
29+
- name: SPRING_DATASOURCE_USERNAME # Name of the environment variable
30+
valueFrom: # Get the value of environment variable from kubernetes secrets
3231
secretKeyRef:
33-
name: mysql-user
32+
name: mysql-user-pass
3433
key: username
3534
- name: SPRING_DATASOURCE_PASSWORD
3635
valueFrom:
3736
secretKeyRef:
38-
name: mysql-pass
37+
name: mysql-user-pass
3938
key: password
4039
- name: SPRING_DATASOURCE_URL
4140
valueFrom:
4241
secretKeyRef:
43-
name: mysql-url
42+
name: mysql-db-url
4443
key: url
4544
---
46-
apiVersion: v1
47-
kind: Service
48-
metadata:
49-
name: polling-app-server
50-
labels:
45+
apiVersion: v1 # API version
46+
kind: Service # Type of the kubernetes resource
47+
metadata:
48+
name: polling-app-server # Name of the kubernetes resource
49+
labels: # Labels that will be applied to this resource
5150
app: polling-app-server
52-
spec:
53-
type: NodePort
51+
spec:
52+
type: NodePort # The service will be exposed by opening a Port on each node and proxying it.
5453
selector:
55-
app: polling-app-server
56-
ports:
54+
app: polling-app-server # The service exposes Pods with label `app=polling-app-server`
55+
ports: # Forward incoming connections on port 8080 to the target port 8080
5756
- name: http
5857
port: 8080
5958
targetPort: 8080

0 commit comments

Comments
 (0)