The MLOps model package export feature used in this procedure is off by default. Contact your DataRobot representative or administrator for information on enabling it.
Feature flag: Enable MMM model package export
The following describes the process of deploying a DataRobot model on the Google Cloud Platform (GCP) using the Google Kubernetes Engine (GKE).
DataRobot MLOps provides a central hub to deploy, monitor, manage, and govern all your models in production. With MLOps, you aren't limited to serving DataRobot models on the dedicated scalable prediction servers inside the DataRobot cluster. You can also deploy DataRobot models into Kubernetes (K8s) clusters while maintaining the advantages of DataRobot's model monitoring capabilities.
This exportable DataRobot model is called a Portable Prediction Server (PPS) and is similar to Docker containers in the flexibility and portability it provides. A PPS is based on Docker containers and contains a DataRobot model with embedded monitoring agents. Using this approach, a DataRobot model is made available via a scalable deployment environment for usage, and associated data can be tracked in the centralized DataRobot MLOps dashboard with all of its monitoring and governance advantages.
Unifying the portability of DataRobot model Docker images with the scalability of a K8s platform results in a powerful ML solution ready for production usage.
The following sections, each a step in the process, describe the procedure for deploying and monitoring DataRobot models on the GCP platform via a PPS. The examples use the Kaggle housing prices dataset.
Build models using the housing prices dataset. Once Autopilot finishes, you can create and download the MLOps model package. To do this, navigate to the Models tab to select a model and click Predict > Deploy. In the MLOps Package section, select Generate & Download.
DataRobot generates a model package (.mlpkg file) containing all the necessary information about the model.
Set the PROJECT_ID environment variable to your Google Cloud project ID (the project ID you defined during the Google Cloud SDK installation). The PROJECT_ID associates the container image with your project's Container Registry:
Run the docker images command to verify that the build was successful:
The generated image contains the DataRobot model and the monitoring agent used to transfer the service and model health metrics back to the DataRobot MLOps platform.
Once you have tested and validated the container image locally, upload it to a registry so that your Google Kubernetes Engine (GKE) cluster can download and run it.
Configure the Docker command-line tool to authenticate to Container Registry:
gcloud auth configure-docker
Push the Docker image you built to the Container Registry:
Pushing to the Container Registry may result in the storage.buckets.create permission issue. If you receive this error, contact the administrator of your GCP account.
After the command completes, run the following command to see the cluster worker instances:
gcloud compute instances list
The output is similar to:
Note
Pushing to the Container Registry may result in the gcloud.container.clusters.create permission issue. If you receive this error, contact the administrator of your GCP account.
K8s provides the ability to manage resources in a flexible, automatic manner. For example, you can create a HorizontalPodAutoscaler resource for your deployment:
Run the following command to check that the pods you created are all operational and in a running state (e.g., you may to see up to 5 running pods as requested in the previous autoscale step):
The default service type in GKE is called ClusterIP, where the service gets an IP address reachable only from inside the cluster. To expose a Kubernetes service outside of the cluster, you must create a service of type LoadBalancer. This type of service spawns an External Load Balancer IP for a set of pods, reachable via the internet.
Use the kubectl expose command to generate a Kubernetes service for the house-regression-app deployment:
--port is the port number configured on the Load Balancer
--target-port is the port number that the house-regression-app container is listening on.
Run the following command to view service details:
kubectl get service
The output is similar to:
Copy the EXTERNAL-IP address from the service details.
Score your model using the EXTERNAL-IP address.
curl -X POST http://XX.XX.XX.XX/predictions -H "Content-Type: text/csv" --data- binary @/Users/X.X/community/docker/kaggle_house_test_dataset.csv
Note
Update the IP address placeholder above with the EXTERNAL-IP address you copied and update the path to the kaggle_house_test_dataset.csv dataset to match the path locally on your workstation.
Note
The cluster is open to all incoming requests at this point. See the Google documentation to apply more fine-grained role-based access control (RBAC).
Finally, update the K8s deployment configuration with the PPS and monitoring agent configuration. Add the following environment variables into the K8s Deployment configuration (see the complete configuration file here):
apiVersion:apps/v1kind:Deploymentmetadata:annotations:deployment.kubernetes.io/revision:"2"creationTimestamp:"2020-07-08T12:47:27Z"generation:8labels:app:house-regression-appname:house-regression-appnamespace:defaultresourceVersion:"14171"selfLink:/apis/apps/v1/namespaces/default/deployments/house-regression-appuid:2de869fc-c119-11ea-8156-42010a840053spec:progressDeadlineSeconds:600replicas:5revisionHistoryLimit:10selector:matchLabels:app:house-regression-appstrategy:rollingUpdate:maxSurge:25%maxUnavailable:25%type:RollingUpdatetemplate:metadata:creationTimestamp:nulllabels:app:house-regression-appspec:containers:-env:-name:PORTABLE_PREDICTION_API_WORKERS_NUMBERvalue:"2"-name:PORTABLE_PREDICTION_API_MONITORING_ACTIVEvalue:"True"-name:PORTABLE_PREDICTION_API_MONITORING_SETTINGSvalue:output_type=output_dir;path=/tmp;max_files=50;file_max_size=10240000;model_id=<your_mlops_model_id>;deployment_id=<your_mlops_deployment_id>-name:MONITORING_AGENTvalue:"True"-name:MONITORING_AGENT_DATAROBOT_APP_URLvalue:https://app.datarobot.com/-name:MONITORING_AGENT_DATAROBOT_APP_TOKENvalue:<your_datarobot_api_token>image:gcr.io/${PROJECT_ID}/house-regression-model:v1imagePullPolicy:IfNotPresentname:house-regression-modelresources:{}terminationMessagePath:/dev/termination-logterminationMessagePolicy:FilednsPolicy:ClusterFirstrestartPolicy:AlwaysschedulerName:default-schedulersecurityContext:{}terminationGracePeriodSeconds:30status:availableReplicas:5conditions:-lastTransitionTime:"2020-07-08T12:47:27Z"lastUpdateTime:"2020-07-08T13:40:47Z"message:ReplicaSet "house-regression-app-855b44f748" has successfully progressed.reason:NewReplicaSetAvailablestatus:"True"type:Progressing-lastTransitionTime:"2020-07-08T13:41:39Z"lastUpdateTime:"2020-07-08T13:41:39Z"message:Deployment has minimum availability.reason:MinimumReplicasAvailablestatus:"True"type:AvailableobservedGeneration:8readyReplicas:5replicas:5updatedReplicas:5