【问题标题】:Issue on creating PV volumes on GKE using access modes使用访问模式在 GKE 上创建 PV 卷的问题
【发布时间】:2021-01-11 17:47:48
【问题描述】:

我有一个在 Google Cloud 上运行的 GKE 集群。我创建了一个持久性卷并挂载了我的部署,因此我的应用程序和持久性之间的连接已成功绑定。

我也使用下面的链接https://github.com/elastic/beats/blob/master/deploy/kubernetes/filebeat-kubernetes.yaml在同一个集群上运行filebeat

应用程序和 filebeat 也都安装成功。 PV 卷是使用 GCE 中的 访问模式:ReadWriteOnce 创建的。但是我的集群有许多节点正在运行,并且我的应用程序没有为所有正在运行的 pod 安装。在 google Cloud PV 卷中不支持 访问模式:ReadWriteMany。因此,由于应用程序未正确安装,我的 filebeat 也失败了,并且 filebeat 具有使用 deamonset 在许多节点上运行的能力。有没有办法解决上述问题。

【问题讨论】:

  • 我已经发布了关于 FileBeat 的答案(它使用不同于应用程序的卷)。您的应用程序需要卷的原因是什么?这仅用于记录吗?提示:他们应该登录到 stdout

标签: google-kubernetes-engine filebeat persistent-volumes


【解决方案1】:

FileBeat 使用的音量应该与音量稍有不同。通常应用程序会记录到 stdout,然后 container runtime(例如 Docker 守护程序或 containerd)将日志保存在本地节点上。

FileBeat 需要在每个节点上运行,因此应如您所说使用DaemonSet 进行部署。但它也应该使用hostPath 卷从节点挂载卷。

查看您链接的DaemonSet 的这一部分(此处未使用持久卷):

      volumes:
      - name: config
        configMap:
          defaultMode: 0640
          name: filebeat-config
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers
      - name: varlog
        hostPath:
          path: /var/log
      # data folder stores a registry of read status for all files, so we don't send everything again on a Filebeat pod restart
      - name: data
        hostPath:
          # When filebeat runs as non-root user, this directory needs to be writable by group (g+w).
          path: /var/lib/filebeat-data
          type: DirectoryOrCreate

【讨论】:

    【解决方案2】:

    您想要实现访问模式:ReadWriteMany 是的,有一些选项,例如您可以使用 NFS 或 Gluster FS 集群。

    如果您只想读取选项,您可以添加磁盘 PD:https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/readonlymany-disks 访问模式将是:readonlymany

    您可以使用文件存储:https://cloud.google.com/kubernetes-engine/docs/concepts/persistent-volumes

    您还可以使用云卷服务:https://cloud.google.com/solutions/partners/netapp-cloud-volumes/overview (NFS & SMB)

    如果你只想要readonlymany,你可以使用磁盘,但是如果你想执行写操作,你也必须使用 NFS。

    Cloud Filestore 示例:

    首先创建一个 Filestore 实例。

    gcloud filestore instances create nfs-server
        --project=[PROJECT_ID]
        --zone=us-central1-c
        --tier=STANDARD
        --file-share=name="vol1",capacity=1TB
        --network=name="default",reserved-ip-range="10.0.0.0/29"
    

    然后在 GKE 中创建一个持久化卷。

        apiVersion: v1
    kind: PersistentVolume
    metadata:
     name: fileserver
    spec:
     capacity:
       storage: storage
     accessModes:
     - ReadWriteMany
     nfs:
       path: /file-share
       server: ip-address
    

    [IP_ADDRESS] 将在文件存储控制台中可用。

    现在创建持久卷声明。

        apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
     name: fileserver-claim
    spec:
     accessModes:
     - ReadWriteMany
     storageClassName: ""
     volumeName: fileserver
     resources:
       requests:
         storage: storage
    

    最后,将卷挂载到您的 pod 中。

    apiVersion: v1
    kind: Pod
    metadata:
     name: my-pod
    spec:
     containers:
     - name: container-name
       image: image-name
       volumeMounts:
       - mountPath: mount-path
         name: mypvc
     volumes:
     - name: mypvc
       persistentVolumeClaim:
         claimName: claim-name
         readOnly: false
    

    文档:https://cloud.google.com/filestore/docs/accessing-fileshares

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      • 2017-10-27
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      相关资源
      最近更新 更多