Apply policies to resources
You can reference policies from VirtualServer, VirtualServerRoute, and Ingress resources. How you attach a policy depends on the resource type.
You can attach policies at:
spec.policiesfor server-wide behaviorspec.routes[].policiesfor route-specific behavior
Example:
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: cafe
spec:
host: cafe.example.com
policies:
- name: access-policy
upstreams:
- name: coffee
service: coffee-svc
port: 80
routes:
- path: /coffee
policies:
- name: route-cors-policy
action:
pass: coffeeYou can attach policies at:
spec.subroutes[].policies
Example:
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: tea
spec:
host: cafe.example.com
upstreams:
- name: tea
service: tea-svc
port: 80
subroutes:
- path: /tea
policies:
- name: subroute-policy
action:
pass: teaIngress uses annotations instead of a policies field.
Supported annotations are:
nginx.org/policiesnginx.com/policies
Example:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: webapp
annotations:
nginx.org/policies: access-policy,cors-policy
spec:
ingressClassName: nginx
rules:
- host: webapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: webapp
port:
number: 80Learn about ingress-specific policy behavior.