I am trying to deploy a K8S application locally and have a:
Frontend container (nginx listening on port 80, proxying requests to my back service).
Backend container (.NET listening on 5194/HTTP)
Also have a DB and a Redis cache.
My application currently works locally and I can access everything fine, the issue is that I am currently using NodePorts, and would like to use an NGINX Ingress Controller to handle traffic and routing to my Kubernetes services.
The issue is that suddenly when I try to access my application using the Domain name I set in my hosts file, it asks for basic authentication and I have no idea why.
I did initially test the ingress using a simple docker image and that worked fine, when I then tried to do the same for my current application it prompted me for Basic authentication when accessing it using the host defined in the Ingress resource.
This is my current deployment/service for my React frontend image that is served using Nginx in a multi stage dockerfile.
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-deployment
namespace: demo-ns
labels:
app: demo
spec:
replicas: 1
selector:
matchLabels:
app: demo
template:
metadata:
name: demo-pod
labels:
app: demo
spec:
containers:
- name: demo-container
image: <my_nginx_based_react_img>
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: demo-service
namespace: demo-ns
spec:
selector:
app: demo
ports:
- port: 80
targetPort: 80
This is my Nginx Ingress Resource
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
namespace: demo-ns
labels:
app: demo
spec:
ingressClassName: nginx
rules:
- host: hello-world.info
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: demo-service
port:
number: 80
I am creating the NGINX Ingress controller like this
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml
I edited my hosts file to include the domain to test locally.
127.0.0.1 kubernetes.docker.internal hello-world.info
This is what I see when i try to access my application
kubectl get ingress
kubectl get all -n ingress-nginx
What I don’t understand is how it was working properly when I was initially using a simple container to test the Ingress. (It wasn’t asking me for Basic auth)
I did try removing everything, the Ingress controller, Ingress itself, and recreated it using the simple docker container I used initially, but even now I get prompted for auth.
Does anyone have an idea why?
EDIT 1
I noticed in my Ingress controller logs, I see this.
The no object matching is for my application I want to containerize currently, I did remove everything in that namespace when I tried to go back to the simple docker container I had before that was working.
Could this somehow be contributing to the issue I’m facing?
EDIT 2
Seem to have fixed it, I forgot that my Nginx Ingress Resource was in my default namespace, not the namespace where I have all my kubernetes objects for my application.
Fixed this by deleting the ingress and recreating it in my desired namespace.
3