0

I have two VM Instance on GCE with kubernetes self install (using the following https://medium.com/edureka/install-kubernetes-on-ubuntu-5cd1f770c9e4).

I'm trying to create volume and use it in my pods.

I have been created the following disk:

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

And create the following yaml files

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

And when I'm trying to create the pod the pode get status ContainerCreating and on kubectl get events I see:

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

I run my two instances using ServiceAccount with compute instance admin role (according Kubernetes: Failed to get GCE GCECloudProvider with error <nil>) and my kubelet running with --cloud-provider=gce

How can I solve it?

samisaviv
  • 283
  • 1
  • 7
  • 17

1 Answers1

1

You need to create a storageclass

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

For GCE details here

You can also follow GCE documentation here

hoque
  • 5,735
  • 1
  • 19
  • 29
  • I need to create only storageclass? or should I create also disk, pv, pvc? Can you show me please example of pod.yaml file that use this storageclass please? – samisaviv May 05 '20 at 11:00
  • you need storageclass first. then this will be used when pv will be created. you don't need to create disk. create storageclass, pv, pvc – hoque May 05 '20 at 11:04
  • I create storageclass and then pvc but when i run kubectl get pvc the pvc on pending status – samisaviv May 06 '20 at 06:40
  • did you create pod with the pvc? – hoque May 06 '20 at 07:43
  • Now It's working, This storage can accessible from master also?If so, how? – samisaviv May 06 '20 at 08:15
  • 2
    The disk mounted to that node where the pod is scheduled. If you use tolleration to schedule your pod on master than the volume will be mounted on master node – hoque May 06 '20 at 08:17