Setting up your simple .net core application using kubernetes
This is a simple guide how to deploy .net core docker image to kubernetes (minikube).
You need to setup your minikube, docker. Once you have done that, we're ready to go.
Summary of tasks :-
a) setup Docker image
b) push to Docker registry
c) run your application on Kubernetes and scale it
1. Setup Docker image
Our .netcore service exposes /hello/index url which returns "Hello World!".
The complete source code is available here. Once you have clone the git repo, we just need to build our docker image. This is a multistage docker image which means it uses .netcore sdk for building and then deploy built binaries to a .netcore production image.
Go to ConnectCD-NetCoreWebApi, then run the following command :-
docker build -t dotnetapp-prod .
If you want to test your application locally (using DOCKER),
docker run -d -p 5050:5050 dotnetapp-prod
2. Push to Docker registry
Use the following command to push your built image to Docker registry (kepung) is my user id. You should change that to yours.
docker tag dotnetapp-prod kepung/dotnetapp-prod
Your docker file looks something like this :-
3. Running on Kubernetes
You need to start running your kubernetes cluster or minikube.
Next, run the following command. --image specify the image to use and --port, exposes port 5050 because our .net core app uses port 5050 by default.
kubectl run connectcd --image=kepung/dotnetapp-prod --port=5050
You can check your deployment by using
kubectl get deployment
Next, we need to create a service. A service in kubernetes allows pods to talk to host.You can think like setting up a load balancer which has a dedicated ip and you don't have to keep track of pods ip. You always talk to the load balancer.
Use the following command to create a service
kubectl expose deployment/connectcd --type="NodePort" --port=5050
--name=connectcd-http
You will probably get a random port to work with. So let's see how we can get ALL the relevant info to connect to our .net core web api.
To get our host or node use the following command :-
kubectl describe node
To get which port we will be using the command below :-
kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
connectcd-http NodePort 10.103.83.222
As you can see, we use 32206 to map to port 5050.
Once we have the relevant info, we can just hit the service from our browser using the following url :-
http://192.168.99.100:32206/hello/index
Comments
.Net Online Course Hyderabad