Learn how to enable and configure Events for Cloud Run for Anthos, including creating an event broker that can route messages from an event source to a receiver, such as a service in Cloud Run for Anthos.
Creating a GKE cluster with Cloud Run enabled
You must have Cloud Run for Anthos enabled in your cluster before you can get started with Events for Cloud Run for Anthos.
Initializing Events for Cloud Run for Anthos
To initialize Events for Cloud Run for Anthos:
Install the Google Cloud CLI beta components:
gcloud components install beta
Enable services used in this tutorial:
gcloud services enable cloudapis.googleapis.com
Initialize Events for Cloud Run for Anthos using the
gcloud
command-line tool:gcloud beta events init
This creates pods in the
cloud-run-events
andknative-eventing
namespaces.Optional: Ensure that both pods are created:
To check pods in the
cloud-run-events
namespace, run:kubectl get pods -n cloud-run-events
The output is similar to the following:
NAME READY STATUS RESTARTS AGE controller-9cc679b67-2952n 1/1 Running 0 22s webhook-8576c4cfcb-dhz82 1/1 Running 0 16m
To check pods in the
knative-eventing
namespace, run:kubectl get pods -n knative-eventing
The output is similar to the following:
NAME READY STATUS RESTARTS AGE eventing-controller-77f46f6cf8-kj9ck 1/1 Running 0 17m eventing-webhook-5bc787965f-hcmwg 1/1 Running 0 17m
Creating an event broker
You create an event broker to handle routing events from your event sources to the event consumer, for example a destination service.
To create a broker:
Create a namespace:
kubectl create namespace NAMESPACE
Initialize the namespace with the default secret:
gcloud beta events namespaces init NAMESPACE \ --copy-default-secret
Create the event broker:
gcloud beta events brokers create default \ --namespace NAMESPACE
Optional: Run the following command to ensure that the event broker is running:
kubectl get brokers \ -n NAMESPACE
where NAMESPACE is the same namespace as your events broker.
The output is similar to the following:
NAME READY REASON URL default True http://default-brokercell-ingress.cloud-run-events.svc.cluster.local/default/default