kubernetes - 如何找到我的持久卷位置

标签 kubernetes persistent-volumes kubernetes-pvc

我尝试使用主机路径创建持久卷。我可以使用节点亲和性将其绑定(bind)到特定节点,但我没有提供这一点。我的持久卷 YAML 如下所示

apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins
  labels:
    type: fast
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  hostPath:
    path: /mnt/data

在此之后我创建了PVC

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 1Gi

最后将其连接到 pods 上。

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
    - name: myfrontend
      image: thinkingmonster/nettools
      volumeMounts:
        - mountPath: "/var/www/html"
          name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: myclaim

现在,在 pv 或 pvc 的描述命令中,它不会告诉它实际上在哪个节点上保存了卷/mnt/data

我必须通过 ssh 连接到所有节点才能找到相同的位置。

并且 pod 足够智能,只能在 Kubernetes 将主机目录映射到 PV 的节点上创建

如何知道 Kubernetes 在哪个节点上创建了持久卷?无需 ssh 节点或检查 pod 在哪里运行。

最佳答案

仅当卷绑定(bind)到与特定节点关联的声明时。 HostPath 卷与常规排序略有不同,因此不太清晰。当您获得卷声明时,其上的注释应该为您提供大量信息,包括您要查找的内容。特别是,寻找:

volume.kubernetes.io/selected-node: ${NODE_NAME}

PVC 上的注释。您可以通过向 Kubernetes api 服务器询问该信息来查看注释以及其他计算配置:

kubectl get pvc -o yaml -n ${NAMESPACE} ${PVC_NAME}

关于kubernetes - 如何找到我的持久卷位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62034907/

相关文章:

ssl - 使用 HAProxy 入口 Controller 时,TLS 握手间歇性失败

amazon-web-services - 节点缩放后的 K8s StatfullSets "pending"

kubernetes - 有没有一种有效的方法来检查Kubernetes中PV/PVC的使用情况

Kubernetes:无法删除 PersistentVolumeClaim (pvc)

kubernetes - 如何手动恢复 PV

kubernetes - 将2个不同的有状态集连接到同一PV

Azure Durable Function HttpStart 失败 : Webhooks are not configured

docker - standard_init_linux.go :178: exec user process caused "exec format error" kubernetes

elasticsearch - 如何在 K8S 中没有部署的情况下重启 Pod?

kubernetes - 在 Kubernetes 集群中跨上下文移动资源/卷