我正在尝试创建一个Kubernetes部署,其中包含一个关联的ServiceAccount,即linked to an AWS IAM role。此yaml将生成所需的结果,并且相关的部署(包括在底部)将正确启动:
apiVersion: v1
kind: ServiceAccount
metadata:
name: service-account
namespace: example
annotations:
eks.amazonaws.com/role-arn: ROLE_ARN但是,我想使用Terraform Kubernetes提供程序来创建ServiceAccount:
resource "kubernetes_service_account" "this" {
metadata {
name = "service-account2"
namespace = "example"
annotations = {
"eks.amazonaws.com/role-arn" = "ROLE_ARN"
}
}
}不幸的是,当我以这种方式创建ServiceAccount时,我的部署的ReplicaSet失败,并显示以下错误:
Error creating: Internal error occurred: Internal error occurred: jsonpatch add operation does not apply: doc is missing path: "/spec/volumes/0"我已经确认部署是通过Terraform还是通过kubectl创建的并不重要;它不适用于Terraform创建的service-account2,但适用于kubectl-created service-account。在service-account和service-account2之间来回切换部署会相应地决定它是否像您预期的那样工作。
我还确定了eks.amazonaws.com/role-arn是相关的;创建/分配不试图链接回IAM角色工作的ServiceAccounts,无论它们是通过Terraform还是通过kubectl创建的。
使用kubectl来描述部署、ReplicaSet、ServiceAccount和相关的秘密,我看不到任何明显的区别,尽管我承认我不完全确定我可能在寻找什么。
下面是一个简单的yaml部署,它展示了这个问题:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: example
namespace: example
spec:
strategy:
type: Recreate
template:
metadata:
labels:
app: example
spec:
serviceAccountName: service-account # or "service-account2"
containers:
- name: nginx
image: nginx:1.7.8发布于 2019-11-12 01:55:19
将automountServiceAccountToken: true添加到部署中的pod规范应该可以修复此错误。这通常是在服务帐户上默认启用的,但Terraform默认将其设置为关闭。在将所需环境变量添加到pods中的变异web钩子上可以看到此问题:https://github.com/aws/amazon-eks-pod-identity-webhook/issues/17
发布于 2020-05-19 21:29:54
我也遇到过同样的问题,我在terraform kubernetes服务帐户资源中指定了automount_service_account_token = true解决了这个问题。
尝试创建以下服务帐户:
resource "kubernetes_service_account" "this" {
metadata {
name = "service-account2"
namespace = "example"
annotations = {
"eks.amazonaws.com/role-arn" = "ROLE_ARN"
}
}
automount_service_account_token = true
}https://stackoverflow.com/questions/58760572
复制相似问题