404 Not found after configuration of SSL certificate with Cert Bot and Nginx in Kubernetes

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version: 1.29.0-do.0
Cloud being used: Digital Ocean
Installation method:
Host OS: Digital Ocean
CNI and version:
CRI and version:

The API was working perfectly until I added a SSL certificate with cert bot, and now I am always getting 404 error when accessing it. The SSL certificate is valid. I have the same API running before adding an SSL certificate, which is working fine. The cluster is hosted on digital ocean. Pods are running fine and no logs are shown.

Let me know which else of information you need!

Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: btcapi-ingress
  namespace: btcapi
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: "nginx"
    cert-manager.io/issuer: "letsencrypt-prod"
spec:
  ingressClassName: nginx
  tls:
    - hosts:
      - example.me
      secretName: letsencrypt-secret-prodv2
  rules:
    - host: example.me
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: btcapi-service
                port:
                  number: 80

Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /   btcapi-service:443 (10.244.0.108:80,10.244.0.117:80,10.244.0.38:80)
              /   btcapi-service:80 (10.244.0.108:80,10.244.0.117:80,10.244.0.38:80)
Annotations:  cert-manager.io/issuer: letsencrypt-prod
              kubernetes.io/ingress.class: nginx
              nginx.ingress.kubernetes.io/rewrite-target: /

Issuer

apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: letsencrypt-prod
  namespace: btcapi
spec:
  acme:
    email: email@outlook.com  # Set your email
    server: https://acme-v02.api.letsencrypt.org/directory
    privateKeySecretRef:
      name: letsencrypt-secret-prod  # Choose another name
    solvers:
    - http01:
        ingress:
          class: nginx  # Specify your Ingress controller

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: btc-api-server
  labels:
    app: btc-api-server
  namespace: btcapi
spec:
  replicas: 3
  selector:
    matchLabels:
      app: btc-api-server
  template:
    metadata:
      name: btc-api-server
      labels:
        app: btc-api-server
    spec:
      containers:
          - name: btc-api-server
            image: myname/btcapi:0.0.6
            imagePullPolicy: Always
            ports:
              - name: api-access-port
                containerPort: 80
            #resources:
            #  requests:
            #    memory: "2048Mi"
            #  limits:
            #    memory: "2Gi"

      restartPolicy: Always

Service

apiVersion: v1
kind: Service
metadata:
  name: btcapi-service
  labels:
    app: btcapi-service
  namespace: btcapi
spec:
  selector:
    app: btc-api-server
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 80
    - name: redis
      protocol: TCP
      port: 6379
      targetPort: 6379
IP:                10.245.204.32
IPs:               10.245.204.32
Port:              http  80/TCP
TargetPort:        80/TCP
Endpoints:         10.244.0.108:80,10.244.0.117:80,10.244.0.38:80
Port:              https  443/TCP
TargetPort:        80/TCP
Endpoints:         10.244.0.108:80,10.244.0.117:80,10.244.0.38:80
Port:              redis  6379/TCP
TargetPort:        6379/TCP
Endpoints:         10.244.0.108:6379,10.244.0.117:6379,10.244.0.38:6379

I tried to reinstall the whole cluster which still not solved the issue.

Hi,
Try to recreate your ingress rule using below manifest

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: btcapi-ingress
  namespace: btcapi
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: "nginx"
    cert-manager.io/issuer: "letsencrypt-prod"
spec:
  ingressClassName: nginx
  tls:
    - hosts:
      - example.me
      secretName: letsencrypt-secret-prodv2
  rules:
    - host: example.me
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: btcapi-service
                port:
                  number: 80

HTH