gpt4 book ai didi

kubernetes - Kubernetes自己机架上的持久卷

转载 作者:行者123 更新时间:2023-12-02 11:37:48 26 4
gpt4 key购买 nike

我将kubernetes从Google GKE移到了自己的机架中。我应该使用什么持久性存储?

Kubernetes Local Persistent仅在2018年4月13日成为beta版本
https://kubernetes.io/blog/2018/04/13/local-persistent-volumes-beta/

我看到了很多选择:
https://kubernetes.io/docs/concepts/storage/persistent-volumes/#types-of-persistent-volumes

不知道该选择什么。 GKE部署文件会解决一些问题吗?

最佳答案

在GKE的部署文件中,您需要根据“持久卷”设置更改spec.volumes设置。

我建议您选择以下选项之一:

  • 最简单的方法是使用HostPath。它将主机节点文件系统中的文件或目录装载到Pod中。请注意,在这种情况下,如果没有其他配置,则无法从另一个节点访问一个节点上的数据。 Kubernetes中的用法示例:
    apiVersion: v1
    kind: Pod
    metadata:
    name: test-pd
    spec:
    containers:
    - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
    name: test-volume
    volumes:
    - name: test-volume
    hostPath:
    # directory location on host
    path: /data
    # this field is optional
    type: Directory
  • 您可以使用NFS。您需要配置NFS服务器,然后可以通过持久卷声明在“部署”中使用其卷。 Kubernetes中的用法示例:
    apiVersion: v1
    kind: Deployment
    metadata:
    name: nfs-busybox
    spec:
    replicas: 2
    selector:
    name: nfs-busybox
    template:
    metadata:
    labels:
    name: nfs-busybox
    spec:
    containers:
    - image: busybox
    command:
    - sh
    - -c
    - 'while true; do date > /mnt/index.html; hostname >> /mnt/index.html; sleep $(($RANDOM % 5 + 5)); done'
    imagePullPolicy: IfNotPresent
    name: busybox
    volumeMounts:
    # name must match the volume name below
    - name: nfs
    mountPath: "/mnt"
    volumes:
    - name: nfs
    persistentVolumeClaim:
    claimName: nfs

    您可以浏览link以获取有关使用NFS的更多信息。
  • 您可以使用GlusterFS。您需要配置自己的GlusterFS安装,然后才能在Deployments中使用其卷。 Kubernetes中的用法示例:
    apiVersion: v1
    kind: Deployment
    metadata:
    name: nfs-busybox
    spec:
    replicas: 2
    selector:
    name: nfs-busybox
    template:
    metadata:
    labels:
    name: nfs-busybox
    spec:
    containers:
    - image: busybox
    command:
    - sh
    - -c
    - 'while true; do date > /mnt/index.html; hostname >> /mnt/index.html; sleep $(($RANDOM % 5 + 5)); done'
    imagePullPolicy: IfNotPresent
    name: busybox
    volumeMounts:
    # name must match the volume name below
    - name: nfs
    mountPath: "/mnt"
    volumes:
    - name: glusterfsvol
    glusterfs:
    endpoints: glusterfs-cluster
    path: kube_vol
    readOnly: true

    您可以浏览link以获取有关使用GlusterFS的更多信息。

  • 您可以找到有关持久卷和持久卷声明 here的更多信息。

    关于kubernetes - Kubernetes自己机架上的持久卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51176145/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com