88fa06039ce2b3cbad42f8183f5b3937ac17d549
[it/test.git] / XTesting / kubespray / docs / gcp-pd-csi.md
1 # GCP Persistent Disk CSI Driver
2
3 The GCP Persistent Disk CSI driver allows you to provision volumes for pods with a Kubernetes deployment over Google Cloud Platform. The CSI driver replaces to volume provioning done by the in-tree azure cloud provider which is deprecated.
4
5 To deploy GCP Persistent Disk CSI driver, uncomment the `gcp_pd_csi_enabled` option in `group_vars/all/gcp.yml` and set it to `true`.
6
7 ## GCP Persistent Disk Storage Class
8
9 If you want to deploy the GCP Persistent Disk storage class to provision volumes dynamically, you should set `persistent_volumes_enabled` in `group_vars/k8s_cluster/k8s_cluster.yml` to `true`.
10
11 ## GCP credentials
12
13 In order for the CSI driver to provision disks, you need to create for it a service account on GCP with the appropriate permissions.
14
15 Follow these steps to configure it:
16
17 ```ShellSession
18 # This will open a web page for you to authenticate
19 gcloud auth login
20 export PROJECT=nameofmyproject
21 gcloud config set project $PROJECT
22
23 git clone https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver $GOPATH/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
24
25 export GCE_PD_SA_NAME=my-gce-pd-csi-sa
26 export GCE_PD_SA_DIR=/my/safe/credentials/directory
27
28 ./deploy/setup-project.sh
29 ```
30
31 The above will create a file named `cloud-sa.json` in the specified `GCE_PD_SA_DIR`. This file contains the service account with the appropriate credentials for the CSI driver to perform actions on GCP to request disks for pods.
32
33 You need to provide this file's path through the variable `gcp_pd_csi_sa_cred_file` in `inventory/mycluster/group_vars/all/gcp.yml`
34
35 You can now deploy Kubernetes with Kubespray over GCP.
36
37 ## GCP PD CSI Driver test
38
39 To test the dynamic provisioning using GCP PD CSI driver, make sure to have the storage class deployed (through persistent volumes), and apply the following manifest:
40
41 ```yml
42 ---
43 kind: PersistentVolumeClaim
44 apiVersion: v1
45 metadata:
46   name: podpvc
47 spec:
48   accessModes:
49     - ReadWriteOnce
50   storageClassName: csi-gce-pd
51   resources:
52     requests:
53       storage: 1Gi
54
55 ---
56 apiVersion: v1
57 kind: Pod
58 metadata:
59   name: web-server
60 spec:
61   containers:
62    - name: web-server
63      image: nginx
64      volumeMounts:
65        - mountPath: /var/lib/www/html
66          name: mypvc
67   volumes:
68    - name: mypvc
69      persistentVolumeClaim:
70        claimName: podpvc
71        readOnly: false
72 ```
73
74 ## GCP PD documentation
75
76 You can find the official GCP Persistent Disk CSI driver installation documentation here: [GCP PD CSI Driver](https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/blob/master/docs/kubernetes/user-guides/driver-install.md
77 )