ApplicationInsights-Kubernetes/examples/BuildOutOfContainer
Saar Shen 6254a1b9fe
Add an example (#225)
* Add an example

* Address some code review feedback
2021-04-02 10:41:50 -07:00
..
.vscode Add an example (#225) 2021-04-02 10:41:50 -07:00
Controllers Add an example (#225) 2021-04-02 10:41:50 -07:00
BuildOutOfContainer.csproj Add an example (#225) 2021-04-02 10:41:50 -07:00
Dockerfile Add an example (#225) 2021-04-02 10:41:50 -07:00
K8s.yaml Add an example (#225) 2021-04-02 10:41:50 -07:00
Program.cs Add an example (#225) 2021-04-02 10:41:50 -07:00
Readme.md Add an example (#225) 2021-04-02 10:41:50 -07:00
Startup.cs Add an example (#225) 2021-04-02 10:41:50 -07:00
WeatherForecast.cs Add an example (#225) 2021-04-02 10:41:50 -07:00
appsettings.json Add an example (#225) 2021-04-02 10:41:50 -07:00

Readme.md

Example of building the application out of container

This is an example when building the application out of the container.

Prepare this example to try it locally

There are some placeholders to update if you want to run this by yourself:

  • Edit appsettings.json, update the ConnectionString. You can get a connection string from Azure Portal UI on your application insights resource. Refer to Connection strings for more details.

  • In the following steps, when build / push the images, replace dockerhubaccount with your own account name. Also, update it in K8s.yaml so that the image pull will success.

Build the container

  • Build/Publish the binaries locally

    dotnet publish -c Release
    
  • If it is the first time running, pull the base image:

    docker pull mcr.microsoft.com/dotnet/aspnet:5.0
    
  • Build the container:

    docker build -t dockerhubaccount/ai-k8s-oc .
    

Push the built container to docker

docker push dockerhubaccount/ai-k8s-oc

Create a deployment and a service

Refer to K8s.yaml for an example.

  • Create the deployment and the service:

    kubectl create -f K8s.yaml
    

Notice a service is exposed on port 30007.

  • Invoke the endpoints:

    curl http://localhost:30007/weatherforecast
    
  • Inspect the logs of the pod

    kubectl get pod
    kubectl logs <podName>
    

Remove the deployment afterwards for cleanup

kubectl delete -f .\K8s.yaml

Got:

deployment.apps "ai-k8s-webapi" deleted
service "ai-k8s-oc-webapi-svc" deleted