Containers Rules Best Practices
This page distills the container and Kubernetes rule set into practices you can adopt, in the order that a platform team usually adopts them.
Search across all documentation pages
This page distills the container and Kubernetes rule set into practices you can adopt, in the order that a platform team usually adopts them.
The single most important idea: automate rules with policy engines wherever possible, so compliance is the default and not a review-time argument.
Read this after the checklist. The checklist tells you what to enforce; this page tells you how to roll it out without stalling every team.
Adopt the groups roughly top to bottom. Each practice is written as an action with the reasoning attached.
hadolint, kubeconform, and Trivy in pre-commit and CI give fast, friendly feedback before code lands.apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: disallow-latest-tag
spec:
validationFailureAction: Enforce
rules:
- name: require-digest-or-tag
match:
any:
- resources:
kinds: [Pod]
validate:
message: "Images must not use the :latest tag"
pattern:
spec:
containers:
- image: "!*:latest"restricted enforces a large class of rules with zero custom policy code.validationFailureAction: Audit, publish the violations, and let teams see the impact before you enforce.restricted in a non-critical namespace, then expand.You should be able to point at a repository that defines every rule, a CI pipeline that catches most violations early, and an admission layer that makes the critical ones impossible to bypass.
New services should pass by default because the golden path already complies. Exceptions should be visible, owned, and expiring.
If any of those is missing, that gap is your next highest-leverage piece of work.
Kyverno or Gatekeeper? Kyverno uses Kubernetes-native YAML policies and is quick to adopt; Gatekeeper uses OPA/Rego and suits teams already invested in Rego. Either satisfies these practices.
Do policy engines replace Pod Security Standards? No. Use PSS for baseline pod hardening and a policy engine for everything PSS cannot express, like registry allow-lists or required labels.
How do I introduce enforcement without an outage? Always start in audit mode, fix golden-path templates, roll out per namespace, and only then switch to enforce.
Where do these practices stop and design decisions begin? When a team wants to deviate from a rule for architectural reasons, capture it in an ADR rather than a quiet exception.
How many policies are too many? When exception volume and false positives outweigh the incidents prevented. Measure, then prune.
Can I enforce image signing gradually? Yes - verify in audit mode, onboard pipelines to cosign, then flip signature verification to enforce once coverage is high.
Stack versions: This page was written for Kubernetes 1.36.2, Docker Engine 29.6.1 (BuildKit default), containerd (CRI runtime on nodes), Helm 3, Compose v2, Argo CD (latest - verify at build), and Gateway API (GA - verify controller support at build).
Reviewed by Chris St. John·Last updated Jul 16, 2026