Kubernetes pod因无效卷区域不匹配而失败

vaj7vani  于 2024-01-06  发布在  Kubernetes
关注(0)|答案(3)|浏览(128)

我在EKS v 1.16中使用helm chart部署了一个jenkins服务。PV和PVC被意外删除,所以我重新创建了PV和PVC如下:
Pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-vol
spec:
  accessModes:
  - ReadWriteOnce
  awsElasticBlockStore:
    fsType: ext4
    volumeID: aws://us-east-2b/vol-xxxxxxxx
  capacity:
    storage: 120Gi
  claimRef:
    apiVersion: v1
    kind: PersistentVolumeClaim
    name: jenkins-ci
    namespace: ci
  persistentVolumeReclaimPolicy: Retain
  storageClassName: gp2
  volumeMode: Filesystem
status:
  phase: Bound

字符串
PVC.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jenkins-ci
  namespace: ci
spec:
  storageClassName: gp2
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 120Gi
  volumeMode: Filesystem
  volumeName: jenkins-vol
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 120Gi
  phase: Bound


kubectl describe sc gp2

Name:            gp2
IsDefaultClass:  Yes
Annotations:     kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"true"},"name":"gp2","namespace":""},"parameters":{"fsType":"ext4","type":"gp2"},"provisioner":"kubernetes.io/aws-ebs"}
,storageclass.kubernetes.io/is-default-class=true
Provisioner:           kubernetes.io/aws-ebs
Parameters:            fsType=ext4,type=gp2
AllowVolumeExpansion:  True
MountOptions:          <none>
ReclaimPolicy:         Delete
VolumeBindingMode:     Immediate
Events:                <none>


我面临的问题是,当pod被安排在与EBS卷不同的可用性区域中的节点上时,pod没有运行。

lhcgjxsq

lhcgjxsq1#

在部署文件中添加一个节点名,这将使其与所需可用性区域中的节点相匹配(在本例中为us-east-2b):

nodeSelector:
    topology.kubernetes.io/zone: us-east-2b

字符串

fdbelqdn

fdbelqdn2#

将以下标签添加到PersistentVolume。

labels:
    failure-domain.beta.kubernetes.io/region: us-east-2b
    failure-domain.beta.kubernetes.io/zone: us-east-2b

字符串
举例说明:

apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.beta.kubernetes.io/gid: "1000"
  labels:
    failure-domain.beta.kubernetes.io/region: us-east-2b
    failure-domain.beta.kubernetes.io/zone: us-east-2b
  name: test-pv-1
spec:
  accessModes:
  - ReadWriteOnce
  csi:
    driver: ebs.csi.aws.com
    fsType: xfs
    volumeHandle: vol-0d075fdaa123cd0e
  capacity:
    storage: 100Gi
  persistentVolumeReclaimPolicy: Retain
  volumeMode: Filesystem


使用上述标签,Pod将自动在卷所在的同一AZ中运行。

kx7yvsdv

kx7yvsdv3#

根据Persistent volume文档,kubernetes默认调度程序将使用PV定义中的nodeAffinity信息。
nodeAffinity定义了限制可以访问此卷的节点的约束。此字段影响使用此卷的Pod的调度。
链接到文档
这意味着您必须确保PV定义如下所示:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pvc-name
spec:
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: topology.ebs.csi.aws.com/zone
          operator: In
          values:
          - ap-south-1a
...

字符串
一般来说,这应该得到自动填充,但如果这是失踪,那么这是什么原因导致调度程序计划的节点上的卷不能附加的pod。
这里提到的标签来自节点标签之一。

apiVersion: v1
kind: Node
metadata:
  labels:
    ...
    topology.ebs.csi.aws.com/zone: ap-south-1a
    topology.kubernetes.io/region: ap-south-1
    topology.kubernetes.io/zone: ap-south-1a


希望这能帮上忙

相关问题