我在 kops 配置的 AWS 集群上测试了使用 EBS 卷挂载的 kubernetes 部署。这是部署 yml 文件:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: helloworld-deployment-volume
spec:
replicas: 1
template:
metadata:
labels:
app: helloworld
spec:
containers:
- name: k8s-demo
image: wardviaene/k8s-demo
ports:
- name: nodejs-port
containerPort: 3000
volumeMounts:
- mountPath: /myvol
name: myvolume
volumes:
- name: myvolume
awsElasticBlockStore:
volumeID: <volume_id>
之后kubectl create -f <path_to_this_yml>
,我在 pod 描述中收到以下消息:
Attach failed for volume "myvolume" : Error attaching EBS volume "XXX" to instance "YYY": "UnauthorizedOperation: You are not authorized to perform this operation. status code: 403
看起来这只是一个权限问题。好的,我检查了节点角色的策略IAM
-> Roles
->nodes.<my_domain>
并发现没有允许操作卷的ec2:DescribeInstances
操作,默认情况下只有操作。所以我添加了AttachVolume
操作DetachVolume
:
{
"Sid": "kopsK8sEC2NodePerms",
"Effect": "Allow",
"Action": [
"ec2:DescribeInstances",
"ec2:AttachVolume",
"ec2:DetachVolume"
],
"Resource": [
"*"
]
},
这没有帮助。我仍然收到该错误:
Attach failed for volume "myvolume" : Error attaching EBS volume "XXX" to instance "YYY": "UnauthorizedOperation: You are not authorized to perform this operation.
我错过了什么吗?