If you want you can access ML APIs externally.
About this task
Earlier the Product Master - Machine learning (product master-ml) service was of the
type Nodeport
. Now, the service type has changed to ClusterIP
. In this type, by
default, the ports are not exposed. So, to now access the ML service externally through
browser, you need to create a route through the Red Hat®
OpenShift® web console.
Procedure
-
Edit the ML service network policy.
-
Add the following values in the ml-networkpolicy file in the
ingress
section.
- namespaceSelector
- matchLabels
- policy-group.network.openshift.io/ingress
Example
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: np-ml
namespace: cpd-instance
spec:
ingress:
- from:
- namespaceSelector:
matchLabels:
policy-group.network.openshift.io/ingress: ""
- podSelector:
matchLabels:
app: productmaster-sch
- podSelector:
matchLabels:
app: productmaster-wfl
ports:
- port: 5000
protocol: TCP
- port: 5010
protocol: TCP
- port: 5020
protocol: TCP
- port: 5030
protocol: TCP
- port: 50000
protocol: TCP
podSelector:
matchLabels:
app: productmaster-ml
policyTypes:
- Ingress
-
Create route through which you can access the ML service.
-
Log in to your Red Hat
OpenShift
instance as an administrator.
-
Click from the left panel.
-
Specify the following, and click Create.
- Name - The route name.
- Service - productmaster-ml-service
- Port - 5000
-
Optional - To create a route through terminal, proceed as follows.
- Add the following value in the ML service route file.
- host
- The host name.
- namespace
- The namespace where you have installed the Product Master.
kind: Route
apiVersion: route.openshift.io/v1
metadata:
name: ml-route
namespace: ${PROJECT_CPD_INST_OPERANDS}
spec:
host: <host>
to:
kind: Service
name: productmaster-ml-service
weight: 100
port:
targetPort: http
wildcardPolicy: None
- Check if the route has been created successfully by using the following
command.
oc get route | grep ml-route
Output
displays the name of the ML host. Access the route using the following
URL:http://<ML-host>/
Results
Click the new route, to see a label with location that contains a URL. Click this URL to
access the ML service through a browser.