1

I'm following the tutorial from Less Jackson about Kubernetes but I'm stuck around 04:40:00. I always get an 404 returned from my Ingress Nginx Controller. I followed everything he does, but I can't get it to work.

I also read that this could have something to do with IIS, so I stopped the default website which also runs on port 80.

The apps running in the containers are .NET Core.

Commands-deply & cluster ip

apiVersion: apps/v1
kind: Deployment
metadata:
 name: commands-depl
spec:
 replicas: 1
 selector:
  matchLabels:
   app: commandservice
 template:
  metadata:
   labels:
    app: commandservice
  spec:
   containers:
    - name: commandservice
      image: maartenvissershub/commandservice:latest
---
apiVersion: v1
kind: Service
metadata:
 name: commands-clusterip-srv
spec:
 type: ClusterIP
 selector:
  app: commandservice
 ports:
  - name: commandservice
    protocol: TCP
    port: 80
    targetPort: 80

Platforms-depl & cluster ip

apiVersion: apps/v1
kind: Deployment
metadata:
 name: platforms-depl
spec:
 replicas: 1
 selector:
  matchLabels:
   app: platformservice
 template:
  metadata:
   labels:
    app: platformservice
  spec:
   containers:
    - name: platformservice
      image: maartenvissershub/platformservice:latest
---
apiVersion: v1
kind: Service
metadata:
 name: platforms-clusterip-srv
spec:
 type: ClusterIP
 selector:
  app: platformservice
 ports:
  - name: platformservice
    protocol: TCP
    port: 80
    targetPort: 80

Ingress-srv

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
 name: ingress-srv
 annotations:
  kubernetes.io/ingress.class: nginx
  nginx.ingress.kubernetes.io/use-regex: 'true'
  nginx.ingress.kubernetes.io/rewrite-target: /
spec:
 rules:
  - host: acme.com
    http:
     paths:
      - path: /api/platforms
        pathType: Prefix
        backend:
         service:
          name: platforms-clusterip-srv
          port:
           number: 80
      - path: /api/c/platforms
        pathType: Prefix
        backend:
         service:
          name: commands-clusterip-srv
          port:
           number: 80

I also added this to my hosts file: 127.0.0.1 acme.com

And I applied this from the nginx documentation:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.0/deploy/static/provider/cloud/deploy.yaml

kubectl get ingress kubectl get ingress

kubectl describe ing ingress-srv
kubectl describe ing ingress-srv

Dockerfile CommandService

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
WORKDIR /app

COPY *.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT [ "dotnet", "PlatformService.dll" ]

kubectl logs ingress-nginx-controller-6bf7bc7f94-v2jnp -n ingress-nginx LOGS INGRESS POD

Am I missing something?

Maarten Vissers
  • 499
  • 1
  • 4
  • 11
  • 1
    You can either use nodeport or do port forwarding for the ingress svc. Also ensure the container port is listening on the same port which is used in the application service – Nataraj Medayhal Jul 15 '22 at 07:36
  • How can I check the port of my app service? The container port is 80 I think, or how can I check this as well? Thank you!!! – Maarten Vissers Jul 15 '22 at 08:09
  • its depends on the process / server / application which is being run inside the container. You can check the docker file and check which port is exposed – Nataraj Medayhal Jul 15 '22 at 08:27
  • @NatarajMedayhal I've added the Dockerfile, but I don't see an exposed port in there? The application is .NET Core, thanks! – Maarten Vissers Jul 15 '22 at 08:40
  • default port is 80. you can create NodePort for ingress service and access the application url. if you don't want use NodePort you can attach LoadBalancer to ingress and access the url. – Nataraj Medayhal Jul 15 '22 at 09:39
  • @NatarajMedayhal Ok thank you. Adding a nodeport was an earlier step in this tutorial, but because this is not recommended for production we are adding an nginx ingress controller. (Link to nodeport code: https://github.com/binarythistle/S04E03---.NET-Microservices-Course-/blob/main/K8S/platforms-np-srv.yaml) – Maarten Vissers Jul 15 '22 at 11:59
  • @NatarajMedayhal So I'll try adding the LoadBalancer to the ingress controller. Do you have any recommended documentation/tutorial on this (just in case you have)? Can you explain why I have to do this extra configuration and Les Jackson from the tutorial doesn't? – Maarten Vissers Jul 15 '22 at 12:58
  • Request you to refer official kubernetes documentation for different mechanism how to access the k8s resources in following link https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/ – Nataraj Medayhal Jul 15 '22 at 13:14

2 Answers2

1

I found my solution. There was a process running on port 80 with pid 4: 0.0.0.0:80. I could stop it using NET stop HTTP in an admin cmd.

I noticed that running kubectl get services -n=ingress-nginx resulted a ingress-nginx-controll, which is fine, but with an external-ip . Running kubectl get ingress also didn't show an ADDRESS. Now they both show "localhost" as value for external-ip and ADDRESS.

Reference: Port 80 is being used by SYSTEM (PID 4), what is that?

Maarten Vissers
  • 499
  • 1
  • 4
  • 11
0

So this can occur from several reasons:

  1. Pods or containers are not working - try using kubectl get pods -n <your namespace> to see if any are not in 'running' status.
  2. Assuming they are running, try kubectl describe pod <pod name> -n <your namespace> to see the events on your pod just to make sure its running properly.
  3. I have noticed you are not exposing ports in your deployment. please update your deployments like so:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
     name: platforms-depl
    spec:
     replicas: 1
     selector:
      matchLabels:
       app: platformservice
     template:
      metadata:
       labels:
        app: platformservice
      spec:
       containers:
        - name: platformservice
          image: maartenvissershub/platformservice:latest
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
    ---
    apiVersion: v1
    kind: Service
    metadata:
     name: platforms-clusterip-srv
    spec:
     type: ClusterIP
     selector:
      app: platformservice
     ports:
      - name: platformservice
        protocol: TCP
        port: 80
        targetPort: 80
    
    apiVersion: apps/v1
    kind: Deployment
    metadata:
     name: commands-depl
    spec:
     replicas: 1
     selector:
      matchLabels:
       app: commandservice
     template:
      metadata:
       labels:
        app: commandservice
      spec:
       containers:
        - name: commandservice
          image: maartenvissershub/commandservice:latest
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
    ---
    apiVersion: v1
    kind: Service
    metadata:
     name: commands-clusterip-srv
    spec:
     type: ClusterIP
     selector:
      app: commandservice
     ports:
      - name: commandservice
        protocol: TCP
        port: 80
        targetPort: 80

Hope this helps!