I have managed to deploy a simple ASP.NET MVC application to Kubernetes (Kubernetes enabled in Docker Desktop) using this tutorial: https://medium.com/@bterkaly/running-asp-net-applications-in-kubernetes-a-detailed-step-by-step-approach-96c98f273d1a. My manifest looks like this:
environment: development
apphost: k8s
label:
name: aspnet3core
container:
name: aspnet3
pullPolicy: IfNotPresent
image: aspnet3k8s
tag: v1
port: 80
replicas: 3
service:
port: 8888
type: ClusterIP
I have also managed to deploy a simple Web API project to Kubernetes using this tutorial: https://dev.to/wolnikmarcin/run-asp-net-core-3-on-kubernetes-with-helm-1o01. My manifest looks like this:
//myDeploy.yaml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: dotnetlinux
spec:
replicas: 2
template:
metadata:
labels:
app: dotnetlinux
spec:
containers:
- image: "brunoterkaly/dotnetlinux"
imagePullPolicy: Always
name: dotnetlinux
ports:
- containerPort: 80
//myService.yaml
apiVersion: v1
kind: Service
metadata:
name: dotnetlinux
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: dotnetlinux
I am now trying to workout how to call the web api from the MVC project. I cannot find an explanation online of how to do this. I was hoping there would be a sample project on GitHub, but I can't find it.
I am using Docker Desktop with Kubernetes enabled and Visual Studio 2019 (Kubernetes/Helm).
Just posting my comment as an answer:
To access your POD you need to call your service "dotnetlinux" on port :80, something like dotnetlinux:80/yourAPI
.
You can also run kubectl get services
to get the IP of the service, then use that. Not a good approach though, as the IP of the service will change every time your service is restarted.
In this documentation page there is a lot of details about Services and the sessions Motivation and Service resources explain why Services are needed, and how they help you in your case.