[root@master test-dir]# cat nginx-1.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pvc
namespace: test
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
path: /ifs/kubernetes
server: 192.168.3.214
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
namespace: test
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx-1
name: nginx-1-deployment
namespace: test
spec:
replicas: 3
selector:
matchLabels:
app: nginx-1
template:
metadata:
labels:
app: nginx-1
project: blog
spec:
containers:
- image: nginx
name: nginx-1-container
volumeMounts:
- name: my-pvc
mountPath: /usr/share/nginx/html
volumes:
- name: my-pvc
persistentVolumeClaim:
claimName: my-pvc
---
apiVersion: v1
kind: Service
metadata:
name: nginx-1-service
namespace: test
spec:
ports:
- port: 8001 # 访问 Service 的端口,集群端口
protocol: TCP
targetPort: 80 # 容器商品,即应用程序端口
selector:
app: nginx-1 # pod 的 label
project: blog
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: nginx-1-ingress
namespace: test
spec:
rules:
- host: nginx.1.ingress
http:
paths:
- path: "/"
backend:
serviceName: nginx-1-service
servicePort: 8001
[root@master test-dir]#