2019-01-25 03:33:07 +00:00
# Run Velero on GCP
2018-02-14 18:02:35 +00:00
2018-10-26 16:12:28 +00:00
You can run Kubernetes on Google Cloud Platform in either:
2018-02-14 18:02:35 +00:00
* Kubernetes on Google Compute Engine virtual machines
* Google Kubernetes Engine
If you do not have the `gcloud` and `gsutil` CLIs locally installed, follow the [user guide][16] to set them up.
## Create GCS bucket
2019-01-25 03:33:07 +00:00
Velero requires an object storage bucket in which to store backups, preferably unique to a single Kubernetes cluster (see the [FAQ][20] for more details). Create a GCS bucket, replacing the < YOUR_BUCKET > placeholder with the name of your bucket:
2018-02-14 18:02:35 +00:00
```bash
2018-07-24 21:54:12 +00:00
BUCKET=< YOUR_BUCKET >
gsutil mb gs://$BUCKET/
2018-02-14 18:02:35 +00:00
```
## Create service account
2019-01-25 03:33:07 +00:00
To integrate Velero with GCP, create an Velero-specific [Service Account][15]:
2018-02-14 18:02:35 +00:00
1. View your current config settings:
```bash
gcloud config list
```
Store the `project` value from the results in the environment variable `$PROJECT_ID` .
2018-07-24 21:54:12 +00:00
```bash
PROJECT_ID=$(gcloud config get-value project)
```
2018-02-14 18:02:35 +00:00
2. Create a service account:
```bash
2019-01-25 03:33:07 +00:00
gcloud iam service-accounts create velero \
--display-name "Velero service account"
2018-02-14 18:02:35 +00:00
```
2019-01-25 03:33:07 +00:00
> If you'll be using Velero to backup multiple clusters with multiple GCS buckets, it may be desirable to create a unique username per cluster rather than the default `velero`.
2018-07-20 19:21:51 +00:00
2019-01-25 03:33:07 +00:00
Then list all accounts and find the `velero` account you just created:
2018-02-14 18:02:35 +00:00
```bash
gcloud iam service-accounts list
```
Set the `$SERVICE_ACCOUNT_EMAIL` variable to match its `email` value.
2018-07-24 21:54:12 +00:00
```bash
SERVICE_ACCOUNT_EMAIL=$(gcloud iam service-accounts list \
2019-01-25 03:33:07 +00:00
--filter="displayName:Velero service account" \
2018-07-24 21:54:12 +00:00
--format 'value(email)')
```
2018-02-14 18:02:35 +00:00
2019-01-25 03:33:07 +00:00
3. Attach policies to give `velero` the necessary permissions to function:
2018-02-14 18:02:35 +00:00
```bash
2018-04-16 22:11:44 +00:00
ROLE_PERMISSIONS=(
compute.disks.get
compute.disks.create
compute.disks.createSnapshot
compute.snapshots.get
compute.snapshots.create
compute.snapshots.useReadOnly
compute.snapshots.delete
)
2019-01-25 03:33:07 +00:00
gcloud iam roles create velero.server \
2018-04-16 22:11:44 +00:00
--project $PROJECT_ID \
2019-01-25 03:33:07 +00:00
--title "Velero Server" \
2018-04-16 22:11:44 +00:00
--permissions "$(IFS=","; echo "${ROLE_PERMISSIONS[*]}")"
2018-02-14 18:02:35 +00:00
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member serviceAccount:$SERVICE_ACCOUNT_EMAIL \
2019-01-25 03:33:07 +00:00
--role projects/$PROJECT_ID/roles/velero.server
2018-04-16 22:11:44 +00:00
gsutil iam ch serviceAccount:$SERVICE_ACCOUNT_EMAIL:objectAdmin gs://${BUCKET}
2018-02-14 18:02:35 +00:00
```
2019-01-25 03:33:07 +00:00
4. Create a service account key, specifying an output file (`credentials-velero`) in your local directory:
2018-02-14 18:02:35 +00:00
```bash
2019-01-25 03:33:07 +00:00
gcloud iam service-accounts keys create credentials-velero \
2018-02-14 18:02:35 +00:00
--iam-account $SERVICE_ACCOUNT_EMAIL
```
## Credentials and configuration
If you run Google Kubernetes Engine (GKE), make sure that your current IAM user is a cluster-admin. This role is required to create RBAC objects.
See [the GKE documentation][22] for more information.
2019-01-25 03:33:07 +00:00
In the Velero directory (i.e. where you extracted the release tarball), run the following to first set up namespaces, RBAC, and other scaffolding. To run in a custom namespace, make sure that you have edited the YAML files to specify the namespace. See [Run in custom namespace][0].
2018-02-14 18:02:35 +00:00
```bash
2018-11-09 19:04:12 +00:00
kubectl apply -f config/common/00-prereqs.yaml
2018-02-14 18:02:35 +00:00
```
Create a Secret. In the directory of the credentials file you just created, run:
```bash
kubectl create secret generic cloud-credentials \
2019-01-25 03:33:07 +00:00
--namespace velero \
--from-file cloud=credentials-velero
2018-02-14 18:02:35 +00:00
```
2019-01-25 03:33:07 +00:00
**Note: If you use a custom namespace, replace `velero` with the name of the custom namespace**
2018-07-24 21:54:12 +00:00
2018-02-14 18:02:35 +00:00
Specify the following values in the example files:
2019-01-25 03:33:07 +00:00
* In file `config/gcp/05-backupstoragelocation.yaml` :
2018-02-14 18:02:35 +00:00
2018-08-23 19:44:25 +00:00
* Replace `<YOUR_BUCKET>` . See the [BackupStorageLocation definition][7] for details.
2018-02-14 18:02:35 +00:00
2018-11-09 19:04:12 +00:00
* (Optional) If you run the nginx example, in file `config/nginx-app/with-pv.yaml` :
2018-02-14 18:02:35 +00:00
* Replace `<YOUR_STORAGE_CLASS_NAME>` with `standard` . This is GCP's default `StorageClass` name.
2018-11-09 19:04:12 +00:00
* (Optional, use only if you need to specify multiple volume snapshot locations) In `config/gcp/10-deployment.yaml` :
2018-10-26 16:12:28 +00:00
* Uncomment the `--default-volume-snapshot-locations` and replace provider locations with the values for your environment.
2018-02-14 18:02:35 +00:00
## Start the server
2019-01-25 03:33:07 +00:00
In the root of your Velero directory, run:
2018-02-14 18:02:35 +00:00
```bash
2019-01-25 03:33:07 +00:00
kubectl apply -f config/gcp/05-backupstoragelocation.yaml
kubectl apply -f config/gcp/06-volumesnapshotlocation.yaml
2018-11-09 19:04:12 +00:00
kubectl apply -f config/gcp/10-deployment.yaml
2018-02-14 18:02:35 +00:00
```
2018-02-21 19:15:08 +00:00
[0]: namespace.md
2018-09-07 17:18:06 +00:00
[7]: api-types/backupstoragelocation.md#gcp
2018-02-14 18:02:35 +00:00
[15]: https://cloud.google.com/compute/docs/access/service-accounts
[16]: https://cloud.google.com/sdk/docs/
2018-07-20 19:21:51 +00:00
[20]: faq.md
2018-02-14 18:02:35 +00:00
[22]: https://cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control#prerequisites_for_using_role-based_access_control