configuration-snippet annotation doesn't add custom header to response

7/12/2019

I need add response header "X-Robots-Tag: noindex, nofollow". Ingress controller contains directive more_set_headers "X-Robots-Tag: noindex, nofollow";. But in response I don't see it.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.global-static-ip-name: development-ip
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "X-Robots-Tag: noindex, nofollow";
  name: front-ingress
  namespace: staging
spec:
  rules:
  - host: somedomain
    http:
      paths:
      - backend:
          serviceName: front-service
          servicePort: 80
        path: /*
      - backend:
          serviceName: backend-service
          servicePort: 80
        path: /api/*
  tls:
  - hosts:
    - somedomain
    secretName: front-tls-secret
-- Serhii Koberniuk
google-kubernetes-engine
kubernetes-ingress
nginx-ingress

2 Answers

7/22/2019

The problem: cluster have 2 ingress controllers nginx/gce. Annotations was applied to nginx ingress controller, but traffic was via gce ingress controller.

-- Serhii Koberniuk
Source: StackOverflow

7/17/2019

If I understand you correctly you can try to use server-snippet:

apiVersion: v1
data:
  server-snippet: add_header X-Robots-Tag “noindex, nofollow”;

for a snippet in the nginx config service block.

Or you can add it to a specific ingress using nginx.ingress.kubernetes.io/server-snippet:

nginx.ingress.kubernetes.io/server-snippet: |-
  add_header X-Robots-Tag "noindex, nofollow";

for a snippet in the nginx config service block.

Please let me know if that helped.

-- OhHiMark
Source: StackOverflow