
Deploy an application dotnetcore on Kubernetes locally
Installing application dotnetcore demo:
# cloning the codegit clone https://github.com/dotnet/dotnet-docker
Running the app locally:
Navigate to the project folder at dotnet-docker/samples/aspnetapp/aspnetapp.
dotnet run
Go to http://localhost:5000
in a browser to test the app.
Press Ctrl+C at the command prompt to stop the app.
Building the application on Docker container:
Navigate to the Dockerfile folder at dotnet-docker/samples/aspnetapp.
Run the following commands to build sample in Docker:
docker build -t aspnetapp .
Pushing the image to Docker Hub:
# this example I'm using Ubuntusudo docker tag aspnetpp rondweb/dotnetcore:aspnetappsudo docker push rondweb/dotnetcore:aspnetapp
So, we already have our docker image stored in Docker Hub and now we have to create our manifest file to publish our app on Kubernetes locally.
apiVersion: apps/v1kind: Deploymentmetadata: name: aspnetcoreapp labels: app: aspnetcoreappspec: replicas: 1 selector: matchLabels: app: aspnetcoreapp template: metadata: labels: app: aspnetcoreapp spec: containers: - name: aspnetcoreapp image: rondweb/dotnetcore:aspnetapp ports: - containerPort: 80 resources: requests: cpu: 100m memory: 100Mi limits: cpu: 200m memory: 200Mi---apiVersion: v1kind: Servicemetadata: name: aspnetcoreapp-servicespec: type: LoadBalancer ports: - port: 80 selector: app: aspnetcoreapp---apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata: name: aspnetcoreapp-ingress labels: app: aspnetcoreapp-ingressspec: rules: - http: paths: - path: / backend: serviceName: aspnetcoreapp-service servicePort: 80
[git-github-checkout url=”https://github.com/rondweb/kubernetes/blob/dotnetcore/k8s.yml”]
Now let’s install our app on Kubernetes:
kubectl apply -f https://bit.ly/3ndrgeR
After the installation you can check if everything is ok:
kubectl get all
If everything is ok, you can see the app running!

To navigate and test the app:
kubectl port-forward service/aspnetcoreapp-service 8000:80
Navigate to the url: http://localhost:8000/ and check your new app running on Kubernetes! 🙂

Reference: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-5.0
Post a Comment