Skip to content

A DotNet Core WebAPI Sample, w. Docker and AKS demos

License

Notifications You must be signed in to change notification settings

lulzzz/CustomerAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ASP.NET Core WebAPI w. Swashbuckle/Swagger

This little demo app is to show how to:

  • Implement an ASP.NET Core Web API project
  • Customize it with a global error handler
  • Add and customize swagger
  • Build a docker container
  • Run it locally
  • Deploy it to Azure Kubernetes Service (AKS)

Libraries

Visual Studio

Hitting Debug-Start will start the app on a randomly supplied port navigate to

http://localhost:[port]/swagger

To see the swagger UI page.

Dockerize

To dockerize the app, we supply a docker file, and a build

Selecting a Port

In this example, port 5000 is configured. To change that, you will need to search all the source code for that port and replace it, here is a list of places to change:

Visual Studio:

  • .\Properties\launchSettings.json
  • .\Program.cs

Docker Files:

  • .\docker-compose.override.yml
  • .\Dockerfile

Kubernetes Files:

  • .\deployment.yaml
  • .\service.yaml

Docker

Build Bash Script:

#!/bin/bash
set -x
CT={your registry name}/customerapi
dotnet restore ./customerAPI.sln && dotnet publish ./customerAPI.sln -c Release -o ./obj/Docker/publish
docker build -t $CT .
docker push $CT

Run Locally on Docker for Windows:

#!/bin/bash
CT={your registry name}/customerapi
winpty docker run -d -p 5000:5000 $CT --name customerapi
start http://localhost:5000/swagger

This will run it locally, and then browse to the swagger UI page

Deploy to Azure Kubernetes Service (AKS)

kubectl create -f deployment.yaml
kubectl create -f service.yaml

Test:

Go to your Azure subscription, find your agents external ip address, and browse to it, on your port (default: 5000) and go to the swagger page:

http://{external ip address}:{port}/swagger

Clean up:

To delete your assets from your AKS:

kubectl delete service customerapi
kubectl delete deployment customerapi-deployment

Pro-Tip:

Shutdown your AKS Agent VMs when not in use to save $$$

About

Stuart Williams Cloud/DevOps Practice Lead   Magenic Technologies Inc. Office of the CTO   stuartw@magenic.com (e-mail)   Blog: http://blitzkriegsoftware.net/Blog LinkedIn: http://lnkd.in/P35kVT YouTube: https://www.youtube.com/channel/UCO88zFRJMTrAZZbYzhvAlMg

About

A DotNet Core WebAPI Sample, w. Docker and AKS demos

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages