K8S无法将AWS EBS挂载为pod

时间:2017-12-31 04:19:00

标签: amazon-web-services kubernetes persistent-volumes

问题

请建议无法在pod中安装AWS EBS卷的错误原因。

journalctl -b -f -u kubelet

1480 kubelet.go:1625] Unable to mount volumes for pod "nginx_default(ddc938ee-edda-11e7-ae06-06bb783bb15c)": timeout expired waiting for volumes to attach/mount for pod "default"/"nginx". list of unattached/unmounted volumes=[ebs]; skipping pod
1480 pod_workers.go:186] Error syncing pod ddc938ee-edda-11e7-ae06-06bb783bb15c ("nginx_default(ddc938ee-edda-11e7-ae06-06bb783bb15c)"), skipping: timeout expired waiting for volumes to attach/mount for pod "default"/"nginx". list of unattached/unmounted volumes=[ebs]
1480 reconciler.go:217] operationExecutor.VerifyControllerAttachedVolume started for volume "pv-ebs" (UniqueName: "kubernetes.io/aws-ebs/vol-0d275986ce24f4304") pod "nginx" (UID: "ddc938ee-edda-11e7-ae06-06bb783bb15c")
1480 nestedpendingoperations.go:263] Operation for "\"kubernetes.io/aws-ebs/vol-0d275986ce24f4304\"" failed. No retries permitted until 2017-12-31 03:34:03.644604131 +0000 UTC m=+6842.543441523 (durationBeforeRetry 2m2s). Error: "Volume not attached according to node status for volume \"pv-ebs\" (UniqueName: \"kubernetes.io/aws-ebs/vol-0d275986ce24f4304\") pod \"nginx\" (UID: \"ddc938ee-edda-11e7-ae06-06bb783bb15c\") "

的步骤

  1. 在AWS中使用kubeadm(没有EBS卷装,pod工作)部署K8S 1.9(us-west-1和AZ是us-west-1b)。
  2. 根据Kubernetes - Cloud Providerskubelets failing to start when using 'aws' as cloud provider配置IAM角色。
  3. 根据Easily Replace or Attach an IAM Role to an Existing EC2 Instance by Using the EC2 Console将IAM角色分配给EC2实例。
  4. 在清单中部署PV / PVC / POD。
  5. 来自kubectl的状态:

    kubectl get

    NAME      READY     STATUS              RESTARTS   AGE       IP        NODE
    nginx     0/1       ContainerCreating   0          29m       <none>    ip-172-31-1-43.us-west-1.compute.internal
    
    NAME        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS    CLAIM             STORAGECLASS   REASON    AGE
    pv/pv-ebs   5Gi        RWO            Recycle          Bound     default/pvc-ebs                            33m
    
    NAME          STATUS    VOLUME    CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    pvc/pvc-ebs   Bound     pv-ebs    5Gi        RWO                           33m
    

    kubectl描述pod nginx

    Events:
      Type     Reason                 Age                From                                                Message
      ----     ------                 ----               ----                                                -------
      Normal   Scheduled              27m                default-scheduler                                   Successfully assigned nginx to ip-172-31-1-43.us-west-1.compute.internal
      Normal   SuccessfulMountVolume  27m                kubelet, ip-172-31-1-43.us-west-1.compute.internal  MountVolume.SetUp succeeded for volume "default-token-dt698"
      Warning  FailedMount            6s (x12 over 25m)  kubelet, ip-172-31-1-43.us-west-1.compute.internal  Unable to mount volumes for pod "nginx_default(ddc938ee-edda-11e7-ae06-06bb783bb15c)": timeout expired waiting for volumes to attach/mount for pod "default"/"nginx".                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Warning  FailedMount            6s (x12 over 25m)  kubelet, ip-172-31-1-43.us-west-1.compute.internal  Unable to mount volumes for pod "nginx_default(ddc938ee-edda-11e7-ae06-06bb783bb15c)": timeout expired waiting for volumes to attach/mount for pod "default"/"nginx".
    

    清单

    ---
    kind: PersistentVolume
    apiVersion: v1
    metadata:
      name: pv-ebs
      labels:
        type: amazonEBS
    spec:
      capacity:
        storage: 5Gi
      accessModes:
        - ReadWriteOnce
      awsElasticBlockStore:
        volumeID: vol-0d275986ce24f4304
        fsType: ext4
      persistentVolumeReclaimPolicy: Recycle
    ---
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: pvc-ebs
      labels:
        type: amazonEBS
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
    ---
    kind: Pod
    apiVersion: v1
    metadata:
      name: nginx
    spec:
      containers:
        - name: myfrontend
          image: nginx
          volumeMounts:
          - mountPath: "/var/www/html"
            name: ebs
      volumes:
        - name: ebs
          persistentVolumeClaim:
            claimName: pvc-ebs
    

    IAM政策

    enter image description here

    环境

    $ kubectl version -o json
    {
      "clientVersion": {
        "major": "1",
        "minor": "9",
        "gitVersion": "v1.9.0",
        "gitCommit": "925c127ec6b946659ad0fd596fa959be43f0cc05",
        "gitTreeState": "clean",
        "buildDate": "2017-12-15T21:07:38Z",
        "goVersion": "go1.9.2",
        "compiler": "gc",
        "platform": "linux/amd64"
      },
      "serverVersion": {
        "major": "1",
        "minor": "9",
        "gitVersion": "v1.9.0",
        "gitCommit": "925c127ec6b946659ad0fd596fa959be43f0cc05",
        "gitTreeState": "clean",
        "buildDate": "2017-12-15T20:55:30Z",
        "goVersion": "go1.9.2",
        "compiler": "gc",
        "platform": "linux/amd64"
      }
    }
    
    $ cat /etc/centos-release
    CentOS Linux release 7.4.1708 (Core) 
    

    EC2

    enter image description here

    EBS

    enter image description here

1 个答案:

答案 0 :(得分:0)

解决方案

找到显示如何配置AWS云提供商的文档。

步骤

  1. 使用 KubernetesCluster = $ {kubernetes群集名称} 标记EC2实例和SG。如果使用kubeadm创建,则 kubernetes Ability to configure user and cluster name in AdminKubeConfigFile
  2. 一样
  3. 运行 kubeadm init --config kubeadm.yaml
  4. kubeadm.yaml(Ansible模板)

    library(dplyr)
    df %>% 
       group_by(user_id) %>% 
       mutate(new_rank1 = lag(cumsum(matric_1 > 15 & matric_2 > 20) + 1, default = 1))
    # A tibble: 16 x 5
    # Groups: user_id [4]
    #   user_id matric_1 matric_2 new_rank new_rank1
    #   <fctr>     <dbl>    <dbl>    <dbl>     <dbl>
    # 1 a          10.0     10.0      1.00      1.00
    # 2 a          23.0     25.0      1.00      1.00
    # 3 a           4.00    10.0      2.00      2.00
    # 4 a           5.00    13.0      2.00      2.00
    # 5 b          17.0     21.0      1.00      1.00
    # 6 b           5.00    10.0      2.00      2.00
    # 7 b          40.0      7.00     2.00      2.00
    # 8 c           1.00     3.00     1.00      1.00
    # 9 c           2.00     4.00     1.00      1.00
    #10 c          18.0     22.0      1.00      1.00
    #11 c          19.0     21.0      2.00      2.00
    #12 c           5.00     4.00     3.00      3.00
    #13 d          18.0     23.0      1.00      1.00
    #14 d           2.00     4.00     2.00      2.00
    #15 d          19.0     21.0      2.00      2.00
    #16 d           2.00     4.00     3.00      3.00
    

    结果

    kind: MasterConfiguration
    apiVersion: kubeadm.k8s.io/v1alpha1
    api:
      advertiseAddress: {{ K8S_ADVERTISE_ADDRESS }}
    networking:
      podSubnet:        {{ K8S_SERVICE_ADDRESSES }}
    cloudProvider:      {{ K8S_CLOUD_PROVIDER }}