apiVersion: networking.k8s.io/v1 kind: Ingress metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | if ($request_method = 'OPTIONS') { add_header 'Access-Control-Max-Age' 1728008; add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Headers' '*'; add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,PATCH,OPTIONS'; return 200; } kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/cors-allow-credentials: "true" nginx.ingress.kubernetes.io/cors-allow-headers: DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,token,Cookie nginx.ingress.kubernetes.io/cors-allow-methods: PUT, GET, POST, OPTIONS nginx.ingress.kubernetes.io/cors-allow-origin: '*' nginx.ingress.kubernetes.io/enable-cors: "true" nginx.ingress.kubernetes.io/proxy-body-size: 300m name: flaskdemo namespace: {{NAMESPACE}} spec: rules: - host: {{INGRESS_FLASKDEMO}} http: paths: - path: / pathType: Prefix backend: service: name: flaskdemo port: number: 5000
标签:Control,ingress,跨域,kubernetes,nginx,io,cors,k8s From: https://www.cnblogs.com/quemengqio/p/17106362.html