AttachVolume.NewAttacher 卷失败:无法获取 GCE GCECloudProvider,错误 <nil>

AttachVolume.NewAttacher failed for volume: Failed to get GCE GCECloudProvider with error <nil>

我在 GCE 上有两个 VM 实例,带有 kubernetes 自行安装(使用以下 https://medium.com/edureka/install-kubernetes-on-ubuntu-5cd1f770c9e4)。

我正在尝试创建卷并在我的 pods 中使用它。

我已经创建了以下磁盘:

gcloud compute disks create --type=pd-ssd --size=10GB manual-disk-1

并创建以下 yaml 文件

pv_manual.yaml:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: manually-created-pv
spec:
  accessModes:
  - ReadWriteMany
  capacity:
    storage: 10Gi
  persistentVolumeReclaimPolicy: Retain
  gcePersistentDisk:
    pdName: manual-disk-1

pvc_manual.yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mypvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 10Gi

pod.yaml:

apiVersion: v1
kind: Pod
metadata:
   name: sleppypod
spec:
   volumes:
     - name: data
       persistentVolumeClaim:
         claimName: mypvc
   containers:
     - name: sleppycontainer
       image: gcr.op/google_containers/busybox
       command:
         - sleep
         - "5000"
       volumeMounts:
         - name: data
           mountPath: /data
           readOnly: false

当我尝试创建 pod 时,pode 获得状态 ContainerCreating 并且在 kubectl get events 我看到:

7s Warning FailedAttachVolume AttachVolume.NewAttacher failed for volume : Failed to get GCE GCECloudProvider with error

我 运行 我的两个实例使用具有计算实例管理员角色的 ServiceAccount(根据 Kubernetes: Failed to get GCE GCECloudProvider with error <nil>)和我的 kubelet 运行 --cloud-provider=gce

我该如何解决?

您需要创建一个存储类

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
  name: standard
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-standard
  fstype: ext4
  replication-type: none

GCE 详情here

您也可以遵循 GCE 文档 here