-
Notifications
You must be signed in to change notification settings - Fork 3
/
statefulset.py
68 lines (63 loc) · 3.01 KB
/
statefulset.py
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
from constructs import Construct, Node
from imports import k8s
class StateFulSet(Construct):
def __init__(self, scope: Construct, id: str):
super().__init__(scope, id)
msql_name = 'msql'
msql_label = {'ss': msql_name}
k8s.KubeStatefulSet(
self, "MsqlStatefulSet",
metadata=k8s.ObjectMeta(name=msql_name),
spec=k8s.StatefulSetSpec(
replicas=1,
selector=k8s.LabelSelector(match_labels=msql_label),
service_name=msql_name,
template=k8s.PodTemplateSpec(
metadata=k8s.ObjectMeta(labels=msql_label, name=msql_name),
spec=k8s.PodSpec(
containers=[k8s.Container(
name=msql_name,
image="openshift/mysql-55-centos7",
ports=[k8s.ContainerPort(container_port=3306)],
env=[
k8s.EnvVar(name='MYSQL_ROOT_PASSWORD', value='yourpassword'),
k8s.EnvVar(name='MYSQL_USER', value='wp_user'),
k8s.EnvVar(name='MYSQL_PASSWORD', value='wp_pass'),
k8s.EnvVar(name='MYSQL_DATABASE', value='wp_db'),
],
volume_mounts=[k8s.VolumeMount(mount_path='/var/lib/mysql/data',
name='mysql-persistent-storage')]
)]
)
),
volume_claim_templates=[
k8s.KubePersistentVolumeClaimProps(
metadata=k8s.ObjectMeta(name="mysql-persistent-storage"),
spec=k8s.PersistentVolumeClaimSpec(
access_modes=["ReadWriteOnce"],
resources=k8s.ResourceRequirements(requests={"storage": k8s.Quantity.from_string("2Gi")})
)
)
]
)
)
k8s.KubePersistentVolume(
self, "STSPersistentVolume1",
metadata=k8s.ObjectMeta(name='nfs-0001'),
spec=k8s.PersistentVolumeSpec(
access_modes=['ReadWriteOnce', 'ReadWriteMany'],
capacity={'storage': k8s.Quantity.from_string('2Gi')},
nfs=k8s.NfsVolumeSource(path='/exports/data-0001', server='192.168.121.210'),
persistent_volume_reclaim_policy='Retain'
)
)
k8s.KubePersistentVolume(
self, "STSPersistentVolume2",
metadata=k8s.ObjectMeta(name='nfs-0002'),
spec=k8s.PersistentVolumeSpec(
access_modes=['ReadWriteOnce', 'ReadWriteMany'],
capacity={'storage': k8s.Quantity.from_string('5Gi')},
nfs=k8s.NfsVolumeSource(path='/exports/data-0002', server='192.168.121.210'),
persistent_volume_reclaim_policy='Retain'
)
)