Skip to content

Is there a way to expose multiple ports on a single Knative service #7140

Closed

Description

@Tomcli

Ask your question here:

Hi. We want to expose multiple ports on the Knative service. However, it seems like it doesn't allow more than one custom port according to the validation. https://github.com/knative/serving/blob/master/pkg/apis/serving/k8s_validation.go#L397-L406

Is there any way we could work around this? Thank you.

Activity

  1. added
    kind/question
    on Mar 4, 2020
  2. vagababov commented on Mar 4, 2020

    @vagababov
    Contributor

    Can you describe the use case?

  3. Tomcli commented on Mar 4, 2020

    @Tomcli
    Author

    We have a container that exposed http and grpc on two different port. we want to use a single Knative service to map those two ports like the following.

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: custom-sample-predictor
    spec:
      template:
        metadata:
          annotations:
            autoscaling.knative.dev/class: kpa.autoscaling.knative.dev
            autoscaling.knative.dev/maxScale: "1"
            autoscaling.knative.dev/minScale: "1"
            autoscaling.knative.dev/target: "1"
            queue.sidecar.serving.knative.dev/resourcePercentage: "0.2"
        spec:
          containerConcurrency: 0
          containers:
          - env:
            - name: TARGET
              value: Python KFServing Sample
            image: tomcli/custom-sample
            ports:
              - name: h2c
                containerPort: 8080
              - name: http1
                containerPort: 8081
            name: user-container
            resources:
              limits:
                cpu: "2"
                memory: 4Gi
              requests:
                cpu: "2"
                memory: 2Gi
          timeoutSeconds: 60
      traffic:
      - latestRevision: true
        percent: 100

    However, with the current validation test, we are only allowed to have one port per Knative service. Is there an other way that can achieve the same use case? Thanks

  4. vagababov commented on Mar 4, 2020

    @vagababov
    Contributor
  5. mattmoor commented on Mar 5, 2020

    @mattmoor
    Contributor

    This is complicated for a variety of reasons, and probably not something we'll support anytime soon (if ever). Most of the reasons that come to mind are networking related so cc @tcnghia

    In the meantime, is it possible to multiplex the http handling alongside the GRPC handling?

  6. dprotaso commented on Mar 5, 2020

    @dprotaso
    Member

    @Tomcli can you comment on the specifics of your workload

    I'm curious about the following:

    1. What's the purpose for each port being exposed?
    2. What's the exposure of each port (ie. are they both public to the internet)
    3. What type of traffic/load does each port receive?
    4. How do you expect this app to scale as the traffic/load increases/decreases.
  7. Tomcli commented on Mar 5, 2020

    @Tomcli
    Author

    Hi @dprotaso, one of our use cases is to use tensorflow serving on Knative.

    Below are the answers to your questions:

    1. TensorFlow serving has http and grpc hosted on two different port. They both are used for model prediction but with different protocol.
    2. Both of the ports should be public to all users.
    3. It depends on the model, most of the time the http port will receive restful requests such as Posting JSON formatted data. grpc port will receive data in TensorProto created by TensorFlow.
    4. We are planning to scale based on the number of concurrent requests or cpu/gpu consumption.
  8. dprotaso commented on Mar 5, 2020

    @dprotaso
    Member

    We are planning to scale based on the number of concurrent requests or cpu/gpu consumption.

    Is this scaling on the number of concurrent requests tied to a specific port?

  9. dprotaso commented on Mar 5, 2020

    @dprotaso
    Member

    TensorFlow serving has http and grpc hosted on two different port. They both are used for model prediction but with different protocol.

    If it's a matter of a different protocols you could run two separate Knative Services.

  10. mattmoor commented on Mar 5, 2020

    @mattmoor
    Contributor

    Can GRPC not multiplex the GRPC handlers alongside non-GRPC http/2 handlers?

  11. dprotaso commented on Mar 5, 2020

    @dprotaso
    Member

    It requires some work and is language specific

    We use it in our tests

    func httpWrapper(g *grpc.Server) http.Handler {
    return servingnetwork.NewProbeHandler(
    http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    if r.ProtoMajor == 2 && r.Header.Get("Content-Type") == "application/grpc" {
    g.ServeHTTP(w, r)
    }
    }),
    )
    }

    func NewServer(addr string, h http.Handler) *http.Server {
    h1s := &http.Server{
    Addr: addr,
    Handler: h2c.NewHandler(h, &http2.Server{}),
    }
    return h1s
    }

    @Tomcli that's the other option worth exploring - then you'd have the expected behaviour you want with a single port

  12. Tomcli commented on Mar 5, 2020

    @Tomcli
    Author

    Thanks @dprotaso, we will try to explore these options and see can it fit in our scenario.

  13. dprotaso commented on Apr 8, 2020

    @dprotaso
    Member
  14. dprotaso commented on Apr 8, 2020

    @dprotaso
    Member

    This topic came up at the API WG meeting (2020-04-08) see notes & recording here

  15. knative-housekeeping-robot commented on Jul 8, 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

  16. added
    lifecycle/stale
    on Jul 8, 2020
  17. mattmoor commented on Jul 8, 2020

    @mattmoor
    Contributor

    /remove-lifecycle stale

  18. removed
    lifecycle/stale
    on Jul 8, 2020
  19. mattmoor commented on Aug 17, 2020

    @mattmoor
    Contributor

    Consolidating these under: #8471

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/question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions