-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
bonus-task-solution.yaml
204 lines (204 loc) · 4.26 KB
/
bonus-task-solution.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
---
apiVersion: v1
kind: Secret
data:
mysql_root_password: TXlzcWw1LjZQYXNzd29yZA==
metadata:
name: mysql-password
namespace: cka
type: Opaque
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-mysql
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
persistentVolumeReclaimPolicy: Recycle
accessModes:
- ReadWriteOnce
hostPath:
path: "/data_mysql"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-mysql
namespace: cka
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: mysql
name: mysql
namespace: cka
spec:
replicas: 1
selector:
matchLabels:
app: mysql
serviceName: mysql
template:
metadata:
labels:
app: mysql
spec:
securityContext:
runAsUser: 65534
runAsGroup: 65534
volumes:
- name: pv-mysql
persistentVolumeClaim:
claimName: pvc-mysql
initContainers:
- name: fix-permissions
image: busybox:1.35
command: ["sh", "-c", "chown -R 65534:65534 /var/lib/mysql"]
securityContext:
runAsUser: 0
volumeMounts:
- mountPath: "/var/lib/mysql"
name: pv-mysql
containers:
- image: mysql:5.6
name: mysql
volumeMounts:
- mountPath: "/var/lib/mysql"
name: pv-mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-password
key: mysql_root_password
---
apiVersion: v1
kind: Service
metadata:
labels:
app: mysql
name: mysql
namespace: cka
spec:
ports:
- name: "3306"
port: 3306
protocol: TCP
targetPort: 3306
selector:
app: mysql
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: wordpress
name: wordpress
namespace: cka
spec:
replicas: 3
selector:
matchLabels:
app: wordpress
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
spec:
# See https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#always-co-located-in-the-same-node
# The deployment has PodAntiAffinity configured to ensure
# the scheduler does not co-locate replicas on a single node.
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- wordpress
topologyKey: "kubernetes.io/hostname"
# See https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/#taint-based-evictions
# The following toleration "matches" the taint on the control-plane node, therefore
# a pod with this toleration would be able to schedule onto control-plane.
tolerations:
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
containers:
- image: wordpress:5.6-apache
name: wordpress
env:
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-password
key: mysql_root_password
- name: WORDPRESS_DB_HOST
value: mysql
- name: WORDPRESS_DB_USER
value: root
resources:
requests:
cpu: 10m
memory: 64Mi
livenessProbe:
httpGet:
path: /readme.html
port: 80
periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
labels:
app: wordpress
name: wordpress
namespace: cka
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
nodePort: 31234
selector:
app: wordpress
type: NodePort
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: netpol-mysql
namespace: cka
spec:
podSelector:
matchLabels:
app: mysql
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
app: wordpress
ports:
- protocol: TCP
port: 3306
egress:
- to:
- ipBlock:
cidr: 10.0.0.0/8