The following are prerequisites for Channel
, Topic
and PullSubscription
.
-
Create a Google Cloud project and install the
gcloud
CLI and rungcloud auth login
. This sample will use a mix ofgcloud
andkubectl
commands. The rest of the sample assumes that you've set the$PROJECT_ID
environment variable to your Google Cloud project id, and also set your project ID as default usinggcloud config set project $PROJECT_ID
. -
Enable the
Cloud Pub/Sub API
on your project:gcloud services enable pubsub.googleapis.com
-
Create a Google Cloud Service Account. This sample creates one service account for both registration and receiving messages, but you can also create a separate service account for receiving messages if you want additional privilege separation.
-
Create a new service account named
cloudrunevents-pullsub
with the following command:gcloud iam service-accounts create cloudrunevents-pullsub
-
Give that Service Account the
Pub/Sub Editor
role on your Google Cloud project:gcloud projects add-iam-policy-binding $PROJECT_ID \ --member=serviceAccount:cloudrunevents-pullsub@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/pubsub.editor
-
Optional: If you plan on using the StackDriver monitoring APIs, also give the Service Account the
Monitoring MetricWriter
role on your Google Cloud project:gcloud projects add-iam-policy-binding $PROJECT_ID \ --member=serviceAccount:cloudrunevents-pullsub@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/monitoring.metricWriter
-
Download a new JSON private key for that Service Account. Be sure not to check this key into source control!
gcloud iam service-accounts keys create cloudrunevents-pullsub.json \ --iam-account=cloudrunevents-pullsub@$PROJECT_ID.iam.gserviceaccount.com
-
Create a secret on the kubernetes cluster with the downloaded key:
# The secret should not already exist, so just try to create it. kubectl --namespace default create secret generic google-cloud-key --from-file=key.json=cloudrunevents-pullsub.json
google-cloud-key
andkey.json
are default values expected byChannel
,Topic
andPullSubscription
.
-