【问题标题】:Deploying bluespice-free in Kubernetes在 Kubernetes 中部署无 bluespice
【发布时间】:2021-09-16 05:55:47
【问题描述】:

根据this source,我可以通过以下方式存储到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。我可以即时附加持久卷以保存数据吗?

【问题讨论】:

    标签: docker kubernetes persistent-volumes


    【解决方案1】:

    如果你想挂载一个本地目录,你不必处理PVC,因为you can't force a specific host path in a PersistentVolumeClaim。对于本地测试,您可以使用 hostPath,如 documentation 中所述:

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

    • 运行需要访问 Docker 内部的容器;使用hostPath/var/lib/docker
    • 在容器中运行 cAdvisor;使用hostPath/sys
    • 允许 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 的更多信息,您可以查看official Kubernetes documents

    PersistentVolume (PV) 是集群中的一块存储,由管理员配置或使用 Storage Classes 动态配置。它是集群中的资源,就像节点是集群资源一样。 PV 是与 Volumes 类似的卷插件,但其生命周期独立于使用 PV 的任何单个 Pod。此 API 对象捕获存储实现的详细信息,无论是 NFS、iSCSI 还是特定于云提供商的存储系统。

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

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

    关于您的最后一个问题:it's impossible to attach Persistent Volume on the fly

    【讨论】:

      猜你喜欢
      • 2018-10-10
      • 2021-11-27
      • 2021-02-22
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 2020-09-13
      • 2016-04-18
      • 1970-01-01
      相关资源
      最近更新 更多