自定义header中间件

apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: test-header
spec:
  headers:
    frameDeny: true
    browserXssFilter: true    #customBrowserXSSValue: "1; mode=block"
    contentTypeNosniff: true
    stsSeconds: 31536000
    stsIncludeSubdomains: true
    stsPreload: true
    referrerPolicy: "no-referrer-when-downgrade"
    customFrameOptionsValue: "SAMEORIGIN"    
    contentSecurityPolicy: "connect-src *"
    customResponseHeaders:
      X-Custom-Response-Header: "value"
      Cache-Control: "no-cache"
      X-Download-Options: "noopen"
      X-Permitted-Cross-Domain-Policies: "master-only"
      Set-Cookie: "Secure; HttpOnly; SameSite=Strict"

    accessControlAllowMethods:
      - "GET"
      - "OPTIONS"
      - "PUT"
      - "POST"
    accessControlAllowHeaders:
      - "*"

ka -f /dataF/k8s/tfk/header.yaml

  • 在 dashboard/#/http/middlewares 中可以看到

https://doc.traefik.io/traefik/routing/providers/kubernetes-ingress/

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata: 
  annotations: 
    traefik.ingress.kubernetes.io/router.middlewares: default-test-header@kubernetescrd
    # auth@file,default-prefix@kubernetescrd  #注意前面有命令空间名

# default-test-header   default是命名空间  test-header是中间件的name