标签:replica ann 自动完成 val hang 修改 应用 共享存储 wan
StorageClass作为对存储资源的抽象定义, 对用户设置的NFS申请屏蔽后端存储的细节, 一方面减少了用户对于存储资源细节的关注, 另一方面减轻了管理员手工管理pv的工作, 由系统自动完成pv的创建和绑定
StorageClass本身是一种资源对象, 不提供pv的创建, 这里以NFS共享存储为例, 使用nfs-client-provisioner组件连接nfs服务器以及pv的创建
1.安装nfs服务:省略
2.克隆nfs-client-provisioner组件代码
git clone https://github.com/kubernetes-incubator/external-storage.git
cd external-storage/nfs-client/deploy
3.修改deployment文件, 主要修改nfs服务器地址和nfs提供的目录
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: nfs-client-provisioner
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
app: nfs-client-provisioner
spec:
serviceAccountName: nfs-client-provisioner
containers:
- name: nfs-client-provisioner
image: registry.cn-hangzhou.aliyuncs.com/wangfang-dev/nfs-client-provisioner:latest
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: fuseim.pri/ifs
- name: NFS_SERVER
value: 192.168.1.48
- name: NFS_PATH
value: /data/nfs
volumes:
- name: nfs-client-root
nfs:
server: 192.168.1.48
path: /data/nfs
4.StorageClass
此处可以不修改,或者修改provisioner的名字,需要与上面的deployment的PROVISIONER_NAME名字一致。
cat class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: default
provisioner: fuseim.pri/ifs
5.应用创建
kubectl apply -f deployment.yaml
kubectl apply -f class.yaml
kubectl apply -f rbac.yaml
7.创建pvc和deployment资源
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: nginx-deployment-pvc
annotations:
volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
labels:
app: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.12
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
volumes:
- name: html
persistentVolumeClaim:
claimName: nginx-deployment-pvc
8.验证
自动创建pv
PV以 ${namespace}-${pvcName}-${pvName}的命名格式提供(在NFS服务器上)
PV回收的时候以 archieved-${namespace}-${pvcName}-${pvName} 的命名格式(在NFS服务器上)
kubernetes之NFS动态提供Kubernetes后端存储卷
标签:replica ann 自动完成 val hang 修改 应用 共享存储 wan
原文地址:https://www.cnblogs.com/lovelinux199075/p/11268414.html