创建channel

[root@master sources]# kn channel create imc01
Channel 'imc01' created in namespace 'default'.
[root@master sources]# kn channel create imc02 --type messaging.knative.dev:v1:InMemoryChannel
Channel 'imc02' created in namespace 'default'.
[root@master sources]# kn channel list
NAME    TYPE              URL                                                 AGE     READY   REASON
imc01   InMemoryChannel   http://imc01-kn-channel.default.svc.cluster.local   9m14s   True    
imc02   InMemoryChannel   http://imc02-kn-channel.default.svc.cluster.local   5m43s   True

 查看channel详细信息

[root@master sources]# kn channel list imc01 -o yaml

创建两个订阅者

[root@master sources]# kn service create event-display-01 --image ikubernetes/event_display --port 8080 --scale-min 1
Creating service 'event-display-01' in namespace 'default':

  0.063s The Route is still working to reflect the latest desired specification.
  0.071s ...
  0.085s Configuration "event-display-01" is waiting for a Revision to become ready.
  6.359s ...
  6.424s Ingress has not yet been reconciled.
  6.486s Waiting for load balancer to be ready
  6.684s Ready to serve.

Service 'event-display-01' created to latest revision 'event-display-01-00001' is available at URL:
http://event-display-01.default.yang.com
[root@master sources]# kn service create event-display-02 --image ikubernetes/event_display --port 8080 --scale-min 1
Creating service 'event-display-02' in namespace 'default':

  0.061s The Route is still working to reflect the latest desired specification.
  0.099s ...
  0.119s Configuration "event-display-02" is waiting for a Revision to become ready.
  8.392s ...
  8.439s Ingress has not yet been reconciled.
  8.508s Waiting for load balancer to be ready
  8.723s Ready to serve.

Service 'event-display-02' created to latest revision 'event-display-02-00001' is available at URL:
http://event-display-02.default.yang.com
[root@master sources]# kubectl get pods
NAME                                                 READY   STATUS    RESTARTS   AGE
event-display-01-00001-deployment-57f8d8697b-glgdg   3/3     Running   0          42s
event-display-02-00001-deployment-66d7fb7bd9-xf8cx   3/3     Running   0          3m37s
[root@master sources]# kn channel delete imc02
Channel 'imc02' deleted in namespace 'default'.
[root@master sources]# kn channel list
NAME    TYPE              URL                                                 AGE   READY   REASON
imc01   InMemoryChannel   http://imc01-kn-channel.default.svc.cluster.local   18m   True

 创建两个订阅

[root@master sources]# kn subscription create sub01 --channel messaging.knative.dev:v1:InmemoryChannel:imc01 --sink ksvc:event-display-01
Subscription 'sub01' created in namespace 'default'.
[root@master sources]# kn subscription create sub02 --channel messaging.knative.dev:v1:InmemoryChannel:imc01 --sink ksvc:event-display-02
Subscription 'sub02' created in namespace 'default'.
[root@master sources]# kn subscription list
NAME    CHANNEL                 SUBSCRIBER              REPLY   DEAD LETTER SINK   READY   REASON
sub01   InmemoryChannel:imc01   ksvc:event-display-01                              True    
sub02   InmemoryChannel:imc01   ksvc:event-display-02                              True

 curl请求命令

curl -v "http://imc01-kn-channel.default.svc.cluster.local" -X POST \
-H "Ce-Id: say-hello" \
-H "Ce-Specversion: 1.0" \
-H "Ce-Type: com.magedu.sayhievent" \
-H "Ce-Time: 2022-10-02T11:36:56.7181741Z" \
-H "Ce-Source: sendoff" \
-H "Content-Type: application/json" \
-d '{"msg":"Hello MageEdu Knative from imc01!"}'

 创建一个pods集群内访问imc01

[root@master k8s-gitlab]# kubectl run client-$RANDOM --image=ikubernetes/admin-box:v1.2 --restart=Never -it --command -- /bin/sh
If you don't see a command prompt, try pressing enter.
root@client-31297 # curl -v "http://imc01-kn-channel.default.svc.cluster.local/" -X POST \
> -H "Ce-Id: say-hello" \
> -H "Ce-Specversion: 1.0" \
> -H "Ce-Type: com.magedu.sayhievent" \
> -H "Ce-Time: 2022-10-02T11:36:56.7181741Z" \
> -H "Ce-Source: sendoff" \
> -H "Content-Type: application/json" \
> -d '{"msg":"Hello MageEdu Knative from imc01!"}'
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 10.100.135.196:80...
* TCP_NODELAY set
* Connected to imc01-kn-channel.default.svc.cluster.local (10.100.135.196) port 80 (#0)
> POST / HTTP/1.1
> Host: imc01-kn-channel.default.svc.cluster.local
> User-Agent: curl/7.67.0
> Accept: */*
> Ce-Id: say-hello
> Ce-Specversion: 1.0
> Ce-Type: com.magedu.sayhievent
> Ce-Time: 2022-10-02T11:36:56.7181741Z
> Ce-Source: sendoff
> Content-Type: application/json
> Content-Length: 43
> 
* upload completely sent off: 43 out of 43 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 202 Accepted
< allow: POST, OPTIONS
< date: Fri, 21 Oct 2022 04:59:04 GMT
< content-length: 0
< x-envoy-upstream-service-time: 1
< server: envoy
< 
* Connection #0 to host imc01-kn-channel.default.svc.cluster.local left intact

请求完后查看01和02都可以看到事件

原文地址:http://www.cnblogs.com/zyyang1993/p/16813132.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性