赞
踩
PS:
因为 原来是1.20版本默认禁止使用selfLink。 所以后续版本需要在kube-apiserver.yaml后面增加 - --feature-gates=RemoveSelfLink=false
最好解决方案: https://blog.csdn.net/joker_zhou/article/details/125478979
基本流程简单:
1. 首先在客户端按照nfs 服务..这个网上一堆不介绍了,
2. 创建一个命名空间 (kubectl create namespace xxxx)
3. 创建rbac (rbac.yaml)
4. 创建nfs的provisioner (deployment.yaml)
5. 创建StorageClass (storageClass.yaml)
6. 在PVC使用storageClass即可 (pvc.yaml)
rbac.yaml
- apiVersion: v1
- kind: ServiceAccount
- metadata:
- name: nfs-client-provisioner
- # replace with namespace where provisioner is deployed
- namespace: hello-storageclass
- ---
- kind: ClusterRole
- apiVersion: rbac.authorization.k8s.io/v1
- metadata:
- name: nfs-client-provisioner-runner
- rules:
- - apiGroups: [""]
- resources: ["persistentvolumes"]
- verbs: ["get", "list", "watch", "create", "delete"]
- - apiGroups: [""]
- resources: ["persistentvolumeclaims"]
- verbs: ["get", "list", "watch", "update"]
- - apiGroups: ["storage.k8s.io"]
- resources: ["storageclasses"]
- verbs: ["get", "list", "watch"]
- - apiGroups: [""]
- resources: ["events"]
- verbs: ["create", "update", "patch"]
- ---
- kind: ClusterRoleBinding
- apiVersion: rbac.authorization.k8s.io/v1
- metadata:
- name: run-nfs-client-provisioner
- subjects:
- - kind: ServiceAccount
- name: nfs-client-provisioner
- # replace with namespace where provisioner is deployed
- namespace: hello-storageclass
- roleRef:
- kind: ClusterRole
- name: nfs-client-provisioner-runner
- apiGroup: rbac.authorization.k8s.io
- ---
- kind: Role
- apiVersion: rbac.authorization.k8s.io/v1
- metadata:
- name: leader-locking-nfs-client-provisioner
- # replace with namespace where provisioner is deployed
- namespace: hello-storageclass
- rules:
- - apiGroups: [""]
- resources: ["endpoints"]
- verbs: ["get", "list", "watch", "create", "update", "patch"]
- ---
- kind: RoleBinding
- apiVersion: rbac.authorization.k8s.io/v1
- metadata:
- name: leader-locking-nfs-client-provisioner
- # replace with namespace where provisioner is deployed
- namespace: hello-storageclass
- subjects:
- - kind: ServiceAccount
- name: nfs-client-provisioner
- # replace with namespace where provisioner is deployed
- namespace: hello-storageclass
- roleRef:
- kind: Role
- name: leader-locking-nfs-client-provisioner
- apiGroup: rbac.authorization.k8s.io
deployment.yaml
- apiVersion: apps/v1
- kind: Deployment
- metadata:
- name: nfs-client-provisioner
- labels:
- app: nfs-client-provisioner
- # replace with namespace where provisioner is deployed
- namespace: hello-storageclass
- spec:
- replicas: 1
- strategy:
- type: Recreate
- selector:
- matchLabels:
- app: nfs-client-provisioner
- template:
- metadata:
- labels:
- app: nfs-client-provisioner
- spec:
- serviceAccountName: nfs-client-provisioner
- containers:
- - name: nfs-client-provisioner
- image: quay.io/external_storage/nfs-client-provisioner:latest
- volumeMounts:
- - name: nfs-client-root
- mountPath: /persistentvolumes
- env:
- - name: PROVISIONER_NAME
- value: fuseim.pri/ifs
- #记住这个名字fuseim.pri/ifs 后面要用到
- - name: NFS_SERVER
- value: 192.168.1.4 #NFS服务器的IP
- - name: NFS_PATH
- # remote server (192.168.1.4) nfs directory
- value: /hddisk/nfsdata/nacos #这里是NFS创建的文件夹目录 需要 777 权限
- volumes:
- - name: nfs-client-root
- nfs:
- server: 192.168.1.4 #这个和上面配置一致
- path: /hddisk/nfsdata/nacos
storageclass.yaml
- kind: StorageClass
- apiVersion: storage.k8s.io/v1
- metadata:
- name: managed-nfs-storage #这个也记住在pvc中使用到
- annotations:
- kubesphere.io/creator: admin
- storageclass.kubesphere.io/support-snapshot: 'false'
- provisioner: fuseim.pri/ifs #这个就是deployment.yaml里面让记住的名字
- parameters:
- archiveOnDelete: 'false'
- reclaimPolicy: Delete
- volumeBindingMode: Immediate
pvc.yaml
- kind: PersistentVolumeClaim
- apiVersion: v1
- metadata:
- name: ks-mavenresp
- namespace: p-lms
- annotations:
- kubesphere.io/alias-name: mysql-data
- kubesphere.io/creator: admin
- pv.kubernetes.io/bind-completed: 'yes'
- pv.kubernetes.io/bound-by-controller: 'yes'
- volume.beta.kubernetes.io/storage-provisioner: fuseim.pri/ifs
- spec:
- accessModes:
- - ReadWriteOnce
- resources:
- requests:
- storage: 10Gi
- volumeName: pvc-4a1833c6-a922-4824-9236-613329394482
- storageClassName: managed-nfs-storage #这里..不用说吧= =storageClassName 很明显了
- volumeMode: Filesystem
deployment.yaml
- spec:
- volumes:
- - name: volume-2 #这里起个别名 引用pvc
- persistentVolumeClaim:
- claimName: ks-mavenresp #pvc名字
- containers:
- - name: jnlp
- image: 'jenkins/jnlp-slave:3.27-1'
- command:
- - jenkins-slave
- args:
- - f739d2774efec33b8d0f5cdf8159e35954af289b3f3ce8fbe38d36b3cb16bf46
- - maven-nd1fh
- volumeMounts:
- - name: volume-2 #这里使用pvc
- mountPath: /root/.m2
关于在k8s-v1.20以上版本使用nfs作为storageclass出现selfLink was empty, can‘t make reference_w2909526的博客-CSDN博客
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。