This sample shows how to Configure CloudSchedulerSource
resource for receiving
scheduled events from
Google Cloud Scheduler.
-
Install Knative-GCP. Note that your project needs to be created with an App Engine application. Refer to this guide for more details.
-
Enable the
Cloud Scheduler API
on your project:gcloud services enable cloudscheduler.googleapis.com
-
Create a
CloudSchedulerSource
-
If you are in GKE and using Workload Identity, update
serviceAccount
with the Pub/Sub enabled service account you created in Create a Pub/Sub enabled Service Account. -
If you are using standard Kubernetes secrets, but want to use a non-default one, update
secret
with your own secret.
kubectl apply --filename cloudschedulersource.yaml
-
-
Create a
Service
that the Scheduler notifications will sink into:kubectl apply --filename event-display.yaml
We will verify that the published event was sent by looking at the logs of the service that this Scheduler job sinks to.
-
We need to wait for the downstream pods to get started and receive our event, wait 60 seconds. You can check the status of the downstream pods with:
kubectl get pods --selector app=event-display
You should see at least one.
-
Inspect the logs of the
Service
:kubectl logs --selector app=event-display -c user-container
You should see log lines similar to:
☁️ cloudevents.Event
Validation: valid
Context Attributes,
specversion: 1.0
type: com.google.cloud.scheduler.job.execute
source: //cloudscheduler.googleapis.com/projects/knative-gcp/locations/us-east4/schedulers/scheduler-test
subject: jobs/cre-scheduler-bfc82b00-11fd-42ec-b21a-011dddc2170b
id: 714614529367848
time: 2019-08-28T22:29:00.979Z
datacontenttype: application/octet-stream
Extensions,
knativecemode: binary
Data,
my test data
- For integrating with Cloud Pub/Sub, see the PubSub example.
- For integrating with Cloud Storage see the Storage example.
- For integrating with Cloud Audit Logs see the Cloud Audit Logs example.
- For more information about CloudEvents, see the HTTP transport bindings documentation.
-
Delete the
CloudSchedulerSource
kubectl delete -f ./cloudschedulersource.yaml
-
Delete the
Service
kubectl delete -f ./event-display.yaml