K8S 使用NFS存储 动态创建 PVC/PV 并通过 Statefulset 部署 MySQL
1、apiVersion: v1kind: ConfigMapmetadata:name: mysql-configdata:MYSQL_ROOT_PASSWORD: '123456'---apiVersion: apps/v1kind: StatefulSetmetadata:name: mysqlspec:replicas: 1serviceName: mysql-serviceselecto
·
K8S 使用NFS存储 动态创建 PVC
1、创建
vim statefulset-mysql.yaml
# MySQL 配置
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
data:
MYSQL_ROOT_PASSWORD: '123456'
---
# MySQL 容器
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
spec:
replicas: 1
serviceName: mysql-service
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
ports:
- name: mysql
containerPort: 3306
protocol: TCP
envFrom:
- configMapRef:
name: mysql-config
resources:
requests:
cpu: 1
memory: 1Gi
limits:
cpu: 1
memory: 1Gi
volumeMounts:
- name: mysql-data
mountPath: /var/lib/mysql
volumeClaimTemplates:
- metadata:
name: mysql-data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: nfs-storage
resources:
requests:
storage: 1Gi
---
# 内部访问的无头服务
apiVersion: v1
kind: Service
metadata:
name: mysql-service
spec:
selector:
app: mysql
ports:
- name: mysql
port: 3306
clusterIP: None
---
# 外部访问的服务
apiVersion: v1
kind: Service
metadata:
name: mysql-external-service
spec:
selector:
app: mysql
ports:
- name: mysql
protocol: TCP
port: 3306
targetPort: 3306
nodePort: 30306
type: NodePort
更多推荐
已为社区贡献13条内容
所有评论(0)