How to expose knative service to outside world via ingress

11/20/2019

Below is my knative service sample

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: test-svc
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/minScale: "1"
    spec:
      serviceAccountName: default
      containers:
      - image: ******************
        imagePullPolicy: IfNotPresent
        name: test-svc
        envFrom:
        - secretRef:
           name: test-env
kubectl get ksvc

NAME       URL                                   LATESTCREATED    LATESTREADY      READY     REASON
test-svc   http://test-svc.kube-system.kasl.io   test-svc-8v6gv   test-svc-8v6gv   True

Gateway+virual service

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: httpbin-gateway
spec:
  selector:
    istio: ingressgateway # use Istio default gateway implementation
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: httpbin
spec:
  hosts:
  - "*"
  gateways:
  - httpbin-gateway
  http:
  - match:
    - uri:
        prefix: /headers
    route:
    - destination:
        host: istio-ingressgateway.istio-system.svc.cluster.local

if i do curl -v http://test-svc.kube-system.kasl.io inside cluster its working perfectly Below is my knative service sample

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: test-svc
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/minScale: "1"
    spec:
      serviceAccountName: default
      containers:
      - image: ******************
        imagePullPolicy: IfNotPresent
        name: test-svc
        envFrom:
        - secretRef:
           name: test-env
kubectl get ksvc

NAME       URL                                   LATESTCREATED    LATESTREADY      READY     REASON
test-svc   http://test-svc.kube-system.kasl.io   test-svc-8v6gv   test-svc-8v6gv   True

Gateway+virual service

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: httpbin-gateway
spec:
  selector:
    istio: ingressgateway # use Istio default gateway implementation
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: httpbin
spec:
  hosts:
  - "*"
  gateways:
  - httpbin-gateway
  http:
  - match:
    - uri:
        prefix: /headers
    route:
    - destination:
        host: istio-ingressgateway.istio-system.svc.cluster.local

if i do curl -v http://test-svc.kube-system.kasl.io inside cluster its working

Now i want to expose these service to outside cluster

-- Bala Krishna
google-kubernetes-engine
istio
knative
kubernetes
kubernetes-ingress

1 Answer

11/20/2019

Knative uses a shared ingress gateway to serve all incoming traffic within Knative service mesh, which is the knative-ingress-gateway gateway under knative-serving namespace. By default, it uses Istio gateway service istio-ingressgateway under istio-system namespace as its underlying service. You can replace the service with that of your own as follows[1]and for more detail steps refer to link[2].

[1]https://knative.dev/docs/serving/setting-up-custom-ingress-gateway/ [2]https://starkandwayne.com/blog/public-traffic-into-knative-on-gke/

-- Ali Reza Izadi
Source: StackOverflow