2023-12-20 15:49:14 +08:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 创建 Namespace
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Namespace
|
|
|
|
|
metadata:
|
|
|
|
|
name: hty1024-db
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 创建 StorageClass
|
|
|
|
|
apiVersion: storage.k8s.io/v1
|
|
|
|
|
kind: StorageClass
|
|
|
|
|
metadata:
|
|
|
|
|
name: storage-local-mariadb
|
|
|
|
|
labels:
|
|
|
|
|
app.k8s.hty1024.com/env: prod
|
|
|
|
|
app.k8s.hty1024.com/type: db
|
|
|
|
|
app.k8s.hty1024.com/name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
app.k8s.hty1024.com/version: 11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
app.k8s.hty1024.com/resources: storageClass
|
|
|
|
|
provisioner: kubernetes.io/no-provisioner
|
|
|
|
|
reclaimPolicy: Retain
|
|
|
|
|
volumeBindingMode: WaitForFirstConsumer
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 创建 PersistentVolume
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: PersistentVolume
|
|
|
|
|
metadata:
|
|
|
|
|
name: hty1024-db-mariadb-pv
|
|
|
|
|
labels:
|
|
|
|
|
app.k8s.hty1024.com/env: prod
|
|
|
|
|
app.k8s.hty1024.com/type: db
|
|
|
|
|
app.k8s.hty1024.com/name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
app.k8s.hty1024.com/version: 11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
app.k8s.hty1024.com/resources: persistentVolume
|
|
|
|
|
spec:
|
|
|
|
|
capacity:
|
|
|
|
|
storage: 100Gi
|
|
|
|
|
volumeMode: Filesystem
|
|
|
|
|
accessModes:
|
|
|
|
|
- ReadWriteOnce
|
|
|
|
|
persistentVolumeReclaimPolicy: Retain
|
|
|
|
|
storageClassName: storage-local-mariadb
|
|
|
|
|
local:
|
|
|
|
|
path: /app/mariadb/data
|
|
|
|
|
nodeAffinity:
|
|
|
|
|
required:
|
|
|
|
|
nodeSelectorTerms:
|
|
|
|
|
- matchExpressions:
|
|
|
|
|
- key: node.k8s.hty1024.com/type
|
|
|
|
|
operator: In
|
|
|
|
|
values:
|
|
|
|
|
- app
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 创建 PersistentVolumeClaim
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: PersistentVolumeClaim
|
|
|
|
|
metadata:
|
|
|
|
|
name: hty1024-db-mariadb-pvc
|
|
|
|
|
namespace: hty1024-db
|
|
|
|
|
labels:
|
|
|
|
|
app.k8s.hty1024.com/env: prod
|
|
|
|
|
app.k8s.hty1024.com/type: db
|
|
|
|
|
app.k8s.hty1024.com/name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
app.k8s.hty1024.com/version: 11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
app.k8s.hty1024.com/resources: persistentVolumeClaim
|
|
|
|
|
spec:
|
|
|
|
|
resources:
|
|
|
|
|
requests:
|
|
|
|
|
storage: 100Gi
|
|
|
|
|
volumeMode: Filesystem
|
|
|
|
|
accessModes:
|
|
|
|
|
- ReadWriteOnce
|
|
|
|
|
storageClassName: storage-local-mariadb
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 创建 ConfigMap(自定义 my.cnf 文件)
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: ConfigMap
|
|
|
|
|
metadata:
|
|
|
|
|
name: hty1024-db-mariadb-cm
|
|
|
|
|
namespace: hty1024-db
|
|
|
|
|
labels:
|
|
|
|
|
app.k8s.hty1024.com/env: prod
|
|
|
|
|
app.k8s.hty1024.com/type: db
|
|
|
|
|
app.k8s.hty1024.com/name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
app.k8s.hty1024.com/version: 11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
app.k8s.hty1024.com/resources: configMap
|
|
|
|
|
data:
|
|
|
|
|
my.cnf: |
|
|
|
|
|
[mysqld]
|
|
|
|
|
max_connections = 1000
|
|
|
|
|
character-set-server = utf8mb4
|
|
|
|
|
collation-server = utf8mb4_unicode_ci
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 创建 Secret(自定义 MySQL 用户密码)
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Secret
|
|
|
|
|
metadata:
|
|
|
|
|
name: hty1024-db-mariadb-secret
|
|
|
|
|
namespace: hty1024-db
|
|
|
|
|
labels:
|
|
|
|
|
app.k8s.hty1024.com/env: prod
|
|
|
|
|
app.k8s.hty1024.com/type: db
|
|
|
|
|
app.k8s.hty1024.com/name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
app.k8s.hty1024.com/version: 11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
app.k8s.hty1024.com/resources: secret
|
|
|
|
|
type: Opaque
|
|
|
|
|
stringData:
|
|
|
|
|
root.key: |
|
|
|
|
|
12345678
|
|
|
|
|
immutable: true
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 创建 Service
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Service
|
|
|
|
|
metadata:
|
|
|
|
|
name: hty1024-db-mariadb-service
|
|
|
|
|
namespace: hty1024-db
|
|
|
|
|
labels:
|
|
|
|
|
app.k8s.hty1024.com/env: prod
|
|
|
|
|
app.k8s.hty1024.com/type: db
|
|
|
|
|
app.k8s.hty1024.com/name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
app.k8s.hty1024.com/version: 11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
app.k8s.hty1024.com/resources: service
|
|
|
|
|
spec:
|
|
|
|
|
type: ClusterIP
|
|
|
|
|
ports:
|
|
|
|
|
- port: 3306
|
|
|
|
|
targetPort: 3306
|
|
|
|
|
selector:
|
|
|
|
|
app.k8s.hty1024.com/env: prod
|
|
|
|
|
app.k8s.hty1024.com/type: db
|
|
|
|
|
app.k8s.hty1024.com/name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
app.k8s.hty1024.com/version: 11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
app.k8s.hty1024.com/resources: pod
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 创建 StatefulSet
|
|
|
|
|
apiVersion: apps/v1
|
|
|
|
|
kind: StatefulSet
|
|
|
|
|
metadata:
|
|
|
|
|
name: hty1024-db-mariadb-statefulset
|
|
|
|
|
namespace: hty1024-db
|
|
|
|
|
labels:
|
|
|
|
|
app.k8s.hty1024.com/env: prod
|
|
|
|
|
app.k8s.hty1024.com/type: db
|
|
|
|
|
app.k8s.hty1024.com/name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
app.k8s.hty1024.com/version: 11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
app.k8s.hty1024.com/resources: statefulSet
|
|
|
|
|
spec:
|
|
|
|
|
replicas: 1
|
|
|
|
|
minReadySeconds: 30
|
|
|
|
|
selector:
|
|
|
|
|
matchLabels:
|
|
|
|
|
app.k8s.hty1024.com/env: prod
|
|
|
|
|
app.k8s.hty1024.com/type: db
|
|
|
|
|
app.k8s.hty1024.com/name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
app.k8s.hty1024.com/version: 11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
app.k8s.hty1024.com/resources: pod
|
|
|
|
|
template:
|
|
|
|
|
metadata:
|
|
|
|
|
labels:
|
|
|
|
|
app.k8s.hty1024.com/env: prod
|
|
|
|
|
app.k8s.hty1024.com/type: db
|
|
|
|
|
app.k8s.hty1024.com/name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
app.k8s.hty1024.com/version: 11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
app.k8s.hty1024.com/resources: pod
|
|
|
|
|
spec:
|
|
|
|
|
terminationGracePeriodSeconds: 60
|
|
|
|
|
volumes:
|
|
|
|
|
- name: localtime
|
|
|
|
|
hostPath:
|
|
|
|
|
path: /etc/localtime
|
|
|
|
|
- name: hty1024-db-mariadb-data
|
|
|
|
|
persistentVolumeClaim:
|
|
|
|
|
claimName: hty1024-db-mariadb-pvc
|
|
|
|
|
- name: hty1024-db-mariadb-conf
|
|
|
|
|
configMap:
|
|
|
|
|
name: hty1024-db-mariadb-cm
|
|
|
|
|
items:
|
|
|
|
|
- key: my.cnf
|
|
|
|
|
path: my.cnf
|
|
|
|
|
- name: hty1024-db-mariadb-pwd
|
|
|
|
|
secret:
|
|
|
|
|
secretName: hty1024-db-mariadb-secret
|
|
|
|
|
containers:
|
|
|
|
|
- name: mariadb
|
2024-10-11 01:03:00 +08:00
|
|
|
|
image: mariadb:11.5.2
|
2023-12-20 15:49:14 +08:00
|
|
|
|
ports:
|
|
|
|
|
- name: tcp
|
|
|
|
|
containerPort: 3306
|
|
|
|
|
volumeMounts:
|
|
|
|
|
- name: localtime
|
|
|
|
|
mountPath: /etc/localtime
|
|
|
|
|
readOnly: true
|
|
|
|
|
- name: hty1024-db-mariadb-data
|
|
|
|
|
mountPath: /var/lib/mysql
|
|
|
|
|
- name: hty1024-db-mariadb-conf
|
|
|
|
|
mountPath: /etc/mysql/conf.d/
|
|
|
|
|
- name: hty1024-db-mariadb-pwd
|
|
|
|
|
mountPath: /tmp/secret-volume
|
|
|
|
|
readOnly: true
|
|
|
|
|
env:
|
|
|
|
|
- name: MYSQL_ROOT_PASSWORD_FILE
|
|
|
|
|
value: "/tmp/secret-volume/root.key"
|
|
|
|
|
nodeSelector:
|
|
|
|
|
node.k8s.hty1024.com/type: app
|
|
|
|
|
|