Coder Social home page Coder Social logo

c_solutions's Introduction

.NET 6 Web API

This is a boilerplate template for building / deploying a .NET Core Web API on Kubernetes.

Versioning

GitHub Release .NET Core Version Diagnostics HealthChecks Version
main 6.0.100-preview.6.21355.2 2.2.0

Project Structure

.
├── build.proj
├── docker-compose.debug.yml
├── docker-compose.yml
├── obj
├── README.md
├── Titanic.Api
│   ├── appsettings.Development.json
│   ├── appsettings.json
│   ├── bin
│   ├── Controllers
│   │   └── PassengerController.cs
│   ├── Dockerfile
│   ├── Dtos.cs
│   ├── Extensions.cs
│   ├── kubernetes
│   │   ├── mongodb.yaml
│   │   └── titanic.yaml
│   ├── Models
│   │   └── Passenger.cs
│   ├── obj
│   ├── Program.cs
│   ├── Properties
│   │   └── launchSettings.json
│   ├── Repositories
│   │   ├── InMemPassengersRepository.cs
│   │   ├── IPassengersRepository.cs
│   │   └── MongoDbPassengersRepository.cs
│   ├── Settings
│   │   └── MongoDbSettings.cs
│   └── Titanic.Api.csproj
├── titanic.csv
└── Titanic.UnitTests
    ├── bin
    ├── obj
    ├── PassengerControllerTests.cs
    ├── Titanic.UnitTests.csproj
    └── Usings.cs

Deploying a .NET Core Web API microservice on Kubernetes

Prerequisite:

  • Docker
  • .NET Core 6

to run in production

$ cd Titanic.Api
$ docker-compose up -d

Checking the Readiness and Liveness of the App.

###To check if the API is live sh {url/endpoint}/healt/live ###To check is the database is ready to serve requests sh {url/endpoint}/healt/ready

  • The docker-compose.yml is for building both db and api.
  • Dockerfile is .NET Core Web API Multistage Dockerfile (following Docker Best Practices)
  • appsettings.Development.json is .NET Core Web API development environment config
  • kubenertes folder contains Kubernetes yaml files (deployment, statefulstes, services) the webapi image cheloghm/titanic:v26 is the latest and best version while the database image cheloghm/mongo:v4 is a seeded/pre-populated database and the best version. Both images are already implemented in their respective yml files is the Kubernets directory. Just run the comand: sh $ kubectl apply -f kubernetes/mongodb.yaml $ kubectl apply -f kubernetes/mongodb.yaml In your cluster to spin up the service/app.
  • Program.cs is .NET Core Web API environment variable mapping config and .NET Core Web API startup & path routing config

Setting Up

To setup this project, you need to clone the git repo

$ git clone https://github.com/cheloghm/C_Solutions.git
### To run in Dev environment 
    ```sh
    $ dotnet run
    ```
    OR
    ```sh
        docker run -it --rm -p 8282:80 -e MongoDbSettings:Host=mongo -e MongoDbSettings:Password=pass1234 --network=titanic cheloghm/titanic:v26
        And run the database
        ```sh
            $ docker run -d --rm --name mongo -p 27017:27017 -v mongodbdata:/data/db -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e                MONGO_INITDB_ROOT_PASSWORD=pass1234 --network=titanic cheloghm/mondo:v4
### To run UnitTests
    ```sh
    $ dotnet test 
    ```

To run in a K8s cluster Ensure you create the secret: kubectl create secret generic titanic-secrets --from-literal=mongodb-password='pass1234'

More information on that coming soon.

c_solutions's People

Contributors

cheloghm avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.