Monitoring — track Pod security compliance.
1# PrometheusRule for PSS violations2apiVersion: monitoring.coreos.com/v13kind: PrometheusRule4metadata:5 name: pss-violations6 namespace: monitoring7spec:8 groups:9 - name: pss10 rules:11 - alert: PodSecurityPolicyViolation12 expr: increase(kubernetes_audit_event_total{verb="create",resource="pods",user_agent!="kube-controller-manager"}[5m]) > 013 for: 5m14 labels:15 severity: warning16 annotations:17 summary: "Pod security policy violation detected"18 description: "Namespace {{ $labels.namespace }} has Pod security violations"19---20# Grafana dashboard for PSS21apiVersion: v122kind: ConfigMap23metadata:24 name: pss-dashboard25 namespace: monitoring26data:27 pss-dashboard.json: |28 {29 "panels": [30 {31 "title": "PSS Violations by Namespace",32 "targets": [33 {34 "expr": "sum(rate(kubernetes_audit_event_total{verb=\"create\",resource=\"pods\"}[5m])) by (namespace)",35 "legendFormat": "{{ namespace }}"36 }37 ]38 }39 ]40 }
1# Check audit events2kubectl get events -A --sort-by=.lastTimestamp | grep -i "audit\|warn\|error"34# View PSS violations5kubectl get events -A --field-selector reason=FailedCreate --sort-by=.lastTimestamp67# Check namespace compliance8kubectl get namespaces -o json | jq '.items[] | {name: .metadata.name, labels: .metadata.labels}' | grep pod-security910# Monitor Pod security11kubectl get pods -A -o json | jq '.items[] | {name: .metadata.name, namespace: .metadata.namespace, securityContext: .spec.securityContext}'1213# Check Prometheus alerts14kubectl get prometheusrule -n monitoring15kubectl describe prometheusrule pss-violations -n monitoring1617# View Grafana dashboard18kubectl get configmap pss-dashboard -n monitoring -o yaml
Monitoring Tools:
Metrics: