forked from dennyzhang/challenges-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 2
/
kubernetes.yaml
136 lines (136 loc) · 3.51 KB
/
kubernetes.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
################################################################################
# Create volume for DB server
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_atomic_host/7/html/getting_started_with_kubernetes/get_started_provisioning_storage_in_kubernetes
# https://kubernetes.io/docs/getting-started-guides/minikube/#configuring-kubernetes
# https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims
kind: PersistentVolume
apiVersion: v1
metadata:
name: mysql001
labels:
type: local
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/data/mysql001"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mysql001-1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
################################################################################
---
# https://github.com/kubernetes/examples/blob/master/guestbook/all-in-one/guestbook-all-in-one.yaml
# https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: dbserver-deployment
labels:
app: dbserver
spec:
replicas: 1
selector:
matchLabels:
app: dbserver
template:
metadata:
labels:
app: dbserver
spec:
containers:
- name: dbserver
image: mariadb
# https://kubernetes.io/docs/concepts/policy/resource-quotas/
resources:
requests:
cpu: 400m
memory: 600Mi
ports:
- containerPort: 3306
env:
# https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysecret
key: mysql_root_password
# https://kubernetes.io/docs/concepts/storage/persistent-volumes/#claims-as-volumes
volumeMounts:
- mountPath: "/var/lib/mysql"
name: mysqlstorage
volumes:
- name: mysqlstorage
persistentVolumeClaim:
claimName: mysql001-1
---
# Use services to export my app
# https://kubernetes.io/docs/concepts/services-networking/service/
apiVersion: v1
kind: Service
metadata:
name: my-dbserver-service
labels:
app: dbserver
spec:
type: NodePort
ports:
- port: 3306
targetPort: 3306
selector:
app: dbserver
################################################################################
---
# https://github.com/kubernetes/examples/blob/master/guestbook/all-in-one/guestbook-all-in-one.yaml
# https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: dbclient-deployment
labels:
app: dbclient
spec:
replicas: 2
selector:
matchLabels:
app: dbclient
template:
metadata:
labels:
app: dbclient
spec:
containers:
- name: dbclient
# Docker Image: https://hub.docker.com/_/adminer/
image: adminer
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 8080
---
# Use services to export my app
# https://kubernetes.io/docs/concepts/services-networking/service/
apiVersion: v1
kind: Service
metadata:
name: my-dbclient-service
labels:
app: dbclient
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
selector:
app: dbclient