nginx-ingress use default upstream 127.0.0.1:8181

11/30/2020

I am new with Kubernetes and maybe my question was stupid, but I don't know how to fix it

I create an nginx-ingress deployment with nodePort service using this manual https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-ingress
  namespace: nginx-ingress
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx-ingress
  template:
    metadata:
      labels:
        app: nginx-ingress
    spec:
      serviceAccountName: nginx-ingress
      containers:
      - image: nginx/nginx-ingress:1.9.1
        imagePullPolicy: Always
        name: nginx-ingress
        ports:
        - name: http
          containerPort: 80
        - name: readiness-port
          containerPort: 8081
        readinessProbe:
          httpGet:
            path: /nginx-ready
            port: readiness-port
          periodSeconds: 1
        securityContext:
          allowPrivilegeEscalation: true
          runAsUser: 101 #nginx
          capabilities:
            drop:
            - ALL
            add:
            - NET_BIND_SERVICE
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        args:
          - -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
          - -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret

And service:

apiVersion: v1
kind: Service
metadata:
  name: nginx-ingress
  namespace: nginx-ingress
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
      name: http
      nodePort: 30369
  selector:
    app: nginx-ingress

And create deployments with service:

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: landing
  name: landing
  labels:
    app:landing
spec:
  replicas: 1
  selector:
    matchLabels:
      app: landing
  template:
    metadata:
      labels:
        app: landing
        namespace: landing
    spec:
      containers:
      - name: landing
        image: private-registry/landing
        imagePullPolicy: Always
        ports:
          - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: landing
  namespace: landing
spec:
  selector:
    app: landing
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

Then I add ingress:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: landing
  namespace: landing
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  ingressClassName: nginx
  rules:
  - host: landing.site
    http:
      paths:
      - path: /
        backend:
          serviceName: landing
          servicePort: 80

But in nginx-ingress POD, I see default upstream backend,

upstream default-landing-landing.site-landing-80 {
	zone default-landing-landing.site-landing-80 256k;
	random two least_conn;

	server 127.0.0.1:8181 max_fails=1 fail_timeout=10s max_conns=0;

}

What am I doing wrong?

-- Dmitriy Krinitsyn
kubernetes
nginx

2 Answers

11/30/2020

That is how an nginx ingress works. There is nothing wrong here. A default backend is to handle all URL paths which a nginx controller doesn't understand. So in your case, any request expect landing.site/ would be served by the default backend and be shown a generic 404 nginx error page.

-- ukpillai
Source: StackOverflow

12/1/2020

Well, I was so stupid :) I have another one ingress in default backend with same host. Delete it and all works fine

-- Dmitriy Krinitsyn
Source: StackOverflow