使用存储供应器 Gluster 插件
storage-provisioner-gluster 插件
Gluster,一个可扩展的网络文件系统,提供 PersistentVolumeClaims 的动态供应。
启动 Minikube
该插件可在 Minikube 中使用,无需任何额外配置。
$ minikube start
启用 storage-provisioner-gluster
要启用此插件,只需运行
$ minikube addons enable storage-provisioner-gluster
在一分钟内,插件管理器应该会检测到更改,您应该会看到 `storage-gluster` 命名空间中的几个 Pod。
$ kubectl -n storage-gluster get pods
NAME READY STATUS RESTARTS AGE
glusterfile-provisioner-dbcbf54fc-726vv 1/1 Running 0 1m
glusterfs-rvdmz 0/1 Running 0 40s
heketi-79997b9d85-42c49 0/1 ContainerCreating 0 40s
有些 Pod 需要比其他 Pod 更多的时间才能启动并运行,但在几分钟内,所有内容都应已部署,并且所有 Pod 都应处于 `READY` 状态。
$ kubectl -n storage-gluster get pods
NAME READY STATUS RESTARTS AGE
glusterfile-provisioner-dbcbf54fc-726vv 1/1 Running 0 5m
glusterfs-rvdmz 1/1 Running 0 4m
heketi-79997b9d85-42c49 1/1 Running 1 4m
一旦 Pod 状态为 `Running`,`glusterfile` StorageClass 就应该被标记为 `default`。
$ kubectl get sc
NAME PROVISIONER AGE
glusterfile (default) gluster.org/glusterfile 3m
创建 PVC
Gluster 环境中的存储限制为 10 GiB。这是因为数据存储在 Minikube 虚拟机中(一个稀疏文件 `/srv/fake-disk.img`)。
以下 `yaml` 创建一个 PVC,启动一个 CentOS 开发 Pod 以生成网站,并部署一个 NGINX Web 服务器以提供对网站的访问。
---
#
# Minimal PVC where a developer can build a website.
#
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: website
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Mi
storageClassName: glusterfile
---
#
# This pod will just download a fortune phrase and store it (as plain text) in
# index.html on the PVC. This is how we create websites?
#
# The root of the website stored on the above PVC is mounted on /mnt.
#
apiVersion: v1
kind: Pod
metadata:
name: centos-webdev
spec:
containers:
- image: centos:latest
name: centos
args:
- curl
- -o/mnt/index.html
- https://api.ef.gy/fortune
volumeMounts:
- mountPath: /mnt
name: website
# once the website is created, the pod will exit
restartPolicy: Never
volumes:
- name: website
persistentVolumeClaim:
claimName: website
---
#
# Start a NGINX webserver with the website.
# We'll skip creating a service, to keep things minimal.
#
apiVersion: v1
kind: Pod
metadata:
name: website-nginx
spec:
containers:
- image: gcr.io/google_containers/nginx-slim:0.8
name: nginx
ports:
- containerPort: 80
name: web
volumeMounts:
- mountPath: /usr/share/nginx/html
name: website
volumes:
- name: website
persistentVolumeClaim:
claimName: website
由于 PVC 是通过 `ReadWriteMany` 访问模式创建的,因此两个 Pod 可以同时访问该 PVC。其他网站开发 Pod 可以使用相同的 PVC 更新网站内容。
上述配置不会在 Minikube VM 上公开网站。查看网站内容的一种方法是 SSH 连接到 Minikube VM 并在那里获取网站。
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
centos-webdev 0/1 Completed 0 1m 172.17.0.9 minikube
website-nginx 1/1 Running 0 24s 172.17.0.9 minikube
$ minikube ssh
_ _
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ curl http://172.17.0.9
I came, I saw, I deleted all your files.
$