To run dotnet Rest Apis in a kubernetes cluster and establish asynchronous commnuication between them by using RabbitMq. This project has two services
- PlatformService - uses Sql Server database
- CommandService - uses InMemory data
Both the services will be running in a kubernetes cluster in their individual pods. Sql server will also be running in a separate pod. Outside Interaction with platformservice will be enabled with help of ingress nginx API gateway which will route requests to services based on path values.
Following are the steps to get these running in a kubernetes cluster
- Build docker images from dockerfile for both the services. Make sure that docker desktop is running with kubernetes enabled on the development machine.
- Go the
/PlatformService
folder and run the following command (Dont forget the period in the below command. It provides the build context) This will a create a image<docker-hub-id>/platformservice
docker build -t <docker-hub-id>/platformservice .
- Go the
/CommandService
folder and run the following command (Dont forget the period in the below command. It provides the build context) This will a create a image<docker-hub-id>/commandservice
docker build -t <docker-hub-id>/commandservice .
- Go the
- Now that we have images, we will create running containers by running the below command
Test each service by hitting below endpoints by using Postman
docker run -d -p 8080:80 <docker-hub-id>/platformservice docker run -d -p 8080:80 <docker-hub-id>/commandservice
If successful response is received, we have running conatiners in docker.(platformservice) GET http://localhost:8080/api/platforms (commandservice) POST http://localhost:8080/api/c/platforms
- Push these docker images to
hub.docker.com
by running below commands. These images will be used by kubernetes cluster later.docker push <docker-hub-id>/platformservice docker push <docker-hub-id>/commandservice
- Now we will run these images inside a kubernetes cluster.
Go the
/K8S
folder and run the following commands. This will create pods forplatformservice
andcommandservice
and will create CLusterIp services to enable interaction for outside world.To see the deploymentskubectl apply -f platforms-depl.yaml kubectl apply -f commands-depl.yaml
To get the podskubectl get deployments
To get the services (clusterIp services)kubectl get pods
kubectl get services
- Pods are ephemeral in nature, so direct access to pods is not allowed that is why we created clusterIp services to enable their interaction to outside world. One way for us to interact with pod is to make use of nodeport service. To start this service, go to
K8S
folder and run the below commandTo get the port from which we can access platformservice run the below command and look for servicetype ClusterIp and take note of the externalPort.kubectl apply -f platforms-np-srv.yaml
Test platformservice by hitting below endpoints by using Postmankubectl get services
Successful reponse indicates that we are now able to interact with the platformservice pod through a nodeport service.GET http://localhost:<30xxx>/api/platforms