BookmarkSubscribeRSS Feed

How to Deploy and Score a SAS Model or Decision in Azure Kubernetes Service – Part 2

Started ‎01-06-2022 by
Modified ‎01-06-2022 by
Views 2,989

With SAS Container Runtime (SCR) you can publish a SAS rule set, decision, or a model in a container image. You can deploy the SCR image to Azure Kubernetes Service (AKS). AKS simplifies the implementation of Kubernetes clusters. It also provides all the orchestration features you need to manage cloud-native applications.

The three-part series shows you how to create and set up a simple AKS cluster, deploy and expose your scoring container to your users, through a deployment, a service and an ingress. Finally, you will learn how to score the SAS decision or the model.

 

In this post, you will learn how to create a deployment and a service manifest for a SAS Container Runtime image.

 

Link your Cluster with a Container Registry

 

The Azure Container Registry (ACR) is where the SCR container image is stored. This SCR image was published from SAS Viya.

 

Link an existing Azure Container Registry with your Azure Kubernetes Service clusters. By linking them, you allow AKS to pull images from the ACR.

 

 

ACR_NAME=modelmanager
az aks update -n $CLUSTER_NAME -g $RESOURCE_GROUP --attach-acr $ACR_NAME

 

In case you need to create an ACR:

 

az acr create --resource-group $RESOURCE_GROUP --name $ACR_NAME --sku Basic --location $LOCATION

 

You can read more about How to Publish a SAS Model to Azure with SCR.

 

 

Deployment

 

Create a Deployment Manifest

 

 

In Cloud Shell, create a manifest file for the Kubernetes deployment.

 

touch scr-deployment.yaml

 

Open the integrated editor in Cloud Shell by typing:

 

code .

 

Copy the file contents below, open the YAML file, and paste the code.

 

# scr-deployment.yaml
apiVersion: apps/v1 # Where in the API it resides
kind: Deployment # The kind of workload we're creating
metadata:
  name: scoring # This will be the name of the deployment
spec:
  selector: # Define the wrapping strategy
    matchLabels: # Match all pods with the defined labels
      app: scoring # Labels follow the `name: value` template
  template: # This is the template of the pod inside the deployment
    metadata: # Metadata for the pod
      labels:
        app: scoring
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      containers: # Here we define all containers
        - image: modelmanager.azurecr.io/autoauction3_0:latest
          name: scoring
          resources:
            requests: # Minimum amount of resources requested
              cpu: 100m
              memory: 128Mi
            limits: # Maximum amount of resources requested
              cpu: 250m
              memory: 256Mi
          ports:
            - containerPort: 8080 # The SCR container exposes this port
              name: http # We named that port "http" so we can refer to it later

 

Save the manifest file and close the editor.  

 

Apply the Manifest

 

In Cloud Shell, run the kubectl apply command to submit the deployment manifest to your cluster.

 

kubectl apply -f ./scr-deployment.yaml

 

The command should output a result similar to the following example.

 

deployment.apps/scoring created

 

Run the command to check if the deployment was successful.

 

kubectl get deploy scoring

 

After a minute or so, the command should output a table similar to the following example.

 

NAME      READY   UP-TO-DATE   AVAILABLE   AGE
scoring   1/1     1            1           85s

 

Run the command to check if the pod is running.

 

kubectl get pods

 

Check the READY status before you move forward.

 

NAME                       READY   STATUS    RESTARTS   AGE
scoring-5dd6f469bf-tt6pm   1/1     Running   0          117s

 

Enable Network Access to an Application

A Kubernetes service is a workload that abstracts the IP address for networked workloads. A Kubernetes service acts as a load balancer and redirects traffic to specified ports by using port-forwarding rules.

 

Create a Service Manifest

 

 

In Cloud Shell, create a manifest file for the Kubernetes service.

 

touch scr-service.yaml

 

Open the integrated editor in Cloud Shell by entering:

 

code .

 

Copy the file contents below, open the YAML file, and paste the code.

 

# scr-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: scoring
spec:
  type: ClusterIP
  selector:
    app: scoring
  ports:
    - port: 80 # SERVICE exposed port
      name: http # SERVICE port name
      protocol: TCP # The protocol the SERVICE will listen to
      targetPort: http # Port to forward to in the POD

 

Deploy the Service

 

In Cloud Shell, run the kubectl apply command to submit the service manifest to your cluster.

 

kubectl apply -f ./scr-service.yaml

 

The command should output a result similar to the following example:

 

service/scoring created

 

Run the kubectl get service command to check if the deployment was successful.

 

kubectl get service scoring

 

The command should output a result similar to the following example.

 

NAME      TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
scoring   ClusterIP   10.0.14.34           80/TCP    2m36s

 

Note that the service only makes the pod accessible within the cluster, using an internal IP. No external IP is associated with the service.

 

Conclusion

The second step was to create an Azure Kubernetes Service deployment and a service, by using manifest files. The deployment creates a pod from the SCR image. The service exposes the pod within the cluster. 

 

Read Further

 

Read the next post in the series, to find out how to create an ingress, using YAML files, to route internet traffic to the service inside the clus....

Read the previous post, how to create and set up a simple AKS cluster.

 

Thank you for your time reading this article. If you liked the article, give it a thumbs up! Please comment and tell us what you think about SAS Container Runtime and Azure deployments.

Version history
Last update:
‎01-06-2022 12:28 AM
Updated by:
Contributors

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started