This sample shows how to Configure CloudSchedulerSource
resource for receiving
scheduled events from
Google Cloud Scheduler.
-
Create with an App Engine application in your project. Refer to this guide for more details. You can change the APP_ENGINE_LOCATION, but please make sure you also update the spec.location in
CloudSchedulerSource
export APP_ENGINE_LOCATION=us-central gcloud app create --region=$APP_ENGINE_LOCATION
-
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
serviceAccountName
with the Kubernetes service account you created in Create a Service Account for the Data Plane, which is bound to the Pub/Sub enabled Google service account. -
If you are using standard Kubernetes secrets, but want to use a non-default one, update
secret
with your own secret. -
By default, the Scheduler will be created in the same project as your GKE cluster. However, if you are managing multiple projects, then you can specify
spec.project
, which is the Google Cloud Project that the Scheduler is created in.
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 --tail=200
You should see log lines similar to:
☁️ cloudevents.Event
Validation: valid
Context Attributes,
specversion: 1.0
type: google.cloud.scheduler.job.v1.executed
source: //cloudscheduler.googleapis.com/projects/test-project/locations/us-central1/jobs/cre-scheduler-a7155fae-895c-4d11-b555-b2cd5ed97666
id: 1313918157507406
time: 2020-06-30T16:21:00.861Z
dataschema: https://raw.githubusercontent.com/googleapis/google-cloudevents/master/proto/google/events/cloud/scheduler/v1/data.proto
datacontenttype: application/json
Extensions,
knativearrivaltime: 2020-06-30T16:21:01.401511767Z
knsourcetrigger: link0.16512790926262466
traceparent: 00-37bb197929fc15a684be311da682fce2-4af58d9f16415e4a-00
Data,
{
"custom_data": "c2NoZWR1bGVyIGN1c3RvbSBkYXRh" // base64 encoded "scheduler custom data"
}
You may have issues receiving desired CloudEvent. Please use Authentication Mechanism Troubleshooting to check if it is due to an auth problem.
- For more details on Cloud Pub/Sub formats refer to the Subscriber overview guide.
- 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 integrating with Cloud Build see the Build 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