Skip to content

Configure Ingress

The original project made use of the Spring Cloud Gateway project to configure ingress and routing.

Ingress is Istio's bread and butter. Envoy provides those capabilities. And so the dependency was removed and replaced with a standard Istio Ingress Gateway.

The Istio installation includes the Ingress Gateway component. You should be able to see the deployment in the istio-system namespace with:

kubectl get deploy -n istio-system

Ingress is configured with Istio in two parts: the gateway configuration proper, and the configuration to route requests to backing services.

Configure the Gateway

The below configuration creates a listener on the ingress gateway for HTTP traffic on port 80.

gateway.yaml
---
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: main-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 80
        name: http
        protocol: HTTP
      hosts:
      - "*"

Apply the gateway configuration to your cluster:

kubectl apply -f manifests/ingress/gateway.yaml

Since no routing has been configured yet for the gateway, a request to the gateway should return an HTTP 404 response:

curl -v http://$LB_IP/

Configure routing

The original Spring Cloud Gateway routing rules were replaced and are now captured with a standard Istio VirtualService in manifests/ingress/routes.yaml:

routes.yaml configures routing for the Istio ingress gateway (which replaces spring cloud gateway) to the application's API endpoints.

It exposes endpoints to each of the services, and in addition, routes requests with the /api/gateway prefix to the petclinic-frontend application. In the original version, the petclinic-frontend application and the gateway "proper" were bundled together as a single microservice.

routes.yaml
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: petclinic-routes
spec:
  hosts:
  - "*"
  gateways:
  - main-gateway
  http:
    - match:
      - uri:
          prefix: "/api/customer/"
      rewrite:
        uri: "/"
      route:
      - destination:
          host: customers-service.default.svc.cluster.local
          port:
            number: 8080
    - match:
      - uri:
          prefix: "/api/visit/"
      rewrite:
        uri: "/"
      route:
      - destination:
          host: visits-service.default.svc.cluster.local
          port:
            number: 8080
      timeout: 4s
    - match:
      - uri:
          prefix: "/api/vet/"
      rewrite:
        uri: "/"
      route:
      - destination:
          host: vets-service.default.svc.cluster.local
          port:
            number: 8080
    - match:
        - uri:
            prefix: "/api/gateway"
      route:
        - destination:
            host: petclinic-frontend.default.svc.cluster.local
            port:
              number: 8080
    - route:
        - destination:
            host: petclinic-frontend.default.svc.cluster.local
            port:
              number: 8080

Apply the routing rules for the gateway:

kubectl apply -f manifests/ingress/routes.yaml

Visit the app

With the application deployed and ingress configured, we can finally view the application's user interface.

To see the running PetClinic application, open a browser tab and visit http://$LB_IP/.

You should see a home page. Navigate to the Vets page, then the Pet Owners page, and finally, drill down to a specific pet owner, and otherwise get acquainted with the UI.

Next, let us explore some of the API endpoints exposed by the PetClinic application.