一、新建nfs服务器(192.168.1.44)
1.基础配置(IP地址防火墙等)
2.配置时间同步
root@localhost \~\]# yum -y install ntpdate.x86_64
\[root@localhost \~\]# ntpdate time2.aliyun.com
27 Sep 10:28:08 ntpdate\[1634\]: adjust time server 203.107.6.88 offset 0.014965 sec
\[root@localhost \~\]# crontab -e //设置计划任务
\* 3 \* \* \* /sbin/ntpdate time2.aliyun.com
### 3.安装nfs服务应用
\[root@localhost \~\]# yum -y install rpcbind nfs-utils
### 4.配置文件
\[root@localhost \~\]# echo "/root/pes \*(rw,sync)" \>\> /etc/exports
\[root@localhost \~\]# cat /etc/exports
/root/pes \*(rw.sync)
### 5.准备pes资源目录(部署考试系统项目)
### 6.启动服务
\[root@localhost \~\]# systemctl start rpcbind.service nfs-server.service //启动
\[root@localhost \~\]# systemctl enable rpcbind.service nfs-server.service //设置开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
### 7.验证
\[root@localhost \~\]# showmount -e localhost //这样代表成功
Export list for localhost:
/root/pes \*
## 二、部署前端
### 1.创建web-deployment.yaml资源清单文件
\[root@k8s-master \~\]# mkdir pes-k8s
\[root@k8s-master \~\]# cd pes-k8s
\[root@k8s-master pes-k8s\]# vim web-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
namespace: default
labels:
app: web-deployment
spec:
selector:
matchLabels:
app: web-deployment
replicas: 3
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: web-deployment
spec:
containers:
- name: nginxlatest
image: docker.io/library/nginx:latest
imagePullPolicy: Never
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 80
name: nginxport
volumeMounts:
- name: localtime
mountPath: /usr/share/nginx/html
volumes:
- name: localtime
nfs:
server: 192.168.1.44
path: /root/pes/web/dist
restartPolicy: Always
\[root@k8s-master pes-k8s\]# kubectl create -f web-deployment.yaml
deployment.apps/web-deployment created
\[root@k8s-master pes-k8s\]# kubectl get po -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
cluster-test-66bb44bd88-nk46t 1/1 Running 76 (21m ago) 14d 172.16.169.179 k8s-node2 \