复制 kind : Deployment
apiVersion : apps/v1
metadata :
name : nfs-client-provisioner
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
- name : NFS_SERVER
value : nfs
- name : NFS_PATH
value : /mnt/nfs/k8s
volumes :
- name : nfs-client-root
nfs :
server : nfs
path : /mnt/nfs/k8s
复制 apiVersion : v1
kind : ServiceAccount
metadata :
name : nfs-client-provisioner
---
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 : [ "list" , "watch" , "create" , "update" , "patch" ]
- apiGroups : [ "" ]
resources : [ "endpoints" ]
verbs : [ "create" , "delete" , "get" , "list" , "watch" , "patch" , "update" ]
---
kind : ClusterRoleBinding
apiVersion : rbac.authorization.k8s.io/v1
metadata :
name : run-nfs-client-provisioner
subjects :
- kind : ServiceAccount
name : nfs-client-provisioner
namespace : default
roleRef :
kind : ClusterRole
name : nfs-client-provisioner-runner
apiGroup : rbac.authorization.k8s.io
2.3 nfs-client-class.yaml
复制 apiVersion : storage.k8s.io/v1
kind : StorageClass
metadata :
name : nfs-storage
provisioner : fuseim.pri/ifs # or choose another name, must match deployment's env PROVISIONER_NAME'
复制 $ kubectl create -f nfs-client.yaml
$ kubectl create -f nfs-client-sa.yaml
$ kubectl create -f nfs-client-class.yaml
复制 $ kubectl get pods
NAME READY STATUS RESTARTS AGE
...
nfs-client-provisioner-7648b664bc-7f9pk 1/1 Running 0 7h
...
$ kubectl get storageclass
NAME PROVISIONER AGE
course-nfs-storage fuseim.pri/ifs 11s
复制 kind : PersistentVolumeClaim
apiVersion : v1
metadata :
name : ceres-admin-server-nfs-pvc
annotations :
volume.beta.kubernetes.io/storage-class : "nfs-storage"
spec :
accessModes :
- ReadWriteMany
resources :
requests :
storage : 32Mi
复制 [root@k8s-master StorageClass]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
ceres-admin-server-nfs-pvc Bound pvc-fec62c86-451e-4125-9e00-be60394f40d9 32Mi RWX nfs-storage 3h13m
ceres-app-server-nfs-pvc Bound pvc-6367fbb5-bc9c-4a75-a5a4-0a555172a6fd 32Mi RWX nfs-storage 53m
自动生成了一个关联的 PV 对象,访问模式是 RWX,回收策略是 Delete,这个 PV 对象并不是我们手动创建的吧,这是通过我们上面的 StorageClass 对象自动创建的:
复制 [root@k8s-master StorageClass]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-6367fbb5-bc9c-4a75-a5a4-0a555172a6fd 32Mi RWX Delete Bound default/ceres-app-server-nfs-pvc nfs-storage 55m
pvc-fec62c86-451e-4125-9e00-be60394f40d9 32Mi RWX Delete Bound default/ceres-admin-server-nfs-pvc nfs-storage 3h14m
复制 apiVersion : apps/v1
kind : Deployment
metadata :
labels :
app : ceres-admin-server
name : ceres-admin-server-deployment
spec :
replicas : 1
selector :
matchLabels :
app : ceres-admin-server
template :
metadata :
labels :
app : ceres-admin-server
spec :
containers :
- command :
- java
- '-jar'
- /root/app.jar
- '--spring.config.location=/root/config/'
- '--spring.profiles.active=prod'
image : anaham-docker.pkg.coding.net/cereshop/ceres/ceres-admin-server
name : ceres-admin-server
ports :
- containerPort : 9000
volumeMounts :
- mountPath : /root/config/
name : ceres-admin-server-nfs-pvc
workingDir : /root
imagePullSecrets :
- name : coding-regcred
volumes :
- name : ceres-admin-server-nfs-pvc
persistentVolumeClaim :
claimName : ceres-admin-server-nfs-pvc