Example: creating a Pod

apiVersion: audit.k8s.io/v1, kind: Policy) that contains two primary parts:
omitStages(optional): stages to exclude from logging (for example["RequestReceived"]).rules: an ordered list of rules that select which requests to log and at what verbosity.
namespaces, verbs (create, update, delete, etc.), resources and groups, resourceNames (specific object names), and more. Each rule also sets a level to control verbosity:
Example policy (omits
RequestReceived, logs full RequestResponse for deletes of a specific Pod in prod-namespace, and logs Metadata for Secrets cluster-wide):
namespacesis optional; if omitted the rule applies to all namespaces.verbsis optional; if omitted the rule applies to all operations.groupsidentifies the API group; core/v1 resources use an empty string ("").
Audit logs can grow quickly when you use verbose levels or broad-scoped rules. Craft rules narrowly (specific namespaces, verbs, and resourceNames) and configure rotation/retention for the backend to keep logs manageable.
This lesson focuses on the log backend. To enable the log backend, pass kube-apiserver flags pointing to the audit policy file and the desired log path, and optionally configure rotation/retention:
--audit-log-path=/var/log/k8-audit.log--audit-policy-file=/etc/kubernetes/audit-policy.yaml--audit-log-maxage=10(days to retain)--audit-log-maxbackup=5(number of rotated files to keep)--audit-log-maxsize=100(megabytes before rotation)
Logging
Request or RequestResponse bodies may capture sensitive data (for example, Secrets or tokens). Take care to restrict access to audit logs and avoid storing sensitive request/response bodies unnecessarily.prod-namespace:
--audit-policy-file. Then delete a Pod named webapp-pod in the prod-namespace: