1

I've set up a k8s cluster (1 bare metal node for now, which is both master and worker). I've also set up Nginx ingress controller as described here: https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/ Below are the exact steps:

  1. kubectl apply -f common/ns-and-sa.yaml https://github.com/nginxinc/kubernetes-ingress/blob/release-1.11/deployments/common/ns-and-sa.yaml (no modifications)
  2. kubectl apply -f rbac/rbac.yaml https://github.com/nginxinc/kubernetes-ingress/blob/release-1.11/deployments/rbac/rbac.yaml (no modifications)
  3. kubectl apply -f common/default-server-secret.yaml https://github.com/nginxinc/kubernetes-ingress/blob/release-1.11/deployments/common/default-server-secret.yaml (no modifications)
  4. kubectl apply -f common/nginx-config.yaml https://github.com/nginxinc/kubernetes-ingress/blob/release-1.11/deployments/common/nginx-config.yaml Modified file:
kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
  namespace: nginx-ingress
data:
  ignore-invalid-headers: "false"
  use-forwarded-headers: "true"
  forwarded-for-header: "CF-Connecting-IP"
  proxy-real-ip-cidr: "...IPs go here..."
  1. kubectl apply -f common/ingress-class.yaml https://github.com/nginxinc/kubernetes-ingress/blob/release-1.11/deployments/common/ingress-class.yaml Modified file:
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
  name: nginx
  annotations:
    ingressclass.kubernetes.io/is-default-class: "true"
spec:
  controller: nginx.org/ingress-controller
  1. These commands:
kubectl apply -f common/crds/k8s.nginx.org_virtualservers.yaml
kubectl apply -f common/crds/k8s.nginx.org_virtualserverroutes.yaml
kubectl apply -f common/crds/k8s.nginx.org_transportservers.yaml
kubectl apply -f common/crds/k8s.nginx.org_policies.yaml

No modifications, links:

  1. kubectl apply -f daemon-set/nginx-ingress.yaml https://github.com/nginxinc/kubernetes-ingress/blob/release-1.11/deployments/daemon-set/nginx-ingress.yaml (no modifications)

I've also set up cert-manager, which works fine (pretty sure this does not matter much).

Now, when I create some Ingress resource, it almost works. I can access it from the outer Internet, certificate issuing works, etc. But ConfigMap (common/nginx-config.yaml) is not applied, and annotations like nginx.org/rewrite-target: /$1 are not applied, too.

Example:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-com
  namespace: example-com
  annotations:
    nginx.org/rewrite-target: /$1
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - example.com
    secretName: example-com-tls
  rules:
  - host: example.com
    http:
      paths:
      - path: /api/(.*)
        pathType: ImplementationSpecific
        backend:
          service:
            name: api
            port:
              number: 80
      - path: /(.*)
        pathType: ImplementationSpecific
        backend:
          service:
            name: frontend
            port:
              number: 80

Real domain names are used, of course. I get 404 nginx error in this example. In other Ingress I pass /proxy-body-size annotation, which does not work also (can not upload large files).

I've execed into ingress controller pod with kubectl -n nginx-ingress exec -it nginx-ingress-snjjp bash and looked at files in /etc/nginx/conf.d. None of the files contained configuration specified in ConfigMap or annotations.

This is what it look like (I removed extra blank lines and replaced domain names):

# configuration for example-com/example-com

upstream example-com-example-com-example.com-api-80 {
        zone example-com-example-com-example.com-api-80 256k;
        random two least_conn;

        server 10.32.0.4:80 max_fails=1 fail_timeout=10s max_conns=0;
}
upstream example-com-example-com-example.com-frontend-80 {
        zone example-com-example-com-example.com-frontend-80 256k;
        random two least_conn;

        server 10.32.0.27:80 max_fails=1 fail_timeout=10s max_conns=0;
}

server {
        listen 80;

        listen 443 ssl;

        ssl_certificate /etc/nginx/secrets/example-com-example-com-tls;
        ssl_certificate_key /etc/nginx/secrets/example-com-example-com-tls;

        server_tokens on;

        server_name example.com;

        set $resource_type "ingress";
        set $resource_name "example-com";
        set $resource_namespace "example-com";

        if ($scheme = http) {
                return 301 https://$host:443$request_uri;
        }

        location /api/(.*) {
                set $service "api";

                proxy_http_version 1.1;

                proxy_connect_timeout 60s;
                proxy_read_timeout 60s;
                proxy_send_timeout 60s;
                client_max_body_size 1m;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Forwarded-Port $server_port;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_buffering on;

                proxy_pass http://example-com-example-com-example.com-api-80;
        }
        location /(.*) {
                set $service "frontend";

                proxy_http_version 1.1;

                proxy_connect_timeout 60s;
                proxy_read_timeout 60s;
                proxy_send_timeout 60s;
                client_max_body_size 1m;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Forwarded-Port $server_port;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_buffering on;

                proxy_pass http://example-com-example-com-example.com-frontend-80;
        }
}

I also tried nginx.ingress.kubernetes.io/ annotations (I'm not a pro as you can see, and it was what I googled). No success.

I am updating my cluster, and with the older version of k8s (1.15 I think it was) everything worked a couple of days ago. I used the exact same configuration for every service, except ingress controller, of course.

Any ideas?

ololoepepe
  • 979
  • 1
  • 10
  • 18

1 Answers1

6

I've found out what is wrong. I was using Kubernetes Nginx Ingress Controller https://kubernetes.github.io/ingress-nginx/ with my old setup, and now I am using Nginx Ingress Controller https://www.nginx.com/products/nginx-ingress-controller/ These implementations have different annotations (the latter is missing many useful annotations). This is really very confusing, as configuration is similar and one may think these are the same.

Dharman
  • 30,962
  • 25
  • 85
  • 135
ololoepepe
  • 979
  • 1
  • 10
  • 18
  • do you use this link to deploy ur Nginx ingress controller by helm? https://github.com/nginxinc/kubernetes-ingress – newcomers Feb 26 '22 at 10:10
  • 1
    What a helpful answer! Ran into the same issue. How is this not marked in every single tutorial on how to use/install an nginx ingress controller? – Christopher Gertz May 05 '22 at 19:49