系统部署流程
- 所有节点搭建nfs⽂件系统
- 创建PersistentVolumeClaims(PVC)和PersistentVolume(PV)
- 创建service
- 创建Secret(注⼊MySql密码等)
- 创建confifigMap(初始化数据库)
- 部署MySQL容器组(Deployment)
- 部署WordPress容器组(Deployment)
nfs文件系统搭建
安装nfs并设置开机启动
#集群所有节点上执行nfs文件系统的安装和启动 [root@k8s-01 ~]# yum install nfs-utils -y [root@k8s-01 ~]# systemctl enable nfs-server && systemctl start nfs-server #启动完成后查看nfs启动状态 [root@k8s-01 ~]# systemctl status nfs-server ● nfs-server.service - NFS server and services Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled) Drop-In: /run/systemd/generator/nfs-server.service.d └─order-with-mounts.conf Active: active (exited) since Mon 2021-10-04 17:51:47 CST; 16h ago Process: 1399 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS) Process: 1378 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS) Process: 1375 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS) Main PID: 1378 (code=exited, status=0/SUCCESS) Tasks: 0 Memory: 0B CGroup: /system.slice/nfs-server.service Oct 04 17:51:47 k8s-01 systemd[1]: Starting NFS server and services... Oct 04 17:51:47 k8s-01 systemd[1]: Started NFS server and services.
master节点创建nfs挂载点
#创建/home/nfstest测试路径,测试nfs文件系统 [root@k8s-01 home]# mkdir nfstest #修改/home/nfstest路径权限 #no_subtree_check不检查其父目录的权限,rw表示权限 读写,sync表示同步写入,no_root_squash表示worknode以root访问时赋予本地root权限 [root@k8s-01 home]# chown nfsnobody:nfsnobody /home/nfstest [root@k8s-01 home]# echo -e "/home/nfstest *(rw,sync,no_subtree_check,no_root_squash)" > /etc/exports #应用配置 [root@k8s-01 home]# exportfs -a
work node进行nfs挂载验证
#worknode上创建本地挂载点 [root@k8s-02 ~]# mkdir /home/nfstest #将worknode本地挂载点与master上的nfs挂载点映射 [root@k8s-02 ~]# mount -t nfs 192.168.188.131:/home/nfstest /home/nfstest #本地挂载点修改属主信息 [root@k8s-02 ~]# chown nfsnobody:nfsnobody /home/nfstest #检查挂载是否成功 [root@k8s-02 ~]# df -h|grep /home/nfstest 192.168.188.131:/home/nfstest 16G 7.2G 8.9G 45% /home/nfstest #master节点上创建文件 [root@k8s-01 nfstest]# echo "test nfs on k8s-01 master" >> nfstest.file [root@k8s-01 nfstest]# cat nfstest.file test nfs on k8s-01 master #worknode上对应挂载点查看此文件 [root@k8s-02 ~]# cat /home/nfstest/nfstest.file test nfs on k8s-01 master
配置mysql和wordpress的nfs文件系统
#master节点创建nfs文件主目录以及相关设置 [root@k8s-01 ~]# mkdir -p /kube/mysql-db [root@k8s-01 ~]# mkdir -p /kube/wordpress [root@k8s-01 ~]# chown nfsnobody:nfsnobody /kube/mysql-db [root@k8s-01 ~]# chown nfsnobody:nfsnobody /kube/wordpress [root@k8s-01 ~]# vim /etc/exports /kube/wordpress *(rw,sync,no_subtree_check,no_root_squash) /kube/mysql-db *(rw,sync,no_subtree_check,no_root_squash) [root@k8s-01 ~]# exportfs -a #worknode上创建挂载点,作相应设置,并通过nfs将挂载点挂载到master对应的目录上,k8s-01是master节点的主机名 [root@k8s-02 ~]# mkdir -p /kube/mysql-db You have new mail in /var/spool/mail/root [root@k8s-02 ~]# mkdir -p /kube/wordpress [root@k8s-02 ~]# chown nfsnobody:nfsnobody /kube/mysql-db [root@k8s-02 ~]# chown nfsnobody:nfsnobody /kube/wordpress [root@k8s-02 ~]# mount -t nfs k8s-01:/kube/wordpress /kube/wordpress [root@k8s-02 ~]# mount -t nfs k8s-01:/kube/mysql-db /kube/mysql-db [root@k8s-02 ~]# df -h|grep k8s-01 k8s-01:/kube/wordpress 16G 6.0G 11G 38% /kube/wordpress k8s-01:/kube/mysql-db 16G 6.0G 11G 38% /kube/mysql-db