更新 'kubernetes-MD/Kubernetes存储类StorageClass.md'
This commit is contained in:
parent
79249692e3
commit
44df7d7908
|
@ -1,235 +1,235 @@
|
||||||
<h1><center>Kubernetes存储类StorageClass</center></h1>
|
<h1><center>Kubernetes存储类StorageClass</center></h1>
|
||||||
|
|
||||||
著作:行癫 <盗版必究>
|
著作:行癫 <盗版必究>
|
||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
## 一:StorageClass
|
## 一:StorageClass
|
||||||
|
|
||||||
StorageClass 为管理员提供了描述存储 "类" 的方法。 不同的类型可能会映射到不同的服务质量等级或备份策略,或是由集群管理员制定的任意策略。 Kubernetes 本身并不清楚各种类代表的什么。这个类的概念在其他存储系统中有时被称为 "配置文件"
|
StorageClass 为管理员提供了描述存储 "类" 的方法。 不同的类型可能会映射到不同的服务质量等级或备份策略,或是由集群管理员制定的任意策略。 Kubernetes 本身并不清楚各种类代表的什么。这个类的概念在其他存储系统中有时被称为 "配置文件"
|
||||||
|
|
||||||
#### 1.StorageClass 资源
|
#### 1.StorageClass 资源
|
||||||
|
|
||||||
每个 StorageClass 都包含 `provisioner`、`parameters` 和 `reclaimPolicy` 字段, 这些字段会在 StorageClass 需要动态分配 PersistentVolume 时会使用到
|
每个 StorageClass 都包含 `provisioner`、`parameters` 和 `reclaimPolicy` 字段, 这些字段会在 StorageClass 需要动态分配 PersistentVolume 时会使用到
|
||||||
|
|
||||||
StorageClass 对象的命名很重要,用户使用这个命名来请求生成一个特定的类。 当创建 StorageClass 对象时,管理员设置 StorageClass 对象的命名和其他参数,一旦创建了对象就不能再对其更新
|
StorageClass 对象的命名很重要,用户使用这个命名来请求生成一个特定的类。 当创建 StorageClass 对象时,管理员设置 StorageClass 对象的命名和其他参数,一旦创建了对象就不能再对其更新
|
||||||
|
|
||||||
#### 2.创建Storageclass
|
#### 2.创建Storageclass
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apiVersion: storage.k8s.io/v1
|
apiVersion: storage.k8s.io/v1
|
||||||
kind: StorageClass
|
kind: StorageClass
|
||||||
metadata:
|
metadata:
|
||||||
name: example-nfs //名称
|
name: example-nfs //名称
|
||||||
provisioner: example.com/external-nfs
|
provisioner: example.com/external-nfs
|
||||||
parameters:
|
parameters:
|
||||||
server: nfs-server.example.com
|
server: nfs-server.example.com
|
||||||
path: /share
|
path: /share
|
||||||
readOnly: "false"
|
readOnly: "false"
|
||||||
|
|
||||||
server:NFS 服务器的主机名或 IP 地址
|
server:NFS 服务器的主机名或 IP 地址
|
||||||
path:NFS 服务器导出的路径
|
path:NFS 服务器导出的路径
|
||||||
readOnly:是否将存储挂载为只读的标志(默认为 false)
|
readOnly:是否将存储挂载为只读的标志(默认为 false)
|
||||||
```
|
```
|
||||||
|
|
||||||
注意:
|
注意:
|
||||||
|
|
||||||
provisioner参数值:
|
provisioner参数值:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
NFS example.com/external-nfs
|
NFS example.com/external-nfs
|
||||||
Glusterfs kubernetes.io/glusterfs
|
Glusterfs kubernetes.io/glusterfs
|
||||||
AWS EBS kubernetes.io/aws-ebs
|
AWS EBS kubernetes.io/aws-ebs
|
||||||
......
|
......
|
||||||
```
|
```
|
||||||
|
|
||||||
AWS EBS:
|
AWS EBS:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apiVersion: storage.k8s.io/v1
|
apiVersion: storage.k8s.io/v1
|
||||||
kind: StorageClass
|
kind: StorageClass
|
||||||
metadata:
|
metadata:
|
||||||
name: slow
|
name: slow
|
||||||
provisioner: kubernetes.io/aws-ebs
|
provisioner: kubernetes.io/aws-ebs
|
||||||
parameters:
|
parameters:
|
||||||
type: io1
|
type: io1
|
||||||
iopsPerGB: "10" //这里需要输入一个字符串,即 "10",而不是 10
|
iopsPerGB: "10" //这里需要输入一个字符串,即 "10",而不是 10
|
||||||
fsType: ext4
|
fsType: ext4
|
||||||
|
|
||||||
type:io1,gp2,sc1,st1。详细信息参见 AWS 文档。默认值:gp2
|
type:io1,gp2,sc1,st1。详细信息参见 AWS 文档。默认值:gp2
|
||||||
iopsPerGB:只适用于 io1 卷。每 GiB 每秒 I/O 操作。AWS卷插件将其与请求卷的大小相乘以计算IOPS的容量,并将其限制在 20000 IOPS
|
iopsPerGB:只适用于 io1 卷。每 GiB 每秒 I/O 操作。AWS卷插件将其与请求卷的大小相乘以计算IOPS的容量,并将其限制在 20000 IOPS
|
||||||
fsType:受 Kubernetes 支持的文件类型。默认值:"ext4"
|
fsType:受 Kubernetes 支持的文件类型。默认值:"ext4"
|
||||||
```
|
```
|
||||||
|
|
||||||
Glusterfs:
|
Glusterfs:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
apiVersion: storage.k8s.io/v1
|
apiVersion: storage.k8s.io/v1
|
||||||
kind: StorageClass
|
kind: StorageClass
|
||||||
metadata:
|
metadata:
|
||||||
name: slow
|
name: slow
|
||||||
provisioner: kubernetes.io/glusterfs
|
provisioner: kubernetes.io/glusterfs
|
||||||
parameters:
|
parameters:
|
||||||
resturl: "http://127.0.0.1:8081"
|
resturl: "http://127.0.0.1:8081"
|
||||||
clusterid: "630372ccdc720a92c681fb928f27b53f"
|
clusterid: "630372ccdc720a92c681fb928f27b53f"
|
||||||
restauthenabled: "true"
|
restauthenabled: "true"
|
||||||
restuser: "admin"
|
restuser: "admin"
|
||||||
secretNamespace: "default"
|
secretNamespace: "default"
|
||||||
secretName: "heketi-secret"
|
secretName: "heketi-secret"
|
||||||
gidMin: "40000"
|
gidMin: "40000"
|
||||||
gidMax: "50000"
|
gidMax: "50000"
|
||||||
volumetype: "replicate:3"
|
volumetype: "replicate:3"
|
||||||
|
|
||||||
resturl:制备 gluster 卷的需求的Gluster REST服务/Heketi服务url,通用格式应该是 IPaddress:Port
|
resturl:制备 gluster 卷的需求的Gluster REST服务/Heketi服务url,通用格式应该是 IPaddress:Port
|
||||||
restauthenabled:Gluster REST 服务身份验证布尔值,用于启用对 REST 服务器的身份验证
|
restauthenabled:Gluster REST 服务身份验证布尔值,用于启用对 REST 服务器的身份验证
|
||||||
restuser:在 Gluster 可信池中有权创建卷的 Gluster REST服务/Heketi 用户
|
restuser:在 Gluster 可信池中有权创建卷的 Gluster REST服务/Heketi 用户
|
||||||
restuserkey:服务器进行身份验证。 此参数已弃用,取而代之的是 secretNamespace + secretName
|
restuserkey:服务器进行身份验证。 此参数已弃用,取而代之的是 secretNamespace + secretName
|
||||||
secretNamespace,secretName:Secret 实例的标识,包含与 Gluster REST 服务交互时使用的用户密码;
|
secretNamespace,secretName:Secret 实例的标识,包含与 Gluster REST 服务交互时使用的用户密码;
|
||||||
这些参数是可选的,secretNamespace 和 secretName 都省略时使用空密码,以这种方式创建:
|
这些参数是可选的,secretNamespace 和 secretName 都省略时使用空密码,以这种方式创建:
|
||||||
kubectl create secret generic heketi-secret \
|
kubectl create secret generic heketi-secret \
|
||||||
--type="kubernetes.io/glusterfs" --from-literal=key='opensesame' \
|
--type="kubernetes.io/glusterfs" --from-literal=key='opensesame' \
|
||||||
--namespace=default
|
--namespace=default
|
||||||
clusterid:630372ccdc720a92c681fb928f27b53f 是集群的 ID,当制备卷时, Heketi 将会使用这个文件
|
clusterid:630372ccdc720a92c681fb928f27b53f 是集群的 ID,当制备卷时, Heketi 将会使用这个文件
|
||||||
gidMin,gidMax:StorageClass GID 范围的最小值和最大值,这是 gidMin 和 gidMax 的默认值
|
gidMin,gidMax:StorageClass GID 范围的最小值和最大值,这是 gidMin 和 gidMax 的默认值
|
||||||
volumetype:卷的类型及其参数可以用这个可选值进行配置
|
volumetype:卷的类型及其参数可以用这个可选值进行配置
|
||||||
'Replica volume': volumetype: replicate:3 其中 '3' 是 replica 数量
|
'Replica volume': volumetype: replicate:3 其中 '3' 是 replica 数量
|
||||||
'Disperse/EC volume': volumetype: disperse:4:2 其中 '4' 是数据,'2' 是冗余数量
|
'Disperse/EC volume': volumetype: disperse:4:2 其中 '4' 是数据,'2' 是冗余数量
|
||||||
'Distribute volume': volumetype: none
|
'Distribute volume': volumetype: none
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 3.使用
|
#### 3.使用
|
||||||
|
|
||||||
创建storageclass文件:
|
创建storageclass文件:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
[root@master class]# cat storageclass
|
[root@master class]# cat storageclass
|
||||||
apiVersion: storage.k8s.io/v1
|
apiVersion: storage.k8s.io/v1
|
||||||
kind: StorageClass
|
kind: StorageClass
|
||||||
metadata:
|
metadata:
|
||||||
name: example-nfs
|
name: example-nfs
|
||||||
provisioner: example.com/external-nfs
|
provisioner: example.com/external-nfs
|
||||||
parameters:
|
parameters:
|
||||||
server: 10.0.0.230
|
server: 10.0.0.230
|
||||||
path: /kubernetes-3
|
path: /kubernetes-3
|
||||||
readOnly: "false"
|
readOnly: "false"
|
||||||
```
|
```
|
||||||
|
|
||||||
创建:
|
创建:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
[root@master class]# kubectl create -f storageclass
|
[root@master class]# kubectl create -f storageclass
|
||||||
storageclass.storage.k8s.io/example-nfs created
|
storageclass.storage.k8s.io/example-nfs created
|
||||||
```
|
```
|
||||||
|
|
||||||
查看:
|
查看:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
[root@master class]# kubectl get storageclass
|
[root@master class]# kubectl get storageclass
|
||||||
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
|
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
|
||||||
example-nfs example.com/external-nfs Delete Immediate false 9s
|
example-nfs example.com/external-nfs Delete Immediate false 9s
|
||||||
|
|
||||||
RECLAIMPOLICY:回收策略 Delete
|
RECLAIMPOLICY:回收策略 Delete
|
||||||
VOLUMEBINDINGMODE:默认情况下, Immediate 模式表示一旦创建了PersistentVolumeClaim 也就完成了卷绑定和动态制备
|
VOLUMEBINDINGMODE:默认情况下, Immediate 模式表示一旦创建了PersistentVolumeClaim 也就完成了卷绑定和动态制备
|
||||||
```
|
```
|
||||||
|
|
||||||
创建pv的yaml文件:
|
创建pv的yaml文件:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
[root@master class]# cat pv.yaml
|
[root@master class]# cat pv.yaml
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: PersistentVolume
|
kind: PersistentVolume
|
||||||
metadata:
|
metadata:
|
||||||
name: xingdian-1
|
name: xingdian-1
|
||||||
spec:
|
spec:
|
||||||
capacity:
|
capacity:
|
||||||
storage: 10Gi
|
storage: 10Gi
|
||||||
volumeMode: Filesystem
|
volumeMode: Filesystem
|
||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteOnce
|
- ReadWriteOnce
|
||||||
storageClassName: example-nfs
|
storageClassName: example-nfs
|
||||||
nfs:
|
nfs:
|
||||||
path: /kubernetes-1
|
path: /kubernetes-1
|
||||||
server: 10.0.0.230
|
server: 10.0.0.230
|
||||||
```
|
```
|
||||||
|
|
||||||
创建:
|
创建:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
[root@master class]# kubectl create -f pv.yaml
|
[root@master class]# kubectl create -f pv.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
查看pv:
|
查看pv:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
[root@master class]# kubectl get pv
|
[root@master class]# kubectl get pv
|
||||||
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
|
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
|
||||||
xingdian-1 10Gi RWO Retain Available example-nfs 3s
|
xingdian-1 10Gi RWO Retain Available example-nfs 3s
|
||||||
```
|
```
|
||||||
|
|
||||||
创建应用使用:
|
创建应用使用:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
[root@master class]# cat nginx.yaml
|
[root@master class]# cat nginx.yaml
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: StatefulSet
|
kind: StatefulSet
|
||||||
metadata:
|
metadata:
|
||||||
name: web
|
name: web
|
||||||
spec:
|
spec:
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: nginx
|
app: nginx
|
||||||
serviceName: "nginx"
|
serviceName: "nginx"
|
||||||
replicas: 1
|
replicas: 1
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: nginx
|
app: nginx
|
||||||
spec:
|
spec:
|
||||||
terminationGracePeriodSeconds: 10
|
terminationGracePeriodSeconds: 10
|
||||||
containers:
|
containers:
|
||||||
- name: nginx
|
- name: nginx
|
||||||
image: 10.0.0.230/xingdian/nginx:v1
|
image: 10.0.0.230/xingdian/nginx:v1
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 80
|
- containerPort: 80
|
||||||
name: web
|
name: web
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: www
|
- name: www
|
||||||
mountPath: /usr/share/nginx/html
|
mountPath: /usr/share/nginx/html
|
||||||
volumeClaimTemplates:
|
volumeClaimTemplates:
|
||||||
- metadata:
|
- metadata:
|
||||||
name: www
|
name: www
|
||||||
spec:
|
spec:
|
||||||
accessModes: [ "ReadWriteOnce" ]
|
accessModes: [ "ReadWriteOnce" ]
|
||||||
storageClassName: "example-nfs"
|
storageClassName: "example-nfs"
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 10Gi
|
storage: 10Gi
|
||||||
```
|
```
|
||||||
|
|
||||||
创建:
|
创建:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
[root@master class]# kubectl create -f nginx.yaml
|
[root@master class]# kubectl create -f nginx.yaml
|
||||||
statefulset.apps/web created
|
statefulset.apps/web created
|
||||||
```
|
```
|
||||||
|
|
||||||
查看:
|
查看:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
[root@master class]# kubectl get statefulset
|
[root@master class]# kubectl get statefulset
|
||||||
NAME READY AGE
|
NAME READY AGE
|
||||||
web 1/1 9s
|
web 1/1 9s
|
||||||
[root@master class]# kubectl get pod
|
[root@master class]# kubectl get pod
|
||||||
NAME READY STATUS RESTARTS AGE
|
NAME READY STATUS RESTARTS AGE
|
||||||
web-0 1/1 Running 0 13s
|
web-0 1/1 Running 0 13s
|
||||||
```
|
```
|
||||||
|
|
||||||
验证pv:
|
验证pv:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
[root@master class]# kubectl get pv
|
[root@master class]# kubectl get pv
|
||||||
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
|
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
|
||||||
xingdian-1 10Gi RWO Retain Bound default/www-web-0 example-nfs 52s
|
xingdian-1 10Gi RWO Retain Bound default/www-web-0 example-nfs 52s
|
||||||
```
|
```
|
||||||
|
|
||||||
![image-20220526224804444](Kubernetes%E5%AD%98%E5%82%A8%E7%B1%BBStorageClass.assets/image-20220526224804444-16535764908601.png)
|
![image-20220526224804444](Kubernetes%E5%AD%98%E5%82%A8%E7%B1%BBStorageClass.assets/image-20220526224804444-16535764908601.png)
|
||||||
|
|
Loading…
Reference in New Issue