Skip to content
A small demo web API built using .NET Core, managed using Docker and Kubernetes.
C# Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
DemoWebApi
.dockerignore
.gitignore
DemoWebApi.sln
Dockerfile
README.md

README.md

Demo Web API

A small demo web API built using .NET Core, managed using Docker and Kubernetes. I'm building this with the intention of teaching myself how to set up a .NET Core Web API from scratch and also how to use Kubernetes.

Planned Features

  • .NET Core web API
  • Swagger to view the endpoints
  • Entity Framework to set up and interact with a database
  • Authentication I'm not sure how yet but I want to learn
  • Docker to containerise the application
  • Kubernetes to manage it
  • GitHub Actions to manage builds (hopefully, once they give me access!)
  • Testing, not sure how yet

Running the Project

  1. Build the docker image

    docker build -t demo-web-api .

  2. Run the docker container

    docker run -d -p 8080:80 --name demo-api demo-web-api

  3. Navigate to http://localhost:8080/api/values to see the initial endpoint

Running on minikube

Ensure you have built and tagged the docker image prior to this.

I followed this guide for most of this.

  1. Start (or restart) the cluster by running

    minikube start

    This command creates and configures a Virtual Machine that runs a single-node Kubernetes cluster.

  2. Set you environment variables so that you can pull the local images.

    eval $(minikube docker-env)

  3. Create a Kubernetes deployment using

    kubectl run demo-web-api --image=demo-web-api --port=80

    You should see something like deployment.apps/demo-web-api created

  4. Edit your deployment using

    kubectl edit deployment demo-web-api

    Find and set imagePullPolicy: Never

  5. To access the Kubernetes deployment you have to expose it as a service using

    kubectl expose deployment demo-web-api --type=NodePort

    You should see something like service/demo-web-api exposed

  6. The pod is now exposed, you might have to wait for it to show up before you can access it via the service we created. You can view the status using

    kubectl get pod

    Once the service is created you can use minikube service demo-web-api --url to get the URL that it is exposed on.

    You can check if its working by accessing the /api/values endpoint.

Deleting the minikube deployment

This can be done using kubectl delete deployment demo-web-api

Troubleshooting

Can't get minikube to set up the pod

When you do kubectl get pod the status is ErrImageNeverPull

It can't find your local Docker image so run docker images, see if the demo-web-api image is in the list and if not run docker build -t demo-web-api . from within the project folder to build the image.

You can’t perform that action at this time.