Deploy Knative Services

1. Overview

As a first step, let us ensure all the services are created. A few of the services are predeployed in your OpenShift cluster. These services are built using the Knative Serving framework.

Knative Services are used to deploy and manage the whole lifecycle of your workload. The Knative Serving component scale the Knative Services based on configuration, metrics and incoming requests.

There are 3 Knative Services that are used in this solution

Service name

Function

aiml-moderate-reviews

Checks if the product reviews are acceptable or abusive, and assigns a score (0 or 1) accordingly. The reviews with a score are sent to reviews.moderated topic,

aiml-sentiment-reviews

Analyses the product reviews and creates a new message with a sentiment score; The reviews with a sentiment score are sent to reviews.sentiment topic. This service is predeployed.

persist-reviews

Persists all moderated reviews to a Postgresql database. You will deploy this service in the next steps.

2. Deploy Knative Services

  1. Navigate to the OpenShift Console’s Administrator view, and go to {openshift_cluster_console}/serving/ns/globex-serverless-{user_name}[Serverless > Serving^, window="console"] menu. You will see that two of the above mentioned services have been already deployed (aiml-moderate-reviews and aiml-sentiment-reviews).
    In the next step, you will create the persist-reviews Knative service using a Custom Resource Definition (CRD).

    serverless 2knative services
  2. Create persist-reviews: Click on the Create button highlighted in the screenshot above. Choose Create > Service option. Replace all existing content with the following YAML file, and click on Save

    create knative service
    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: persist-reviews
      namespace: globex-serverless-user1
    spec:
      template:
        metadata:
          annotations:
            autoscaling.knative.dev/min-scale: "1"
        spec:
          containers:
            - image: quay.io/globex-sentiment-analysis/persist-reviews:latest
              volumeMounts:
                - mountPath: /deployments/config
                  name: config
                  readOnly: true
              securityContext:
                runAsNonRoot: true
                allowPrivilegeEscalation: false
                capabilities:
                  drop:
                    - ALL
                seccompProfile:
                  type: RuntimeDefault
          volumes:
            - name: config
              secret:
                secretName: persist-reviews
  3. Navigate back to the {openshift_cluster_console}/topology/ns/globex-serverless-{user_name}?view=graph[Developer > Topology, window="console", target="console"] view of the globex-serverless-{user_name} namespace and you will notice all the three Knative services

    3knative service

3. A note on the newly created persist-reviews

  1. This service is shown with a dark blue colour because of the annotation autoscaling.knative.dev/min-scale: "1" added in the YAML while creation of this service. This means a minimum of one pod is running all the time, instead of it scaling down to zero (0) like the other two services.

  2. With just providing the container image, Knative Serving creates all the other needed Kubernetes resources (Services, Routes, Configurations, and Revisions) - making it easier for developers to create such services quickly.