在k8s集群内部署,pod有健康检查探针,httpd镜像检查nfs挂载到pod内的index.html存在即可更新。
每次更新(新旧容器)最多容器总量为15个
在所有节点上搭建nfs服务器:
[root@server1 ~]# yum -y install nfs-utils rpcbind
[root@server2 ~]# yum -y install nfs-utils rpcbind
[root@server3 ~]# yum -y install nfs-utils rpcbind
在server2上创建nfs文件:
[root@server2 ~]# mkdir /nfsdata
[root@server2 ~]# vi /etc/exports
添加:
/nfsdata *(rw,no_root_squash,sync)
[root@server2 ~]# exportfs -r
[root@server2 ~]# systemctl start rpcbind
[root@server2 ~]# systemctl start nfs-server
所有节点测试访问:
[root@server2 ~]# showmount -e 192.168.1.5
主节点server1上部署:
[root@server1 ~]# vi http.yaml
添加:
apiVersion: apps/v1
kind: Deployment
metadata:
name: apache
spec:
selector:
matchLabels:
app: apache
replicas: 10
template:
metadata:
labels:
app: apache
spec:
containers:
- name: httpd
image: httpd:2.4.48
ports:
- containerPort: 80
volumeMounts:
- name: httpd
mountPath: /usr/local/apache2/htdocs
volumes:
- name: httpd
nfs:
server: 192.168.1.5
path: /nfsdata
执行:
[root@server1 ~]# kubectl apply -f http.yaml --record
deployment.apps/apache created
[root@server1 ~]# cp http.yaml http1.yaml
查看:
修改httpd1.yaml文件:
[root@server1 ~]# vi http1.yaml
添加:
apiVersion: apps/v1
kind: Deployment
metadata:
name: apache
spec:
strategy:
rollingUpdate:
maxSurge: 50%
maxUnavailable: 35%
selector:
matchLabels:
app: apache
replicas: 10
template:
metadata:
labels:
app: apache
spec:
containers:
- name: httpd
image: httpd:latest
ports:
- containerPort: 80
volumeMounts:
- name: httpd
mountPath: /usr/local/apache2/htdocs
args:
- rm -rf /usr/local/apache2/htdocs/index.html; sleep 300000
readinessProbe:
exec:
command:
- cat
- /usr/local/apache2/htdocs/index.html
initialDelaySeconds: 10
periodSeconds: 5
volumes:
- name: httpd
nfs:
server: 192.168.1.5
path: /nfsdata
执行:
[root@server1 ~]# kubectl apply -f http1.yaml --record
查看: