Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create ingress-nginx for my kubernetes deployment and service?

I am able to access my django app deployment using LoadBalancer service type but I’m trying to switch to ClusterIP service type and ingress-nginx but I am getting 503 Service Temporarily Unavailable when I try to access the site via the host url. Describing the ingress also shows error: endpoints "django-service" not found and error: endpoints "default-http-backend" not found. What am I doing wrong?

This is my service and ingress yaml:

---
apiVersion: v1
kind: Service
metadata:
  name: django-service
spec:
  type: ClusterIP
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 8000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: django-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/force-ssl-redirect: 'true'
    nginx.ingress.kubernetes.io/ssl-redirect: 'true'
spec:
  tls:
  - hosts:
    - django.example.com
  rules:
  - host: django.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: django-service
            port:
              number: 80
  ingressClassName: nginx

kubectl get all

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$ kubectl get all
NAME                                        READY   STATUS    RESTARTS   AGE
pod/django-app-5bdd8ffff9-79xzj             1/1     Running   0          7m44s
pod/postgres-58fffbb5cc-247x9               1/1     Running   0          7m44s

NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/django-service   ClusterIP   10.233.29.58    <none>        80/TCP     7m44s
service/pg-service       ClusterIP   10.233.14.137   <none>        5432/TCP   7m44s

NAME                                   READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/django-app             1/1     1            1           7m44s
deployment.apps/postgres               1/1     1            1           7m44s

NAME                                              DESIRED   CURRENT   READY   AGE
replicaset.apps/django-app-5bdd8ffff9             1         1         1       7m44s
replicaset.apps/postgres-58fffbb5cc               1         1         1       7m44s

describe ingress

$ kubectl describe ing django-ingress
Name:             django-ingress
Labels:           <none>
Namespace:        django
Address:          10.10.30.50
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
TLS:
  SNI routes django.example.com
Rules:
  Host                      Path  Backends
  ----                      ----  --------
  django.example.com
                            /   django-service:80 (<error: endpoints "django-service" not found>)
Annotations:                nginx.ingress.kubernetes.io/force-ssl-redirect: true
                            nginx.ingress.kubernetes.io/rewrite-target: /
                            nginx.ingress.kubernetes.io/ssl-redirect: true
Events:
  Type    Reason  Age                   From                      Message
  ----    ------  ----                  ----                      -------
  Normal  Sync    5m28s (x2 over 6m5s)  nginx-ingress-controller  Scheduled for sync
  Normal  Sync    5m28s (x2 over 6m5s)  nginx-ingress-controller  Scheduled for sync

>Solution :

I think you forgot to make the link with your deployment in your service.

apiVersion: v1
kind: Service
metadata:
  name: django-service
spec:
  type: ClusterIP
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 8000
  selector:
    app: your-deployment-name

Your label must be set in your deployment as well:

spec:
  selector:
    matchLabels:
      app: your-deployment-name
  template:
    metadata:
      labels:
        app: your-deployment-name
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading