Kubernetes Namespaces are an optional feature that provide a way to segment and isolate cluster resources across multiple applications and users. As a best practice, workloads should be isolated with Namespaces. Namespaces should be required and the default (empty) Namespace should not be used. This policy validates that Pods specify a Namespace name other than `default`. Rule auto-generation is disabled here due to Pod controllers need to specify the `namespace` field under the top-level `metadata` object and not at the Pod template level.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: disallow-default-namespaceannotations:pod-policies.kyverno.io/autogen-controllers: nonepolicies.kyverno.io/title: Disallow Default Namespacepolicies.kyverno.io/minversion: 1.6.0policies.kyverno.io/category: Multi-Tenancypolicies.kyverno.io/severity: mediumpolicies.kyverno.io/subject: Podpolicies.kyverno.io/description: Kubernetes Namespaces are an optional feature that provide a way to segment and isolate cluster resources across multiple applications and users. As a best practice, workloads should be isolated with Namespaces. Namespaces should be required and the default (empty) Namespace should not be used. This policy validates that Pods specify a Namespace name other than `default`. Rule auto-generation is disabled here due to Pod controllers need to specify the `namespace` field under the top-level `metadata` object and not at the Pod template level.spec:validationFailureAction: Auditbackground: truerules:- name: validate-namespacematch:any:- resources:kinds:- Podvalidate:message: Using 'default' namespace is not allowed.pattern:metadata:namespace: "!default"- name: validate-podcontroller-namespacematch:any:- resources:kinds:- DaemonSet- Deployment- Job- StatefulSetvalidate:message: Using 'default' namespace is not allowed for pod controllers.pattern:metadata:namespace: "!default"
This policy performs some best practices validation on Application fields. Path or chart must be specified but never both. And destination.name or destination.server must be specified but never both.
This policy prevents the use of the default project in an Application.
This policy prevents updates to the project field after an Application is created.