在Kubernetes中无蓝插件部署



根据这个源代码,我可以通过以下方式存储到my/data/folder:

docker run -d -p 80:80 -v {/my/data/folder}:/data bluespice/bluespice-free

我已经创建了以下部署,但不确定如何使用持久卷。

apiVersion: apps/v1
kind: Deployment
metadata:
name: bluespice
namespace: default
labels:
app: bluespice
spec:
replicas: 1
selector:
matchLabels:
app: bluespice
template:
metadata:
labels:
app: bluespice
spec:
containers:
- name: bluespice
image: bluespice/bluespice-free
ports:
- containerPort: 80
env:
- name: bs_url
value: "https://bluespice.mycompany.local"

我的持久卷声明名称是bluespice-pvc

我还部署了没有持久卷的pod。我可以动态地附加持久卷来保存数据吗?

如果要挂载本地目录,则不必处理PVC,因为您不能在persistentvolumecclaim中强制使用特定的主机路径。对于本地测试,您可以使用hostPath如文档中所述:

hostPath卷将一个文件或目录从主机节点的文件系统挂载到Pod中。这不是大多数pod需要的东西,但它为某些应用程序提供了一个强大的逃生舱口。例如,hostPath的一些用途是:

  • 正在运行一个需要访问Docker内部组件的容器;使用/var/lib/dockerhostPath
  • 在容器中运行cAdvisor;使用/syshostPath
  • 允许Pod指定给定的hostPath是否应该在Pod运行之前存在,是否应该创建它,以及它应该作为什么存在除了必需的path属性,您还可以选择为hostPath卷指定type

hostPath配置示例:

apiVersion: apps/v1
kind: Deployment
metadata:
name: bluespice
namespace: default
labels:
app: bluespice
spec:
replicas: 1
selector:
matchLabels:
app: bluespice
template:
metadata:
labels:
app: bluespice
spec:
containers:
- image: bluespice/bluespice-free
name: bluespice
volumeMounts:
- mountPath: /data
name: bluespice-volume
volumes:
- name: bluespice-volume
hostPath:
# directory location on host
path: /my/data/folder
# this field is optional
type: Directory

然而,如果你想转移到生产集群,你应该考虑更可靠的选择,因为允许HostPaths缺乏安全性,而且它不便携:

HostPath卷存在许多安全风险,最好在可能的情况下避免使用HostPath。当必须使用HostPath卷时,应该将其范围限定为所需的文件或目录,并将其挂载为只读。如果通过AdmissionPolicy限制HostPath对特定目录的访问,必须要求volumeMounts使用readOnly挂载才能使策略生效。

有关PersistentVolumes的更多信息,您可以查看Kubernetes官方文档

APersistentVolume(PV)是集群中由管理员发放或使用存储类动态发放的一块存储。它是集群中的资源,就像节点是集群资源一样。PV是像Volumes一样的卷插件,但其生命周期独立于使用PV的任何单个Pod。此API对象捕获存储实现的细节,可以是NFS、iSCSI或特定于云提供商的存储系统。

Apersistentvolumecclaim(PVC)是用户对存储的请求。它类似于Pod。pod消耗节点资源,pvc消耗PV资源。pod可以请求特定级别的资源(CPU和内存)。声明可以请求特定的大小和访问模式(例如,它们可以挂载ReadWriteOnce, ReadOnlyMany或ReadWriteMany,参见AccessModes)。

因此,我建议使用一些云解决方案,如GCP或AWS,或者至少直接从Kubernetes使用NFS共享。也可以在StackOverFlow上查看这个主题。

关于你的最后一个问题:动态地附加持久音量是不可能的。

最新更新