Skip to content

Latest commit

 

History

History

Bet.AspNetCore.Sample

AspNetCore Web Application Sample

GitHub license

buymeacoffee

Give a Star! ⭐

If you like or are using this project to learn or start your solution, please give it a star. Thanks!

NOTE

In order for KeyManagementOptionsSetup to work on the local machine with MSI 1.) Visual Studio.NET and 2.) Azure CLI must be authenticated under the same user account

Summary

This project demonstrates how to utilize:

  • Sentiment and Spam ML models with AspNetCore application
  1. ML.NET Batch predictions requests.
  2. ML.NET Models Generations on start.
  3. ML.NET Models generation on schedule basis.
  4. ML.NET Models HealthChecks
  5. ML.NET Models file watch with File, Azure providers
  • Kubernetes DataProtection provider to store the encryptions keys in Azure Storage Blob.

The building of the models occurs on the launch of the application and the Http traffic is not served until the Initial job has been completed.

Live https://betweb.kingdavidconsulting.com/

These models can be found at the following projects:

The folder named MLContent contains pre-generated ML.NET models that the Web Api Controllers use for the predictions when true is set to true.

Build and Deploy

Testing K8 Cron Job in the local cluster please follow the setup instruction per K8.DotNetCore.Workshop.

Make sure to execute all of the commands from the solution folder.

  1. Build the Image
    # builds and runs the container
    docker-compose -f "docker-compose.yml" -f "docker-compose.override.yml" up -d  bet.web

    # simply builds the image
    docker-compose -f "docker-compose.yml" up -d --build --no-recreate  bet.web

    # publish if needed
    docker push kdcllc/bet:web
  1. Helm Install
    # install web api in the local Kubernetes cluster
    helm install betweb k8s/betweb --set ingress.enabled=false,aadpodidbinding=test,local.enabled=true

    # unistall web api project
    helm uninstall betweb

    # verify the pod
    kubectl describe pod betweb

ML Model HealthCheck

In a situation where the model is being build in the same container and the web api if the model generation fails the container should be restarted.

            services.AddHealthChecks()
                 .AddSslCertificateCheck("kdcllc", "https://kingdavidconsulting.com")
                .AddUriHealthCheck("200_check", builder =>
                {
                    builder.Add(option =>
                    {
                        option.AddUri("https://httpstat.us/200")
                               .UseExpectedHttpCode(HttpStatusCode.OK);
                    });

                    builder.Add(option =>
                    {
                        option.AddUri("https://httpstat.us/203")
                               .UseExpectedHttpCode(HttpStatusCode.NonAuthoritativeInformation);
                    });
                })
                .AddUriHealthCheck("ms_check", uriOptions: (options) =>
                {
                    options.AddUri("https://httpstat.us/503").UseExpectedHttpCode(503);
                })
                .AddMachineLearningModelCheck<SpamInput, SpamPrediction>("Spam_Check")
                .AddMachineLearningModelCheck<SentimentObservation, SentimentPrediction>("Sentiment_Check")
                .AddAzureBlobStorageCheck("files_check", "files", options =>
                {
                    options.Name = "betstorage";
                })
                .AddSigtermCheck("sigterm_check")
                .AddLoggerPublisher(new List<string> { "sigterm_check" });

Machine Learning

Batch testing of values

[
  {
    "label": false,
    "text": "This is a very rude movie"
  },
  {
    "label": true,
    "text": "Hate All Of You're Work"
  }
]

Future work

  • To enable the functionality to accept new data point and storing them inside of SQLite or other storage.

About Docker Images

This repo is utilizing King David Consulting LLC Docker Images: