StorageClass
描述:
1、使用nfs集中式存储实现节点调度后的数据一致性。
2、创建k8s存储类(nfs)用于自动化创建pv、pvc,便于部署。
部署:
#创建nfs
ssh 172.16.1.128
yum -y install nfs-utils rpcbind
mkdir -p /var/nfs
chmod 777 -R /var/nfs
vim /etc/exports
/var/nfs *(rw,sync,no_root_squash)
exportfs -r
systemctl start nfs
systemctl enabled nfs
systemctl start rpcbind
systemctl enabled rpcbind
#创建nfs存储类
wget http://raw.githubusercontent.com/kubernetes-incubator/external-storage/master/nfs-client/deploy/deployment.yaml
vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-client
labels:
app: nfs-client
namespace: default
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: nfs-client
template:
metadata:
labels:
app: nfs-client
spec:
serviceAccountName: nfs-client
containers:
- name: nfs-client
image: quay.io/external_storage/nfs-client-provisioner:latest
image: quay.io/external_storage/nfs-subdir-external-provisioner:v4.0.2
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: radondb-mysql-nfs
- name: ENABLE_LEADER_ELECTION
value: "True"
- name: NFS_SERVER
value: 172.16.1.128
- name: NFS_PATH
value: /var/nfs
volumes:
- name: nfs-client-root
nfs:
server: 172.16.1.128
path: /var/nfs
kubectl apply -f deployment.yaml
vim nfs-client-sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: nfs-client-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-provisioner
subjects:
- kind: ServiceAccount
name: nfs-client
namespace: default
roleRef:
kind: ClusterRole
name: nfs-client-runner
apiGroup: rbac.authorization.k8s.io
kubectl apply -f nfs-client-sa.yaml
vim nfs-client-class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: course-nfs-storage
provisioner: radondb-mysql-nfs
parameters:
pathPattern: "${.PVC.namespace}/${.PVC.annotations.nfs.io/storage-path}"
kubectl apply -f nfs-client-class.yaml
kubectl get storageclass|grep course-nfs-storage
vim test-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-test
annotations:
volume.beta.kubernetes.io/storage-class: "course-nfs-storage"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
kubectl apply -f test-pvc.yaml
kubectl get pvc -A |grep pvc-test
kubectl get pv