Kubernetes 持久化数据存储 StorageClass
Service 服务部分
apiVersion: v1
kind: Service
metadata:
name: tomcat-service
labels:
app: tomcat
spec:
selector:
app: tomcat
ports:
- name: tomcat-port
protocol: TCP
port: 8080
targetPort: 8080
type: ClusterIP
ingress 服务部分
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tomcat
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
tls:
- hosts:
- tomcat.cnsre.cn
secretName: tls-secret
rules:
- tomcat.cnsre.cn
- host: tomcat.cnsre.cn
http:
paths:- path: "/"
pathType: Prefix
backend:
service:
name: tomcat-service
port:
number: 8080
- path: "/"
部署 pod 服务
``` shell
kubectl apply -f tomcatc.yaml
# 输出如下
deployment.apps/tomcat-deployment created
查看状态
kubectl get pod
# 输出如下
NAME READY STATUS RESTARTS AGE
nfs-client-provisioner-fd74f99b4-wr58j 1/1 Running 0 76m
tomcat-deployment-7588b5c8fd-cnwvt 1/1 Running 0 59m
tomcat-deployment-7588b5c8fd-kl8fj 1/1 Running 0 59m
tomcat-deployment-7588b5c8fd-ksbg9 1/1 Running 0 59m
查看 PV PVC
[root@master tomccat]# kubectl get pv,pvc
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pvc-d35c82e3-29f3-4f6d-b25d-3ccdd365d1ec 500Mi RWX Delete Bound default/tomcat managed-nfs-storage 65m
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/tomcat Bound pvc-d35c82e3-29f3-4f6d-b25d-3ccdd365d1ec 500Mi RWX managed-nfs-storage 65m
查看 nfs server 目录中信息
[root@node1 ~]# ll /home/bsh/nfs/default-tomcat-pvc-d35c82e3-29f3-4f6d-b25d-3ccdd365d1ec/
总用量 220
-rw-r-----. 1 root root 22217 9月 3 14:49 catalina.2021-09-03.log
-rw-r-----. 1 root root 0 9月 3 14:41 host-manager.2021-09-03.log
-rw-r-----. 1 root root 2791 9月 3 14:49 localhost.2021-09-03.log
-rw-r-----. 1 root root 118428 9月 3 15:31 localhost_access_log.2021-09-03.txt
-rw-r-----. 1 root root 0 9月 3 14:41 manager.2021-09-03.log