I’m following these instructions Basic Authentication - NGINX Ingress Controller to add basic auth to an NGINX Ingress. This is in EKS. I already have an ALB Ingress which does route to our Service. I had hoped I could insert an NGINX Ingress between the two. However, trying to point the ALB Ingress at the NGINX Ingress causes Kubernetes to complain that there is no such Service. This does make some sense as an Ingress is not a Service, I think. For example:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: foobar-ingress-dev
namespace: foobar-dev
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/group.name: foobar-ingress-dev
alb.ingress.kubernetes.io/scheme: internal
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80}, {"HTTPS":443}]'
alb.ingress.kubernetes.io/healthcheck-path: /
alb.ingress.kubernetes.io/backend-protocol: HTTP
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
spec:
tls:
- hosts:
- foobar.example.com
rules:
- host: foobar.example.com
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: ssl-redirect
port:
name: use-annotation
- pathType: Prefix
path: /
backend:
service:
name: foobar-ingress-basic-auth-dev
port:
number: 3000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: foobar-ingress-basic-auth-dev
namespace: foobar-dev
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/group.name: foobar-ingress-basic-auth-dev
nginx.ingress.kubernetes.io/scheme: internal
nginx.ingress.kubernetes.io/auth-type: basic
nginx.ingress.kubernetes.io/auth-secret: foobar-basic-auth-secret-dev
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required'
spec:
defaultBackend:
service:
name: foobar-dev
port:
number: 3000
Is this possible? Or is there a better way to add basic auth like this? Thanks
Cluster information:
Kubernetes version: v1.21.14-eks-18ef993
Cloud being used: AWS
Installation method: EKS