Kubernetes K3D Ingress always error 404 not found

1.4k views Asked by At

When doing for e.g. a call to my endpoint curl localhost:8081/ticketapi/ticket/get I'm receiving an error 404. I know that error 404 is that the routing cannot be found. But I've no clue on how can I debug my problem or if there is something off in my .yml files.

I'm really new to Kubernetes and Docker and I hope someone can help me solve this issue.

Thanks in advance.

My endpoint in swagger

Cluster create: k3d cluster create --api-port 6550 -p "8081:80@loadbalancer" --agents 2 from here

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ticket-deployment
  labels:
    app: ticketapi
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ticketapi
  template:
    metadata:
      labels:
        app: ticketapi
    spec:
      containers:
        - name: ticketapi
          image: stanpanman/ticketapi:latest
          ports:
            - containerPort: 80

Service:

apiVersion: v1
kind: Service
metadata:
  name: ticket-service
spec:
  selector:
    app: ticketapi
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

Ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
spec:
  ingressClassName: nginx-example
  rules:
    - http:
        paths:
          # Ticket API
          - path: /ticketapi
            pathType: Prefix
            backend:
              service:
                name: ticketapi
                port:
                  number: 80

Describe pod:

Name:         ticket-deployment-6549764674-swwjq
Namespace:    default
Priority:     0
Node:         k3d-k3s-default-agent-1/172.24.0.3
Start Time:   Tue, 03 May 2022 11:31:50 +0200
Labels:       app=ticketapi
              pod-template-hash=6549764674
Annotations:  <none>
Status:       Running
IP:           10.42.2.4
IPs:
  IP:           10.42.2.4
Controlled By:  ReplicaSet/ticket-deployment-6549764674
Containers:
  ticketapi:
    Container ID:   containerd://f830c5396c5886c9109f733a07d9c2e02cde32b7689ed85dbfb8e62dc503705a
    Image:          stanpanman/ticketapi:latest
    Image ID:       docker.io/stanpanman/ticketapi@sha256:428990ac8d10dbf74039eb25a6899448f4cb96997cb5edde2e9d62e66d547070
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 03 May 2022 11:32:03 +0200
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-kgp8c (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-kgp8c:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  17m   default-scheduler  Successfully assigned default/ticket-deployment-6549764674-swwjq to k3d-k3s-default-agent-1
  Normal  Pulling    17m   kubelet            Pulling image "stanpanman/ticketapi:latest"
  Normal  Pulled     17m   kubelet            Successfully pulled image "stanpanman/ticketapi:latest" in 12.656309048s
  Normal  Created    17m   kubelet            Created container ticketapi
  Normal  Started    17m   kubelet            Started container ticketapi
1

There are 1 answers

0
Bguess On

This could help you debug:

Check if your application is actually working at the pod level (make sure the pod-name is correct):

kubectl port-forward pod/ticket-deployment-6549764674-swwjq 8080:80

#then try on your browser localhost:8080/whateverYouConfigured

If this doesn't work, the pb may came from your app ( you can connect into the pod and exec a curl localhost:80/whateverYouConfigured command

If this worked, try to check if the service is working correctly:

kubectl port-forward svc/ticket-service 8080:80
#then try on your browser localhost:8080/whateverYouConfigured

If this doesn't work, check the svc endpoints or labels

If it worked, then you can do the same with the ingress:

kubectl port-forward <ingress-pod-name> 8080:<ingress-port>

If this works check your k3d config / firewalling etc.

Hope this can help: https://learnk8s.io/a/b0862c5c0f1e7a6db8145f7970dd9601.png