我们配置了EKS设置,其中我们使用基于云原生Buildpacks的Tekton Pipeline,我们的
PipelineRuns
在没有获得Pod资源的情况下永远卡住并挂起。我们创建了一个像这样的 PersistentVolumeClaim:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: buildpacks-source-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
创建后查看此 PVC 的事件,有以下事件表明我们的 EKS 设置出现问题:
命令
kubectl describe pvc buildpacks-source-pvc
给出以下事件消息:
Name: buildpacks-source-pvc
Namespace: default
StorageClass: gp2
Status: Pending
Volume:
Labels: <none>
Annotations: volume.beta.kubernetes.io/storage-provisioner: ebs.csi.aws.com
volume.kubernetes.io/selected-node: ip-999-99-99-99.eu-central-1.compute.internal
volume.kubernetes.io/storage-provisioner: ebs.csi.aws.com
Finalizers: [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode: Filesystem
Used By: affinity-assistant-0b3d266b91-0
affinity-assistant-53a7c08baf-0
affinity-assistant-a375f28de3-0
affinity-assistant-e8cb1a6e15-0
buildpacks-test-pipeline-run-9rz4l-fetch-repository-pod
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ExternalProvisioning 3m43s (x561 over 143m) persistentvolume-controller waiting for a volume to be created, either by external provisioner "ebs.csi.aws.com" or manually created by system administrator
EBS CSI 是什么?我们如何让集群像以前一样工作?
从 EKS 1.23 开始,需要 容器存储接口 (CSI) 驱动程序,以便让 PersisentVolumeClaims 由 PersisentVolume 提供服务,就像您在早期 EKS 版本中所习惯的那样。
文档告诉我们,需要配置什么:
本质上,我们需要启用 AWS EBS CSI 驱动程序作为 EKS 插件。但事先我们需要启用 IAM OIDC 提供程序并为 EBS CSI 驱动程序创建 IAM 角色。实现这两者的最简单方法是使用 eksctl(文档中描述了其他方法,例如 使用普通
aws
cli 或 AWS GUI)。
1.) 安装 eksctlaws cli 已安装并配置 - 并且您可以访问 EKS 集群。要使用eksctl
,我们需要先安装它。在Mac上使用brew,例如:
brew tap weaveworks/tap
brew install weaveworks/tap/eksctl
或在 Linux 上使用:
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
2.) 启用 IAM OIDC 提供商
eksctl utils associate-iam-oidc-provider --region=eu-central-1 --cluster=YourClusterNameHere --approve
3.) 创建 Amazon EBS CSI 驱动程序 IAM 角色eksctl
就位,创建 IAM 角色:
eksctl create iamserviceaccount \
--name ebs-csi-controller-sa \
--namespace kube-system \
--cluster YourClusterNameHere \
--attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
--approve \
--role-only \
--role-name AmazonEKS_EBS_CSI_DriverRole
如您所见,AWS 为我们维护了一个托管策略,我们可以简单地使用 (AWS maintains a managed policy, available at ARN arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy
)。仅当您使用加密的 EBS 驱动器时您需要另外向策略添加配置。 命令...
...部署一个创建 IAM 角色的 AWS CloudFormation 堆栈, 将 IAM 策略附加到其上,并注释现有的 具有 Amazon 资源名称的 ebs-csi-controller-sa 服务账户 IAM 角色的 (ARN)。4.) 添加 Amazon EBS CSI 插件
aws sts get-caller-identity --query Account --output text
获取该 ID(请参阅从 AWS CLI 工具获取 AWS 账户号的快速方法?)。现在
eksctl create addon
命令如下所示:
eksctl create addon --name aws-ebs-csi-driver --cluster YourClusterNameHere --service-account-role-arn arn:aws:iam::$(aws sts get-caller-identity --query Account --output text):role/AmazonEKS_EBS_CSI_DriverRole --force
现在,当为您创建 EBS 卷时,您的 PersistentVolumeClaim 应该获得状态 Bound
- 并且 Tekton Pipeline 应该再次运行。
这是我的存储类来解决这种情况:但是 pvc 正在等待,我看到这个错误:
I0820 06:57:02.797899 1 事件.go:298] 事件(v1.ObjectReference{种类:“PersistentVolumeClaim”, 命名空间:“default”,名称:“mysql-pvc”, UID:“9b27cbd2-2d11-4241-8abe-aad64f9e1949”,API版本:“v1”, ResourceVersion:“33859”,FieldPath:“”}):类型:“警告”原因: “ProvisioningFailed”无法使用 StorageClass 配置卷 “ebs-storage-class”:生成可访问性要求时出错: 选定的拓扑图[topology.ebs.csi.aws.com/zone:us-west-2b] 节点“ip-172-31-21-41.us-west-2.compute.internal”不是必需的: [地图[topology.kubernetes.io/zone:us-west-2a] 地图[topology.kubernetes.io/zone:us-west-2b] 地图[topology.kubernetes.io/zone:us-west-2c] 地图[topology.kubernetes.io/zone:us-west-2d]]
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: ebs-storage-class # The name of the StorageClass.
provisioner: ebs.csi.aws.com # The name of the AWS CSI driver.
volumeBindingMode: WaitForFirstConsumer
parameters:
csi.storage.k8s.io/fstype: xfs # The filesystem type to format the volume.
type: gp2 # The type of AWS EBS volume.
#reclaimPolicy: Retain
allowedTopologies:
- matchLabelExpressions:
- key: failure-domain.beta.kubernetes.io/zone
values:
- us-west-2a
- us-west-2b
- us-west-2c
- us-west-2d
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
labels:
app: xyz
tier: mysql
spec:
accessModes:
- ReadWriteOnce
storageClassName: ebs-storage-class
resources:
requests:
storage: 2Gi