2

Is it possible to have Knative automatically create K8s Ingress resources?

Hello all, Based on the following lines from documentation, I was wondering if I can have Knative automatically create the Ingress resources for my service? I haven't found details on this in the documentation.

After the service has been created, Knative performs the following tasks:

- Creates a new immutable revision for this version of the app.
- Performs network programming to create a route, ingress, service, and load balancer for your app.
- Automatically scales your pods up and down based on traffic, including to zero active pods.

Example: Taking the Service and Ingress definition below, would it be possible to abstract away the Ingress yaml and have knative take care of its creation automatically for services?

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello
  namespace: knative
spec:
  template:
    metadata:
      labels:
        app: nonprofit
      annotations:
        queue.sidecar.serving.knative.dev/resourcePercentage: "10"
        autoscaling.knative.dev/class: "kpa.autoscaling.knative.dev"
        autoscaling.knative.dev/target: "40"
        autoscaling.knative.dev/min-scale: "1"
        autoscaling.knative.dev/max-scale: "3"
    spec:
      containers:
        - image: gcr.io/knative-samples/helloworld-java
          resources:
            requests:
              cpu: 50m
              memory: 100M
            limits:
              cpu: 200m
              memory: 200M
          ports:
            - containerPort: 8080
          env:
            - name: TARGET
              value: "Sunny Day"
  traffic:
  - tag: latest
    latestRevision: true
    percent: 100
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: knative-hello-ingress
  namespace: knative
  annotations:
    nginx.ingress.kubernetes.io/upstream-vhost: "hello.knative"
spec:
  ingressClassName: "ingress-generic"
  rules:
  - host: "hello-knative.com"
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: hello
            port:
              number: 80

Thank you,

Haven't tried anything as I haven't found details in the documentation regarding this.

Desolar1um
  • 85
  • 5
  • Have you checked this document on [Configuring Services Custom ingress class](https://knative.dev/docs/serving/services/ingress-class/). Let me know if this helps. – Fariya Rahmat Apr 24 '23 at 12:22
  • @FariyaRahmat Thanks for the response. Yes I have. I neglected to mention in the question that I am using an nginx ingress controller for access to the cluster, and the Ingress I wrote in the question is essentially to have nginx controller reroute the requests to the Knative service – Desolar1um Apr 25 '23 at 09:48

1 Answers1

2

Unfortunately, the v1 Ingress API in Kubernetes does not have sufficient capabilities to express Knative's routing requirements. Knative does support several ingress implementations (including Istio, Contour, and the Gateway API), but no one has written a plugin for the Nginx Ingress annotations.

Some of the capabilities that are missing from the Kubernetes Ingress API which are needed by Knative include:

  • Backend traffic splits / weights
  • Setting request headers to the backend server
  • Requesting HTTP/2 or websockets protocol support

If you're willing to use bets software, the Gateway API plugin is mostly feature complete and should plug into a variety of ingress providers. Unfortunately, Nginx does not appear to be on that list.

E. Anderson
  • 3,405
  • 1
  • 16
  • 19