Best Practices — recommended Pod security configurations.
1# Recommended restricted Pod2apiVersion: v13kind: Pod4metadata:5 name: best-practice-pod6 namespace: production7spec:8 securityContext:9 runAsNonRoot: true10 runAsUser: 100011 runAsGroup: 100012 fsGroup: 100013 fsGroupChangePolicy: OnRootMismatch14 seccompProfile:15 type: RuntimeDefault16 containers:17 - name: app18 image: nginx:latest19 securityContext:20 allowPrivilegeEscalation: false21 readOnlyRootFilesystem: true22 capabilities:23 drop:24 - ALL25 runAsNonRoot: true26 runAsUser: 100027 resources:28 requests:29 cpu: "250m"30 memory: "256Mi"31 limits:32 cpu: "1000m"33 memory: "512Mi"34 volumeMounts:35 - name: tmp36 mountPath: /tmp37 - name: cache38 mountPath: /var/cache/nginx39 volumes:40 - name: tmp41 emptyDir: {}42 - name: cache43 emptyDir: {}44---45# Namespace with all PSS labels46apiVersion: v147kind: Namespace48metadata:49 name: production50 labels:51 pod-security.kubernetes.io/enforce: restricted52 pod-security.kubernetes.io/enforce-version: latest53 pod-security.kubernetes.io/audit: restricted54 pod-security.kubernetes.io/audit-version: latest55 pod-security.kubernetes.io/warn: restricted56 pod-security.kubernetes.io/warn-version: latest
1# Check best practices2kubectl get pod best-practice-pod -o jsonpath='{.spec.securityContext}' | jq3kubectl get pod best-practice-pod -o jsonpath='{.spec.containers[0].securityContext}' | jq45# Verify security6kubectl exec best-practice-pod -- id7kubectl exec best-practice-pod -- whoami8kubectl exec best-practice-pod -- cat /proc/1/status | grep Cap910# Check read-only filesystem11kubectl exec best-practice-pod -- touch /test 2>&11213# Verify seccomp profile14kubectl get pod best-practice-pod -o jsonpath='{.spec.securityContext.seccompProfile}' | jq1516# Check namespace policy17kubectl get namespace production -o yaml | grep pod-security
Best Practices: