本文环境可参考:
详细教程 Centos8.5 基于 k8s v1.30.1 部署高可用集群 kubeadm 安装 kubernetes v1.30.1 docker集群搭建 延长证书有效期-CSDN博客
1 集群部署,需要PV,安装NFS
#master11,slave12,slave13都安装
yum install nfs-utils rpcbind -y
2 配置
#master11
vim /etc/exports
/data/share 192.168.50.0/24(sync,rw,no_root_squash)
#启动服务
systemctl enable rpcbind.service
systemctl enable nfs-server.service
systemctl start rpcbind.service
systemctl start nfs-server.service
#查看服务
[root@master11 share]# showmount -e 192.168.50.11
Export list for 192.168.50.11:
/data/share 192.168.50.0/24
#客户端
#slave12
#启动服务
systemctl enable rpcbind.service
systemctl enable nfs-server.service
systemctl start rpcbind.service
systemctl start nfs-server.service
#查看
[root@slave12 ~]# showmount -e 192.168.50.11
Export list for 192.168.50.11:
/data/share 192.168.50.0/24
#挂载
mkdir -p /mnt/nfs
mount -t nfs 192.168.50.11:/data/share /mnt/nfs
#查看
[root@slave12 ~]# df -h| grep nfs
192.168.50.11:/data/share 36G 16G 21G 44% /mnt/nfs
#slave13同样安装配置
3 yaml配置
[root@master11 soft]# cat discuz.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: discuz
spec:
replicas: 3
selector:
matchLabels:
app: discuz
template:
metadata:
labels:
app: discuz
spec:
containers:
- name: discuz
image: 192.168.50.11:5000/discuz:x3.5
ports:
- containerPort: 80
volumeMounts:
- name: host-data
mountPath: /var/www/html
volumes:
- name: host-data
hostPath:
path: /mnt/nfs/discuz/html
type: DirectoryOrCreate
#
[root@master11 soft]# cat discuz-srv.yaml
apiVersion: v1
kind: Service
metadata:
name: discuz-service
labels:
app: discuz
spec:
selector:
app: discuz
ports:
- protocol: TCP
port: 88
targetPort: 80
nodePort: 30036
type: NodePort
4 创建应用
#master11
kubectl apply -f discuz.yaml
kubectl apply -f discuz-srv.yaml
#删除
kubectl delete -f discuz.yaml
kubectl delete -f discuz-srv.yaml
5 查看和访问
[root@master11 discuz]# kubectl get node,po,svc -A -owide|grep discuz
default pod/discuz-859bc9f964-d79mj 1/1 Running 0 31m 10.244.126.205 slave13 <none> <none>
default pod/discuz-859bc9f964-dgxfw 1/1 Running 0 31m 10.244.126.206 slave13 <none> <none>
default pod/discuz-859bc9f964-v8ff9 1/1 Running 0 31m 10.244.199.16 slave12 <none> <none>
default service/discuz-service NodePort 10.97.87.138 <none> 88:30036/TCP 31m app=discuz
#salve12
[root@slave12 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b588cf2f03f1 2835ba731e97 "docker-php-entrypoi…" 31 minutes ago Up 31 minutes k8s_discuz_discuz-859bc9f964-v8ff9_default_cf503e04-c42f-4e96-9523-165b37ef0634_0
#slave13
ONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b468798d3f94 2835ba731e97 "docker-php-entrypoi…" 32 minutes ago Up 32 minutes k8s_discuz_discuz-859bc9f964-dgxfw_default_5032b3ee-4b11-4121-a1a8-064b7d633f34_0
5ce6b41bd645 2835ba731e97 "docker-php-entrypoi…" 32 minutes ago Up 32 minutes k8s_discuz_discuz-859bc9f964-d79mj_default_4cf410ea-e0c1-42b7-8fb6-d7bc4edf15e4_0
#IP+Nodeport 访问