0

I have developed a very small service on dotnet 6, running in Windows 10 and Docker 20.10.17. I want to expose as service in Kubernetes in local machine as "http://localhost:15001/Calculator/sum/1/1".
I am running an script like:

docker build  -f API/CalculadoraREST/Dockerfile . --tag calculadorarestapi:v1.0

kubectl config set-context --current --namespace=calculadora
kubectl apply -f kubernetes/namespace.yml --overwrite=true
kubectl apply -f kubernetes --overwrite=true

When finished and run kubectl get ingress -n calculadora I get the ingress object and found without IP to access:

NAME                  CLASS    HOSTS   ADDRESS   PORTS   AGE
calculadora-ingress   <none>   *                 80      5s

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS base
WORKDIR /app
EXPOSE 15001

ENV ASPNETCORE_URLS=http://+:15001

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
WORKDIR /src
COPY ["API/CalculadoraREST/CalculadoraRestAPI.csproj", "API/CalculadoraREST/"]
RUN dotnet restore "API/CalculadoraREST/CalculadoraRestAPI.csproj"
COPY . .
WORKDIR "/src/API/CalculadoraREST"
RUN dotnet build "CalculadoraRestAPI.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "CalculadoraRestAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CalculadoraRestAPI.dll"]

Ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: calculadora-ingress
  namespace: calculadora
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /

spec:
  rules:
  - http:
      paths:
      - path: /Calculator/
        pathType: Prefix
        backend:
          service :
            name: calculadorarestapi-service
            port:
              number: 15001

Service:

apiVersion: v1
kind: Service
metadata:
  name: calculadorarestapi-service
  namespace: calculadora  
spec:
  selector:
    app: calculadorarestapi
  ports:
  - protocol: TCP
    port: 15001
    targetPort: 15001
    name: http

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: calculadorarestapi-deployment
  namespace: calculadora  
spec:
  selector:
    matchLabels:
      app: calculadorarestapi
  replicas: 2
  template:
    metadata:
      labels:
        app: calculadorarestapi
    spec:
      containers:
      - name: calculadorarestapi
        image: calculadorarestapi:v1.0
        ports:
        - containerPort: 15001
        resources:
          requests:
            memory: "150Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
      imagePullSecrets:
      - name: regsecret

Any ideas? I will really appreciate your comments. :-)

1 Answers1

0

Could you add the kubernetes.io/ingress.class: "nginx" annotation to the Ingress resource or set the class field as per this Git link.

Hemanth Kumar
  • 2,728
  • 1
  • 4
  • 19
  • Hi Kumar! Thanks for your answer. I added ingresClassName and when tested with apiVersion: networking.k8s.io/v1 I got "error: resource mapping not found for name: "calculadora-ingress" namespace: "calculadora" from "kubernetes\\ingress.yml": no matches for kind "Ingress" in version "networking.k8s.io/v1beta1". Then I tested using "apiVersion: networking.k8s.io/v1" there were no error message but again "No IP on ingress object". – Marcos Guerrero Wilson Sep 20 '22 at 14:35
  • Using the readings you pointed out I maybe there is a problem with path mappings. When I use this service directly in Windows or Docker it works like this: Invoke-WebRequest -URI "http://localhost:15001/Calculator/sum/1/1". What I am expecting in K8s is to find the service in "http://:15001/Calculator/sum/1/1". – Marcos Guerrero Wilson Sep 20 '22 at 14:38
  • I have tried all kind of changes but it looks to me that Ingress-ngnx object is not well implemented on Docker Desktop kubectl as per https://github.com/kubernetes/ingress-nginx/issues/7686 – Marcos Guerrero Wilson Sep 21 '22 at 17:50