Kubernetes Failed to Create PersistentVolumeClaim on AWS-EBS

9/10/2019

I setup a Kubernetes cluster with four EC2 instances using kubeadm. The Kubernetes cluster works fine, but failed when I try to create a PersistentVolumeClaim.

First I created a StorageClass with following YAML which works fine.

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: generic
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
  encrypted: "false"

Then I try to create a PersistentVolumeClaim with the following YAML:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: slow
  labels:
    app: nginx
spec:
  storageClassName: generic
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi

enter image description here

Which got an error message of:

Failed to provision volume with StorageClass "generic": Failed to get AWS Cloud Provider. GetCloudProvider returned <nil> instead

By the way, it seems no PersistentVolume was ever created.

kubectl get pv
No resources found.

Any ideas how to solve this?

Thanks.

-- user1828513
amazon-web-services
kubernetes
persistent-volumes

1 Answer

9/10/2019

This is because you didn't use the option --cloud-provider=aws while running kubeadm init

kubeadm --cloud-provider=aws init ...

Alternatively, you should put the cloud provider info ( cloudProvider ) into your config file and it will add the cloud provider flag to api and controller manager during initialization :

apiVersion: kubeadm.k8s.io/v1alpha1
kind: MasterConfiguration
etcd:
  endpoints:
  - "http://my-etcd1"
  - "http://my-etcd2"
  - "http://my-etcd3"
cloudProvider: aws
apiServerExtraArgs:
  apiserver-count: 3
apiServerCertSANs:
- "my-master-hostname1"
- "my-master-hostname2"
- "my-master-hostname3"
- "10.10.0.50"
- "10.10.0.51"
- "10.10.0.52"
- "127.0.0.1"
token: "my-kube-token"
tokenTTL: "0"

More info : https://medium.com/jane-ai-engineering-blog/kubernetes-on-aws-6281e3a830fe

-- Abdennour TOUMI
Source: StackOverflow