k8s存储卷mysql故障转移
Posted fourw
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s存储卷mysql故障转移相关的知识,希望对你有一定的参考价值。
yum install -y rpcbind nfs-utils
创建共享目录
mkdir /home/sharedir
修改目录权限
chmod 0755 -R sharedir
修改NFS配置文件
vi /etc/exports
/home/sharedir 192.168.2.0(rw,no_root_squash,no_all_squash,sync)
----------------------------
yum install -y nfs-utils
showmount -e 192.168.2.120
mkdir /mnt/sharedir
mount -t nfs 192.168.2.120:/home/sharedir /mnt/sharedir
----------------------------------------
pv创建配置
mysql-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
nfs:
path: /home/sharedir/mysqldata
server: 192.168.2.120
----------------------------------------
pvc创建
mysql-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
----------------------------------------
部署mysql
mysql.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.6
env:
- name: MYSQL_ROOT_PASSWORD
value: password
ports:
- name: mysql
containerPort: 3306
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pvc
----------------------------------------
进入mysql容器:
kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -ppassword
以上是关于k8s存储卷mysql故障转移的主要内容,如果未能解决你的问题,请参考以下文章