0

The domain configured is ticket.devaibhav.live

ping ticket.devaibhav.live is pointing to the correct IP address of the load balancer provisioned by Digital Ocean. I haven't configured SSL on the cluster yet, but if I try to access my website http://ticket.devaibhav.live gives an 400 bad request. I am new to kubernetes and networking inside a cluster.

According to my understanding, when browser sends request to http://ticket.devaibhav.live the request is sent to the Digital Ocean Load balancer and then the ingress service (Ingress-nginx by kubernetes in my case) routes the traffic based on the rules I have defined.

ingress-nginx service

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol: 'true'
    service.beta.kubernetes.io/do-loadbalancer-hostname: 'ticket.devaibhav.live'
  labels:
    helm.sh/chart: ingress-nginx-2.0.3
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/version: 0.32.0
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  type: LoadBalancer
  externalTrafficPolicy: Local
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: http
    - name: https
      port: 443
      protocol: TCP
      targetPort: https
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/component: controller

ingress resource rules

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
  rules:
    - host: ticket.devaibhav.live
      http:
        paths:
          - path: /api/users/?(.*)
            pathType: Prefix
            backend:
              service:
                name: auth-srv
                port:
                  number: 3000
          - path: /api/tickets/?(.*)
            pathType: Prefix
            backend:
              service:
                name: tickets-srv
                port:
                  number: 3000
          - path: /api/orders/?(.*)
            pathType: Prefix
            backend:
              service:
                name: orders-srv
                port:
                  number: 3000
          - path: /api/payments/?(.*)
            pathType: Prefix
            backend:
              service:
                name: payments-srv
                port:
                  number: 3000
          - path: /?(.*)
            pathType: Prefix
            backend:
              service:
                name: client-srv
                port:
                  number: 3000

essentially when I hit http://ticket.devaibhav.live the request should be mapped to the last rule where it must be routed to client-srv.

client deployment and service

apiVersion: apps/v1
kind: Deployment
metadata:
  name: client-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: client
  template:
    metadata:
      labels:
        app: client
    spec:
      containers:
        - name: client
          image: vaibhav908/client

---
apiVersion: v1
kind: Service
metadata:
  name: client-srv
spec:
  selector:
    app: client
  ports:
    - name: client
      protocol: TCP
      port: 3000
      targetPort: 3000

The above configuration works well on the development server where I am using minikube. I am unable to understand where I am going wrong with the configuration. I will provide more details as I feel it would be necessary.

[edit] on the cluster that is deployed kubectl get services

NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)             AGE
client-srv             ClusterIP   10.245.100.25    <none>        3000/TCP            2d17h
and some other services

kubectl describe ingress

Name:             ingress-service
Labels:           <none>
Namespace:        default
Address:          ticket.devaibhav.live
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                   Path  Backends
  ----                   ----  --------
  ticket.devaibhav.live  
                         /api/users/?(.*)      auth-srv:3000 (10.244.1.76:3000)
                         /api/tickets/?(.*)    tickets-srv:3000 (10.244.0.145:3000)
                         /api/orders/?(.*)     orders-srv:3000 (10.244.1.121:3000)
                         /api/payments/?(.*)   payments-srv:3000 (10.244.1.48:3000)
                         /?(.*)                client-srv:3000 (10.244.1.32:3000)
Annotations:             kubernetes.io/ingress.class: nginx
                         nginx.ingress.kubernetes.io/use-regex: true
Events:                  <none>
Vaibhav07
  • 223
  • 2
  • 10
  • 1
    Did you check the logs of the pod? If traffic approaches there you might have a different problem. – Michael Johann Feb 19 '23 at 07:51
  • I have just the log, since it is a next js application running in **dev mode** not build mode... the last log goes something like this ```event - compiled client and server successfully in 8.8s (266 modules)``` so this clearly means that the request has not reached the client pod – Vaibhav07 Feb 19 '23 at 09:12
  • And if you scale the deployment down to 0, do you get the same 400 result? – Michael Johann Feb 19 '23 at 10:37
  • After scaling down the client deployment to 0, the response is simply 'site not found', since there was no client-srv that the ingress could match. Does this mean there are issues within the pod, the traffic was reaching the cluster IP earlier (but since there was some issue within cluster ip+client pod), and now since the client and pod is down, the path could not be mapped. Is this assessment correct? – Vaibhav07 Feb 20 '23 at 09:11

1 Answers1

1

Make sure you have your ingress controller configured to respect the proxy protocol settings in the LB. Try adding a proxy protocol directive to your config map.

As given in the document:

Enables or disables the PROXY protocol to receive client connection (real IP address) information passed through proxy servers and load balancers such as HAProxy and Amazon Elastic Load Balancer (ELB).

Fariya Rahmat
  • 2,123
  • 3
  • 11