安装 storage class:
external-storage/nfs-client/deploy at master · kubernetes-retired/external-storage · GitHub
下载文件并安装:
class.yaml deployment.yaml rbac.yaml
其中修改:
安装
测试:
[root@master test-dir]# cat nginx-1.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
namespace: test
spec:
storageClassName: "managed-nfs-storage"
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]#