我在kops配置的AWS群集上测试了kubernetes部署和EBS卷安装。这是部署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>
之后,我在广告连播描述中收到以下消息:
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
的政策 - &gt; Roles
- &gt; 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.
我错过了什么吗?
答案 0 :(得分:16)
我找到了解决方案。它描述了here。
在kops 1.8.0-beta.1中,主节点要求您使用以下标记标记AWS卷:
KubernetesCluster
:<clustername-here>
因此,使用awscli
创建带有该标记的EBS卷是必要的:
aws ec2 create-volume --size 10 --region eu-central-1 --availability-zone eu-central-1a --volume-type gp2 --tag-specifications 'ResourceType=volume,Tags=[{Key=KubernetesCluster,Value=<clustername-here>}]'
或者您可以在EC2
- &gt;中手动标记。 Volumes
- &gt; Your volume
- &gt; Tags
那就是它。