<p>I am using a GCE cluster with 2 nodes, which I set up using kubeadm. Now I want to set up a persistent volume for postgresql to be deployed. I created a PVC and PV with a storageClass and also created a disk space with 10G in name <strong>postgres</strong> in the same project.Iam attaching the scripts for the PVC,PV,and Deployment below.Also I am using a service account that have the access to the disks.</p>

<p>1.Deployment.yml</p>

<pre><code>apiVersion: apps/v1
kind: Deployment 
metadata:
  name: kyc-postgres
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - image: "postgres:9.6.2"
        name: postgres
        ports:
        - containerPort: 5432
          name: postgres
        volumeMounts:
        - name: postgres-storage
          mountPath: /var/lib/postgresql/db-data
      volumes:
      - name: postgres-storage
        persistentVolumeClaim:
          claimName: kyc-postgres-pvc
</code></pre>

<p>2.PersistentVolumeClaim.yml</p>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: kyc-postgres-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: standard

</code></pre>

<p>3.PersistentVolume.yml</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: kyc-postgres-pv
  annotations:
    kubernetes.io/createdby: gce-pd-dynamic-provisioner
    pv.kubernetes.io/bound-by-controller: "yes"
    pv.kubernetes.io/provisioned-by: kubernetes.io/gce-pd
  finalizers:
  - kubernetes.io/pv-protection
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 5Gi
  claimRef:
    apiVersion: v1
    kind: PersistentVolumeClaim
    name: kyc-postgres-pvc
    namespace: default
  gcePersistentDisk:
    fsType: NTFS
    pdName: postgres
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: failure-domain.beta.kubernetes.io/zone
          operator: In
          values:
          - us-central1-a
        - key: failure-domain.beta.kubernetes.io/region
          operator: In
          values:
          - us-central1-a
  persistentVolumeReclaimPolicy: Delete
  storageClassName: standard
  volumeMode: Filesystem
status:
  phase: Bound
</code></pre>

<ol start="4">
<li>StorageClass.yml</li>
</ol>

<pre><code>apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: standard
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-standard
  zone: us-central1-a
</code></pre>

<p>Now when I create these volumes and deployments, the pod is not getting started properly.Iam getting the following errors when I tired creating deployments.</p>

<pre><code>Failed to get GCE GCECloudProvider with error &lt;nil&gt;
</code></pre>

<p>Also Iam attaching my output for <code>kubectl get sc</code></p>

<pre><code>NAME       PROVISIONER            RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
standard   kubernetes.io/gce-pd   Delete          Immediate           false                  10m
</code></pre>

<p>Can someone help me with this.Thanks in advance for your time – if I’ve missed out anything, over- or under-emphasised a specific point let me know in the comments.</p>

Shilpa
<p>Using the GCECloudProvider in Kubernetes outside of the Google Kubernetes Engine has the following prerequisites :</p>

<ol>
<li><p>The VM needs to be run with a service account that has the right to provision disks. Info on how to run a VM with a service account can be found <a href="https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances" rel="nofollow noreferrer">here</a></p></li>
<li><p>The Kubelet needs to run with the <code>argument --cloud-provider=gce</code>. For this the <code>KUBELET_KUBECONFIG_ARGS</code> in <code>/etc/systemd/system/kubelet.service.d/10-kubeadm.conf</code> have to be edited. The Kubelet can then be restarted with <code>sudo systemctl restart kubelet</code></p></li>
<li><p>The Kubernetes cloud-config file needs to be configured. The file can be found at <code>/etc/kubernetes/cloud-config</code> and the following content is enough to get the cloud provider to work:</p>

<pre><code>[Global]

project-id = "&lt;google-project-id&gt;"
</code></pre></li>
<li><p>Kubeadm needs to have GCE configured as its <a href="https://kubernetes.io/docs/concepts/cluster-administration/cloud-providers/#kubeadm" rel="nofollow noreferrer">cloud provider</a>.However, the <a href="https://kubernetes.io/docs/concepts/cluster-administration/cloud-providers/#node-name-3" rel="nofollow noreferrer">nodeName</a> has to be changed. Edit the config file and upload it to cluster via <code>kubeadm config upload from-file</code></p>

<pre><code>cloudProvider: gce
</code></pre></li>
</ol>
