首页 > 数据库技术 > 详细

k8s存储卷mysql故障转移

时间:2019-09-04 19:16:05      阅读:151      评论:0      收藏:0      [点我收藏+]

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故障转移

原文:https://www.cnblogs.com/fourw/p/11460911.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!