1

I have an api that I am building and linking it to my nginx ingress controller to be used as a loadbalancer. My below yaml works when I change the namespace to default and I'm able to access the API no problem. When I change all the below to any other name space and install in that namespace, I get the error from ingress controller:

Service does not have any active Endpoint

so I thought that the nginx ingress controller (deployed in default namespace) was supposed to be able to see ingress in all namespaces. So is there something wrong with my deployment steps below?

---
apiVersion: v1
kind: Service
metadata:
  name: demoapi
  namespace: alex
spec:
  type: ClusterIP
  selector:
    app: demoapi
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
      name: http

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demoapi
  namespace: alex
  labels:
    app: demoapi
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demoapi
  template:
    metadata:
      labels:
        app: demoapi
    spec:
      containers:
      - name: demoapi
        image: myrepo/demoapi:latest
        ports:
          - containerPort: 8080
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /actuator/health
            port: 8080
          initialDelaySeconds: 15
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 3

        
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: "true"
    nginx.ingress.kubernetes.io/proxy-buffer-size: 512k
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
  name: demoapi
  namespace: alex
spec:
  rules:
    - host: mydomain.com
      http:
        paths:
          - backend:
              serviceName: demoapi
              servicePort: 80
            path: /api/v1/hello
  tls:
    - hosts:
        - mydomain.com
      secretName: mydomain-ssl-secret

I also checked nginx controller config - and it's set with default to watch all namespaces

alex
  • 1,905
  • 26
  • 51
  • 1
    Likely to happen because ingress controller can't access Ingress resources in other namespaces. Check the Role/ClusterRole created for the nginx-controller and verify that it is indeed a ClusterRole with access to Ingress resources in all namespaces. – ashu Sep 30 '20 at 15:39
  • Does this answer your question? [Ingress configuration for k8s in different namespaces](https://stackoverflow.com/questions/59844622/ingress-configuration-for-k8s-in-different-namespaces) – Mafor Sep 30 '20 at 20:40
  • 1
    Could you provide more information? Ive deployed `Nginx Ingress` on my GKE test cluster, changed image to nginx and its working for me: `Endpoints: 10.24.1.10:80`. 1. What is your environment (cloud, local), what k8s version are you using. How did you deploy `Nginx Ingress controller`. Did your pod had any restarts? Could you provide `kubectl describe` demoapi pod? – PjoterS Oct 01 '20 at 11:50
  • PjoterS - I have found the issue! It was not working because my application was being deployed in Fargate nodes in my EKS cluster, and the nginx ingress controller was running in EC2. Apparently you can't connect the two? Once I switched my deployment off of fargate into EC2 it worked. I'm not sure why on a lower level it couldn't use it. – alex Oct 01 '20 at 20:12
  • Did you try to run Ingress and app in Fargate? It also worked there? – PjoterS Oct 02 '20 at 15:01
  • Have you managed to find solution ? – Malgorzata Apr 12 '21 at 07:34

0 Answers0