k8s部署数据持久化mysql
1、创建mysql pv文件[root@k8s-node1 mysql]# cat mysql_pv.yamlapiVersion: v1kind: PersistentVolumemetadata:name: mysql-dataspec:capacity:storage: 1GiaccessModes:- ReadWriteManynfs...
·
1、创建mysql pv文件
[root@k8s-node1 mysql]# cat mysql_pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-data
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
path: /app/mysql_data #nfs共享目录
server: 192.168.29.175 #nfs服务器地址,nfs服务需要自行搭建
persistentVolumeReclaimPolicy: Recycle
2、创建mysql pvc文件
[root@k8s-node1 mysql]# cat mysql_pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mysql-data
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
3、创建mysql deployment文件
[root@k8s-node1 mysql]# cat mysql_deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
template:
metadata:
labels:
name: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
ports:
- name: db
containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456com"
volumeMounts:
- mountPath: /var/lib/mysql
name: mysql-data
volumes:
- name: mysql-data
persistentVolumeClaim:
claimName: mysql-data
4、创建mysql svc文件
[root@k8s-node1 mysql]# cat mysql_svc.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
type: NodePort
ports:
- port: 3306
targetPort: 3306
nodePort: 9006
selector:
name: mysql
5、查看部署结果
[root@k8s-node1 mysql]# kubectl get pod
NAME READY STATUS RESTARTS AGE
mysql-67d458b8b4-w55pp 1/1 Running 0 16m
[root@k8s-node1 ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mysql NodePort 10.1.177.197 <none> 3306:9006/TCP 16m
更多推荐
已为社区贡献45条内容
所有评论(0)