使用存储 Provisioner 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 VM 中(一个稀疏文件 /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
accessMode 创建的,所以两个 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.
$