mirror of https://github.com/knative/docs.git
Updated pingsource docs, collated info (#3509)
* Updated pingsource docs, collated info * updated commands * updated from SME review to remove serving * update service name * Update docs/eventing/sources/ping-source/index.md * Update docs/eventing/sources/ping-source/index.md * Update docs/eventing/sources/ping-source/index.md
This commit is contained in:
parent
57e90c5724
commit
f7b75e373d
|
@ -1,213 +0,0 @@
|
|||
---
|
||||
title: "PingSource example"
|
||||
linkTitle: "PingSource"
|
||||
weight: 10
|
||||
type: "docs"
|
||||
aliases:
|
||||
- ../cronjob-source
|
||||
---
|
||||
|
||||
This example shows how to configure PingSource as an event source targeting
|
||||
a Knative Service.
|
||||
|
||||
## Before you begin
|
||||
|
||||
1. Set up [Knative Serving](../../../serving).
|
||||
1. Set up [Knative Eventing](../../../eventing).
|
||||
|
||||
## Create a Knative Service
|
||||
|
||||
To verify that `PingSource` is working, create a simple Knative
|
||||
Service that dumps incoming messages to its log.
|
||||
|
||||
{{< tabs name="create-service" default="YAML" >}}
|
||||
{{% tab name="YAML" %}}
|
||||
Use following command to create the service from STDIN:
|
||||
|
||||
```shell
|
||||
cat <<EOF | kubectl create -f -
|
||||
apiVersion: serving.knative.dev/v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: event-display
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- image: gcr.io/knative-releases/knative.dev/eventing/cmd/event_display
|
||||
EOF
|
||||
```
|
||||
{{< /tab >}}
|
||||
|
||||
{{% tab name="kn" %}}
|
||||
Use following command to create the service using the kn cli:
|
||||
|
||||
```shell
|
||||
kn service create event-display --image gcr.io/knative-releases/knative.dev/eventing/cmd/event_display
|
||||
```
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
|
||||
## Create a PingSource
|
||||
|
||||
For each set of ping events that you want to request, create an Event
|
||||
Source in the same namespace as the destination.
|
||||
|
||||
{{< tabs name="create-source" default="YAML" >}}
|
||||
{{% tab name="YAML" %}}
|
||||
Use following command to create the event source from STDIN:
|
||||
|
||||
```shell
|
||||
cat <<EOF | kubectl create -f -
|
||||
apiVersion: sources.knative.dev/v1beta2
|
||||
kind: PingSource
|
||||
metadata:
|
||||
name: test-ping-source
|
||||
spec:
|
||||
schedule: "*/2 * * * *"
|
||||
contentType: "application/json"
|
||||
data: '{"message": "Hello world!"}'
|
||||
sink:
|
||||
ref:
|
||||
apiVersion: serving.knative.dev/v1
|
||||
kind: Service
|
||||
name: event-display
|
||||
EOF
|
||||
```
|
||||
{{< /tab >}}
|
||||
|
||||
{{% tab name="kn" %}}
|
||||
Use following command to create the event source from the `ping-source.yaml` file:
|
||||
|
||||
```shell
|
||||
kn source ping create test-ping-source \
|
||||
--schedule "*/2 * * * *" --data \
|
||||
'{ "message": "Hello world!" }' \
|
||||
--sink ksvc:event-display
|
||||
```
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
|
||||
## (Optional) Create a PingSource with binary data
|
||||
|
||||
Sometimes you may want to send binary data, which cannot be directly serialized in yaml, to downstream. This can be achieved by using `dataBase64` as the payload. As the name suggests, `dataBase64` should carry data that is base64 encoded.
|
||||
|
||||
Please note that `data` and `dataBase64` cannot co-exist.
|
||||
|
||||
Use the following command to create the event source with binary data from STDIN:
|
||||
|
||||
```shell
|
||||
cat <<EOF | kubectl create -f -
|
||||
apiVersion: sources.knative.dev/v1beta2
|
||||
kind: PingSource
|
||||
metadata:
|
||||
name: test-ping-source-binary
|
||||
spec:
|
||||
schedule: "*/2 * * * *"
|
||||
contentType: "text/plain"
|
||||
dataBase64: "ZGF0YQ=="
|
||||
sink:
|
||||
ref:
|
||||
apiVersion: serving.knative.dev/v1
|
||||
kind: Service
|
||||
name: event-display
|
||||
EOF
|
||||
```
|
||||
|
||||
## Verify
|
||||
|
||||
Verify that the message was sent to the Knative eventing system by
|
||||
looking at message dumper logs.
|
||||
|
||||
{{< tabs name="view-event" default="kubectl" >}}
|
||||
{{% tab name="kubectl" %}}
|
||||
|
||||
Use following command to view the logs of the event-display service:
|
||||
|
||||
```shell
|
||||
kubectl logs -l serving.knative.dev/service=event-display -c user-container --since=10m
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{% tab name="kail" %}}
|
||||
|
||||
You can also use [`kail`](https://github.com/boz/kail) instead of `kubectl logs`
|
||||
to tail the logs of the subscriber.
|
||||
|
||||
```shell
|
||||
kail -l serving.knative.dev/service=event-display -c user-container --since=10m
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
|
||||
You should see log lines showing the request headers and body from the source:
|
||||
|
||||
```shell
|
||||
☁️ cloudevents.Event
|
||||
Validation: valid
|
||||
Context Attributes,
|
||||
specversion: 1.0
|
||||
type: dev.knative.sources.ping
|
||||
source: /apis/v1/namespaces/default/pingsources/test-ping-source
|
||||
id: d8e761eb-30c7-49a3-a421-cd5895239f2d
|
||||
time: 2019-12-04T14:24:00.000702251Z
|
||||
datacontenttype: application/json
|
||||
Data,
|
||||
{
|
||||
"message": "Hello world!"
|
||||
}
|
||||
```
|
||||
|
||||
If you created a PingSource with binary data, you should also see the following:
|
||||
|
||||
```shell
|
||||
☁️ cloudevents.Event
|
||||
Validation: valid
|
||||
Context Attributes,
|
||||
specversion: 1.0
|
||||
type: dev.knative.sources.ping
|
||||
source: /apis/v1/namespaces/default/pingsources/test-ping-source-binary
|
||||
id: a195be33-ff65-49af-9045-0e0711d05e94
|
||||
time: 2020-11-17T19:48:00.48334181Z
|
||||
datacontenttype: text/plain
|
||||
Data,
|
||||
ZGF0YQ==
|
||||
```
|
||||
|
||||
## Cleanup
|
||||
|
||||
You can delete the PingSource instance by entering the following command:
|
||||
|
||||
{{< tabs name="delete-source" default="kubectl" >}}
|
||||
{{% tab name="kubectl" %}}
|
||||
```shell
|
||||
kubectl delete pingsources.sources.knative.dev test-ping-source
|
||||
kubectl delete pingsources.sources.knative.dev test-ping-source-binary
|
||||
```
|
||||
{{< /tab >}}
|
||||
|
||||
{{% tab name="kn" %}}
|
||||
```shell
|
||||
kn source ping delete test-ping-source
|
||||
kn source ping delete test-ping-source-binary
|
||||
```
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
|
||||
|
||||
Similarly, you can delete the Service instance via:
|
||||
|
||||
{{< tabs name="delete-service" default="kubectl" >}}
|
||||
{{% tab name="kubectl" %}}
|
||||
```shell
|
||||
kubectl delete service.serving.knative.dev event-display
|
||||
```
|
||||
{{< /tab >}}
|
||||
{{% tab name="kn" %}}
|
||||
```shell
|
||||
kn service delete event-display
|
||||
```
|
||||
{{< /tab >}}
|
||||
|
||||
{{< /tabs >}}
|
|
@ -0,0 +1,252 @@
|
|||
---
|
||||
title: "PingSource"
|
||||
weight: 31
|
||||
type: "docs"
|
||||
aliases:
|
||||
- /docs/eventing/sources/pingsource
|
||||
- ../cronjob-source
|
||||
- /docs/eventing/samples/ping-source
|
||||
---
|
||||
|
||||

|
||||
|
||||
A PingSource is an event source that produces events with a fixed payload on a specified [cron](https://en.wikipedia.org/wiki/Cron) schedule.
|
||||
|
||||
The following example shows how you can configure a PingSource as an event source that sends events every minute to a Knative service named `event-display` that is used as a sink.
|
||||
|
||||
## Before you begin
|
||||
|
||||
1. To create a PingSource, you must install [Knative Eventing](../../../eventing). The PingSource event source type is enabled by default when you install Knative Eventing.
|
||||
1. Optional: You can use either `kubectl` or [`kn`](../../../client/install-kn) commands to create components such as a sink and PingSource.
|
||||
1. Optional: You can use either `kubectl` or [`kail`](https://github.com/boz/kail) for logging during the verification step in this procedure.
|
||||
|
||||
## Procedure
|
||||
|
||||
1. Optional: Create a new namespace called `pingsource-example` by entering the following command:
|
||||
|
||||
```shell
|
||||
kubectl create namespace pingsource-example
|
||||
```
|
||||
|
||||
Creating a namespace for the PingSource example allows you to isolate the components created by this demo, so that it is easier for you to view changes and remove components when you are finished.
|
||||
|
||||
1. To verify that the PingSource is working correctly, create an example sink in the `pingsource-example` namespace that dumps incoming messages to a log, by entering the command:
|
||||
|
||||
{{< tabs name="create-sink" default="kubectl" >}}
|
||||
{{% tab name="kubectl" %}}
|
||||
|
||||
```shell
|
||||
kubectl -n pingsource-example apply -f - << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: event-display
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels: &labels
|
||||
app: event-display
|
||||
template:
|
||||
metadata:
|
||||
labels: *labels
|
||||
spec:
|
||||
containers:
|
||||
- name: event-display
|
||||
image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
|
||||
|
||||
---
|
||||
|
||||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: event-display
|
||||
spec:
|
||||
selector:
|
||||
app: event-display
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 8080
|
||||
EOF
|
||||
```
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
<br>
|
||||
|
||||
1. Create a PingSource that sends an event containing `{"message": "Hello world!"}` every minute, by entering the command:
|
||||
|
||||
{{< tabs name="create-source" default="kn" >}}
|
||||
{{% tab name="YAML" %}}
|
||||
|
||||
```shell
|
||||
kubectl create -n pingsource-example -f - <<EOF
|
||||
apiVersion: sources.knative.dev/v1
|
||||
kind: PingSource
|
||||
metadata:
|
||||
name: test-ping-source
|
||||
spec:
|
||||
schedule: "*/1 * * * *"
|
||||
contentType: "application/json"
|
||||
data: '{"message": "Hello world!"}'
|
||||
sink:
|
||||
ref:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
name: event-display
|
||||
EOF
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{% tab name="kn" %}}
|
||||
|
||||
```shell
|
||||
kn source ping create test-ping-source \
|
||||
--namespace pingsource-example \
|
||||
--schedule "*/1 * * * *" \
|
||||
--data '{"message": "Hello world!"}' \
|
||||
--sink http://event-display.pingsource-example.svc.cluster.local
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
<br>
|
||||
|
||||
1. Optional: Create a PingSource that sends binary data.
|
||||
|
||||
If you want to send binary data in an event, this cannot be directly serialized in YAML. However, you can use `dataBase64` in place of `data` in the PingSource spec to carry a data payload that is base64 encoded.
|
||||
|
||||
To create a PingSource that uses base64 encoded data, enter the command:
|
||||
|
||||
```shell
|
||||
kubectl -n pingsource-example apply -f - <<EOF
|
||||
apiVersion: sources.knative.dev/v1
|
||||
kind: PingSource
|
||||
metadata:
|
||||
name: test-ping-source-binary
|
||||
spec:
|
||||
schedule: "*/1 * * * *"
|
||||
contentType: "text/plain"
|
||||
dataBase64: "ZGF0YQ=="
|
||||
sink:
|
||||
ref:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
name: event-display
|
||||
EOF
|
||||
```
|
||||
|
||||
1. View the logs for the `event-display` event consumer by
|
||||
entering the following command:
|
||||
|
||||
{{< tabs name="View logs" default="kubectl" >}}
|
||||
{{% tab name="kubectl" %}}
|
||||
|
||||
```shell
|
||||
kubectl -n pingsource-example logs -l app=event-display --tail=100
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{% tab name="kail" %}}
|
||||
|
||||
```shell
|
||||
kail -l serving.knative.dev/service=event-display -c user-container --since=10m
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
<br>
|
||||
|
||||
This returns the `Attributes` and `Data` of the events that the PingSource sent to the `event-display` service:
|
||||
|
||||
```shell
|
||||
☁️ cloudevents.Event
|
||||
Validation: valid
|
||||
Context Attributes,
|
||||
specversion: 1.0
|
||||
type: dev.knative.sources.ping
|
||||
source: /apis/v1/namespaces/pingsource-example/pingsources/test-ping-source
|
||||
id: 49f04fe2-7708-453d-ae0a-5fbaca9586a8
|
||||
time: 2021-03-25T19:41:00.444508332Z
|
||||
datacontenttype: application/json
|
||||
Data,
|
||||
{
|
||||
"message": "Hello world!"
|
||||
}
|
||||
```
|
||||
|
||||
If you created a PingSource that sends binary data, you will also see output similar to the following:
|
||||
|
||||
```shell
|
||||
☁️ cloudevents.Event
|
||||
Validation: valid
|
||||
Context Attributes,
|
||||
specversion: 1.0
|
||||
type: dev.knative.sources.ping
|
||||
source: /apis/v1/namespaces/pingsource-example/pingsources/test-ping-source-binary
|
||||
id: ddd7bad2-9b6a-42a7-8f9b-b64494a6ce43
|
||||
time: 2021-03-25T19:38:00.455013472Z
|
||||
datacontenttype: text/plain
|
||||
Data,
|
||||
data
|
||||
```
|
||||
|
||||
1. Optional: You can delete the `pingsource-example` namespace and all related resources from your cluster by entering the following command:
|
||||
|
||||
|
||||
```shell
|
||||
kubectl delete namespace pingsource-example
|
||||
```
|
||||
|
||||
1. Optional: You can also delete the PingSource instance only by entering the following command:
|
||||
|
||||
{{< tabs name="delete-source" default="kubectl" >}}
|
||||
{{% tab name="kubectl" %}}
|
||||
|
||||
```shell
|
||||
kubectl delete pingsources.sources.knative.dev test-ping-source
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{% tab name="kn" %}}
|
||||
|
||||
```shell
|
||||
kn source ping delete test-ping-source
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{% tab name="kubectl: binary data PingSource" %}}
|
||||
|
||||
```shell
|
||||
kubectl delete pingsources.sources.knative.dev test-ping-source-binary
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{% tab name="kn: binary data PingSource" %}}
|
||||
|
||||
```shell
|
||||
kn source ping delete test-ping-source-binary
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
<br>
|
||||
|
||||
|
||||
1. Optional: Delete the `event-display` service:
|
||||
|
||||
{{< tabs name="delete-service" default="kubectl" >}}
|
||||
{{% tab name="kubectl" %}}
|
||||
|
||||
```shell
|
||||
kubectl delete service.serving.knative.dev event-display
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{% tab name="kn" %}}
|
||||
|
||||
```shell
|
||||
kn service delete event-display
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
|
@ -1,196 +0,0 @@
|
|||
---
|
||||
title: "PingSource"
|
||||
linkTitle: "PingSource"
|
||||
weight: 31
|
||||
type: "docs"
|
||||
---
|
||||
|
||||

|
||||
|
||||
A PingSource produces events with a fixed payload on a specified cron schedule.
|
||||
|
||||
## Installation
|
||||
|
||||
The PingSource source type is enabled by default when you install Knative Eventing.
|
||||
|
||||
## Example
|
||||
|
||||
This example shows how to send an event every minute to a Event Display Service.
|
||||
|
||||
### Creating a namespace
|
||||
|
||||
Create a new namespace called `pingsource-example` by entering the following
|
||||
command:
|
||||
|
||||
```shell
|
||||
kubectl create namespace pingsource-example
|
||||
```
|
||||
|
||||
### Creating the Event Display Service
|
||||
|
||||
In this step, you create one event consumer, `event-display` to verify that
|
||||
`PingSource` is properly working.
|
||||
|
||||
To deploy the `event-display` consumer to your cluster, run the following
|
||||
command:
|
||||
|
||||
```shell
|
||||
kubectl -n pingsource-example apply -f - << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: event-display
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels: &labels
|
||||
app: event-display
|
||||
template:
|
||||
metadata:
|
||||
labels: *labels
|
||||
spec:
|
||||
containers:
|
||||
- name: event-display
|
||||
image: gcr.io/knative-releases/knative.dev/eventing/cmd/event_display
|
||||
|
||||
---
|
||||
|
||||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: event-display
|
||||
spec:
|
||||
selector:
|
||||
app: event-display
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 8080
|
||||
EOF
|
||||
```
|
||||
|
||||
### Creating the PingSource
|
||||
|
||||
You can now create the `PingSource` sending an event containing
|
||||
`{"message": "Hello world!"}` every minute.
|
||||
|
||||
{{< tabs name="create-source" default="YAML" >}}
|
||||
{{% tab name="YAML" %}}
|
||||
|
||||
```shell
|
||||
kubectl create -n pingsource-example -f - <<EOF
|
||||
apiVersion: sources.knative.dev/v1beta2
|
||||
kind: PingSource
|
||||
metadata:
|
||||
name: test-ping-source
|
||||
spec:
|
||||
schedule: "*/1 * * * *"
|
||||
contentType: "application/json"
|
||||
data: '{"message": "Hello world!"}'
|
||||
sink:
|
||||
ref:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
name: event-display
|
||||
EOF
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
|
||||
{{% tab name="kn" %}}
|
||||
Notice that the namespace is specified in two places in the command in `--namespace` and the `--sink` hostname
|
||||
```shell
|
||||
kn source ping create test-ping-source \
|
||||
--namespace pingsource-example \
|
||||
--schedule "*/1 * * * *" \
|
||||
--data '{"message": "Hello world!"}' \
|
||||
--sink http://event-display.pingsource-example.svc.cluster.local
|
||||
```
|
||||
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
|
||||
## (Optional) Create a PingSource with binary data
|
||||
|
||||
Sometimes you may want to send binary data, which cannot be directly serialized in yaml, to downstream. This can be achieved by using `dataBase64` as the payload. As the name suggests, `dataBase64` should carry data that is base64 encoded.
|
||||
|
||||
Please note that `data` and `dataBase64` cannot co-exist.
|
||||
|
||||
```shell
|
||||
kubectl create -n pingsource-example -f - <<EOF
|
||||
apiVersion: sources.knative.dev/v1beta2
|
||||
kind: PingSource
|
||||
metadata:
|
||||
name: test-ping-source-binary
|
||||
spec:
|
||||
schedule: "*/1 * * * *"
|
||||
contentType: "text/plain"
|
||||
dataBase64: "ZGF0YQ=="
|
||||
sink:
|
||||
ref:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
name: event-display
|
||||
EOF
|
||||
```
|
||||
|
||||
### Verify
|
||||
|
||||
View the logs for the `event-display` event consumer by
|
||||
entering the following command:
|
||||
|
||||
```shell
|
||||
kubectl -n pingsource-example logs -l app=event-display --tail=100
|
||||
```
|
||||
|
||||
This returns the `Attributes` and `Data` of the events that the PingSource sent to the `event-display` Service:
|
||||
|
||||
```shell
|
||||
☁️ cloudevents.Event
|
||||
Validation: valid
|
||||
Context Attributes,
|
||||
specversion: 1.0
|
||||
type: dev.knative.sources.ping
|
||||
source: /apis/v1/namespaces/pingsource-example/pingsources/test-ping-source
|
||||
id: 49f04fe2-7708-453d-ae0a-5fbaca9586a8
|
||||
time: 2021-03-25T19:41:00.444508332Z
|
||||
datacontenttype: application/json
|
||||
Data,
|
||||
{
|
||||
"message": "Hello world!"
|
||||
}
|
||||
```
|
||||
|
||||
If you created a PingSource with binary data, you should also see the following:
|
||||
|
||||
```shell
|
||||
☁️ cloudevents.Event
|
||||
Validation: valid
|
||||
Context Attributes,
|
||||
specversion: 1.0
|
||||
type: dev.knative.sources.ping
|
||||
source: /apis/v1/namespaces/pingsource-example/pingsources/test-ping-source-binary
|
||||
id: ddd7bad2-9b6a-42a7-8f9b-b64494a6ce43
|
||||
time: 2021-03-25T19:38:00.455013472Z
|
||||
datacontenttype: text/plain
|
||||
Data,
|
||||
data
|
||||
```
|
||||
|
||||
### Cleanup
|
||||
|
||||
Delete the `pingsource-example` namespace and all of its resources from your
|
||||
cluster by entering the following command:
|
||||
|
||||
```shell
|
||||
kubectl delete namespace pingsource-example
|
||||
```
|
||||
|
||||
## Reference Documentation
|
||||
|
||||
See the [PingSource specification](../../reference/api/eventing/#sources.knative.dev/v1beta2.PingSource).
|
||||
|
||||
## Contact
|
||||
|
||||
For any inquiries about this source, please reach out on to the
|
||||
[Knative users group](https://groups.google.com/forum/#!forum/knative-users).
|
Loading…
Reference in New Issue