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 |
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 |
persist-reviews |
Persists all moderated reviews to a Postgresql database. You will deploy this service in the next steps. |
The red box in the diagram below highlights the Knative Services that you will be deploying within this section.
2. Deploy Knative Services
-
Click to navigate to the OpenShift Console’s Administrator view, and access the {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-reviewsandaiml-sentiment-reviews). In the next step, you will create thepersist-reviewsKnative service using a Custom Resource Definition (CRD).If you see an error (services.serving.knative.dev is forbidden) instead of the two services, make sure you have selected the project globex-serverless-{user_name}
-
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
apiVersion: serving.knative.dev/v1 kind: Service metadata: name: persist-reviews namespace: globex-serverless-{user_name} 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 -
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
3. A note on the newly created persist-reviews
-
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. -
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.