项目地址:https://github.com/kubernetes-incubator/external-storage.git
使用示例架构:
clipboard.png说明:
nfs默认不支持动态存储,使用了第三方的NFS插件
项目插件地址:https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client/deploy
部署nfs StorageClass:
- clone项目
git clone https://github.com/kubernetes-incubator/external-storage.git
cd external-storage/nfs-client/deploy
- 部署rbac:
kubectl apply -f rbac.yaml
- 部署nfs clinet插件
注意,deployment.yaml里面的image默认是国外,需要改为自己镜像仓库,
下面的需要改为自己的nfs信息
env:
- name: PROVISIONER_NAME
value: fuseim.pri/ifs
- name: NFS_SERVER
value: 10.10.10.60 #NFS地址
- name: NFS_PATH #nfs路径
value: /ifs/kubernetes
volumes:
- name: nfs-client-root
nfs:
server: 10.10.10.60 #NFS地址
path: /ifs/kubernetes #NFS路径
kubectl apply -f deployment.yaml
kubectl apply -f class.yaml
- class.yaml文件详解
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: managed-nfs-storage
provisioner: fuseim.pri/ifs # deployment的env里面的PROVISIONER_NAME的值
parameters:
archiveOnDelete: "false"
使用:
- 创建pvc
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-claim
annotations:
volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" #这里指定的是class.yaml的name
spec:
accessModes:
- ReadWriteMany #运行所有主机读写挂载
resources:
requests:
storage: 1Mi #存储大小
- pod使用pvc
kind: Pod
apiVersion: v1
metadata:
name: test-pod
spec:
containers:
- name: test-pod
image: gcr.io/google_containers/busybox:1.24
command:
- "/bin/sh"
args:
- "-c"
- "touch /mnt/SUCCESS && exit 0 || exit 1"
volumeMounts:
- name: nfs-pvc
mountPath: "/mnt"
restartPolicy: "Never"
volumes:
- name: nfs-pvc
persistentVolumeClaim:
claimName: test-claim #pvc名字
我的blog
https://www.iyunw.cn
网友评论