k8s对mysql做持久化nfs
msyql持久化--nfs
·
1、安装nfs存储服务器--server端
# 安装nfs
yum install -y nfs-utils
# 创建nfs目录
mkdir -p /nfs/data/
mkdir -p /nfs/data/mysql
# 授予权限
chmod -R 777 /nfs/data
# 编辑export文件
vi /etc/exports
/nfs/data *(rw,no_root_squash,sync)
# 使得配置生效
exportfs -r
# 查看生效
exportfs
# 启动rpcbind、nfs服务
systemctl restart rpcbind && systemctl enable rpcbind
systemctl restart nfs && systemctl enable nfs
# 查看rpc服务的注册情况
rpcinfo -p localhost
# showmount测试
showmount -e ip(ip地址)
2、在每个节点上安装nfs--客户端
yum -y install nfs-utils
systemctl start nfs && systemctl enable nfs
3、自定义PV--mysql-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
namespace: app
labels:
cloud: lle-pv-mysql
spec:
capacity:
storage: 5G
volumeMode: Filesystem
accessModes: ["ReadWriteMany"]
persistentVolumeReclaimPolicy: Delete
storageClassName: test-mysql
nfs:
path: /nfs/data/mysql
server: 192.168.3.42
4、自定义PVC--mysql-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
namespace: app
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5G
storageClassName: lle-test-nfs-mysql
volumeMode: Filesystem
volumeName: mysql-pv
5、自定义mysql的用户名和密码--mysql-secert.yaml
将用户名和密码进行加密放入到secret里面
apiVersion: v1
kind: Secret
metadata:
name: mysql-user-passward
namespace: app
data:
username: cm9vdAo=
password: V3d3LjEuY29tCg==
6、设置私有镜像仓库harbor的镜像访问-- harbor-secert.yaml
apiVersion: v1
kind: Secret
metadata:
name: harbor-secert
data:
.dockerconfigjson: ewoJImF1dGhzIjogewoJCSIxOTIuMTY4LjMuNDIiOiB7CgkJCSJhdXRoIjogIllXUnRhVzQ2VjNkM0xqRXVZMjl0IgoJCX0KCX0KfQ==
type: kubernetes.io/dockerconfigjson
7、编辑mysql的yaml文件--deployment---mysql.yaml
kind: Deployment
metadata:
namespace: app
name: mysql
spec:
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: 192.168.3.42/k8s/mysql:latest
name: mysql
env:
# Use secret in real usage
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-user-passward
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-pvc
mountPath: /var/lib/mysql
imagePullSecrets:
- name: harbor-secert
volumes:
- name: mysql-pvc
persistentVolumeClaim:
claimName: mysql-pvc
更多推荐
已为社区贡献4条内容
所有评论(0)