繁体   English   中英

Kubernetes / kops:将EBS卷附加到实例时出错。 您无权执行此操作。 错误403

[英]Kubernetes/kops: error attaching EBS volume to instance. You are not authorized to perform this operation. Error 403

我在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> ,我在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操作。 所以我添加了AttachVolumeDetachVolume动作:

    {
        "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.

我错过了什么吗?

我找到了解决方案。 在这里描述。

在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 - > Volumes - > Your volume - > Tags手动标记它

而已。

编辑:

可以在作为群集一部分的EC2实例标记中找到正确的群集名称。 关键是相同的: KubernetesCluster

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM