Skip to content

Receive and serve Events on multiple ports #6792

Closed

Description

@josiemundi

Ask your question here:

Background:

I have been experimenting with a scenario using Knative Eventing. As part of the scenario, we have an event source which receives events (via web socket) and sinks them to the broker. The broker then sends these events on to a Knative Serving service; a process initiated by our trigger. 

Currently, in the Knative documentation, the way to view and verify events received by a service is via logs, however we want to display the events in a web UI (streamed over SSE or WebSockets). In order to do this, we want our service to receive CloudEvents on one port and serve the web UI on another port.

Issue:

Our service receives cloud events from the broker using the server created by the cloud events package and then allows the stream to be viewed via a web browser using the standard http package. As part of this we can’t both receive the CloudEvents (using kncloudevents) on one port and serve them (e.g using go http) on another, as Knative does not allow multiple ports (https://github.com/knative/serving/blob/master/docs/runtime-contract.md#protocols-and-ports).

If one wants to receive CloudEvents and serve them in real-time using Knative eventing, this does not currently seem possible. This would be used, for example, for real-time updating of display for open web pages or applications.

Proposed solutions to the problem:

  • Use mux and specify path - This method only uses one port, which is not ideal as we would may be exposing an internal use port externally. I have found the following tutorial which seems to be doing the same thing (using the mux approach):

https://github.com/mchmarny/tweetviewer/blob/master/main.go

  • Deploy as a native Kubernetes service

Theoretically, would it be better to use a pull based approach instead? In this case, the event display could go and get the events from the Broker?

I’d be interested to know whether there are any thoughts on this issue. Is it possible that Knative serving would allow multiple ports in the future or is there any plan to make the Knative CloudEvents receiver integrate with the ability to also serve? 

Activity

  1. added
    kind/question
    on Feb 10, 2020
  2. astoycos commented on Feb 28, 2020

    @astoycos

    I am in the same boat, I have written a custom container source to connect Enmasse (A scalable K8s native messaging infrastructure) to Knative. And to demonstrate the usefulness of this I put together a demo where I am simulating an IOT camera that is streaming video through Enmasse to a Knative service, which 1) Listens for incoming CEs containing the video (port 8080) 2) Does some basic tensorflow image analysis and 3) serves the analyzed frames using a flask web server(port 8000). The issue is I can only expose one port for a Knative service, so the demo works however I cannot access the web app since port 8080 is busy listening for incoming messages. The only workaround for this that i've found is to do a manual port forward from my local device and then I can view the webapp through my localhost.

    I believe this was done to ensure the liveliness probe is accurately representing the state of the pod, since if two ports were exposed the probe could signal ready at one port and not know about the other. Also, to keep in memory processing to a minimum within the service

    A current "fix" is to have an intermediate persistent data store that the Knative service can read from

  3. josiemundi commented on Feb 29, 2020

    @josiemundi
    Author

    Hi @astoycos the iot container source looks cool! I'd like to try it out.

    I managed to implement a working Knative Eventing scenario where I could get the cloudEvents received and separate http server on different ports. However, this is done by deploying my service as a native Kubernetes service rather than Knative service. Here is a link to the code and there are instructions:

    https://github.com/josiemundi/knative-web-event-display

    In a way, it's interesting that if you are using eventing you seemingly can't expose another service from the same pod using Knative Serving. This seems to limit some of the things you might want to do with eventing.

  4. astoycos commented on Mar 3, 2020

    @astoycos

    @josiemundi I like how you solved it and pulling data from the Bitcoin API is super Cool! A K8s service was my alternative/backup idea as well, but I really wanted to break some rules and make it work with Knative :) I was actually able to get past the bottleneck by specifying the containersource sink endpoint as https://<service_podIP>:port to exploit the Pod2Pod networking properties of K8's, however this kind of defeats the purpose of Knative since I have to reconfigure this IP anytime the service Scales down and back up again. I talk about it more here:

    https://medium.com/@astoycos/realtime-iot-video-analysis-on-openshift-51dcbacc70f1

    And there's also a link to a video of my demo.

    So for your application what parts scale based on demand? The Container source is always running and the service is now K8s so it wouldn't scale but does the broker/trigger still auto scale?

  5. knative-housekeeping-robot commented on Jun 2, 2020

    @knative-housekeeping-robot

    Issues go stale after 90 days of inactivity.
    Mark the issue as fresh by adding the comment /remove-lifecycle stale.
    Stale issues rot after an additional 30 days of inactivity and eventually close.
    If this issue is safe to close now please do so by adding the comment /close.

    Send feedback to Knative Productivity Slack channel or file an issue in knative/test-infra.

    /lifecycle stale

  6. added
    lifecycle/stale
    on Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/questionlifecycle/stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions