kubernetes-installation/sc-provider/README.md

105 lines
2.4 KiB
Markdown
Raw Normal View History

# Configure Storage Class Provider with NFS
1. Create storage class
```yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-k8s-data
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: k8s/nfs
allowVolumeExpansion: true
```
2. Create service account and permission
- Create service account
```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
```
- Define cluster role
```yaml
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: ["get", "list", "watch", "create", "update", "patch"]
```
- Bind cluster to service account
```yaml
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
```
3. Deploy provisioner as pod
```yaml
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: nfs-client-provisioner
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
app: nfs-client-provisioner
spec:
serviceAccount: nfs-client-provisioner
containers:
- name: nfs-client-provisioner
image: quay.io/external_storage/nfs-client-provisioner:v3.1.0-k8s1.11
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: k8s/nfs
- name: NFS_SERVER
value: 192.168.1.119 # nodes will need nfs-common to access nfs protocol
- name: NFS_PATH
value: /export/k8sdynamic
volumes:
- name: nfs-client-root
nfs:
server: 192.168.1.119
path: /export/k8sdynamic
```