Tutorial for basic asp.net core web api deployed on kubernetes via minikube and docker.
- https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-vsc
- https://kubernetes.io/docs/tutorials/stateless-application/hello-minikube/
- https://stackoverflow.com/questions/42564058/how-to-use-local-docker-images-in-kubernetes/42564211
- minikube version: v0.24.1
- docker version 17.12.0-ce, build c97c6d6
- dotnet version 2.1.4
- macOS version 10.13.2
- ASP.NET Core SDK
- Minikube
- Docker
- Visual Studio Code C# extension (optional)
- Setup Project
mkdir GradeService
cd GradeService
dotnet new webapi
- Add dockerfile which exposes port 8080 at GradeService root.
- Don't need to make any additional changes beyond this point. We will use the autogenerated ValuesController for testing.
We will be using minikube's local docker deamon. Docker images will not be hosted remotely. https://stackoverflow.com/questions/42564058/how-to-use-local-docker-images-in-kubernetes/42564211
eval $(minikube docker-env)
docker build -t grade-service:v1 .
- If you do not demarcate your image tag version it will be given the tag of latest. Kubectl will attempt to remotely pull images tagged with latest, and we do not want this.
- Save kubernetes cluster master ip.
minikube cluster info
- Run docker container to quickly test.
docker run -it --rm -p 8080:8080 --name grade-service grade-service:v1
- In web browser or postman navigate to
<step 3 ip>:8080/api/values
kubectl run grade-service --image=grade-service:v1 --port=8080 imagePullPolicy=Never
- Check deployment and pod
kubectl get deployments
andkubectl get pods
- Create and expose service
kubectl expose deployment grade-service --type=LoadBalancer
- Check services
kubectl get services
- Navigate to service
minikube service grade-service
and append/api/values
You should have your asp.net core web api running on a kubernetes cluster via minikube and docker. Now would be a good time to expand the web api, play around with multiple services and docker-compose, explore kubectl yaml config files (you can explore the default ones created for you during this tutorial via minikube dashboard
).