1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00
kyverno/samples/AddDefaultLabels.md
Chip Zoller 2c86496728
Add new sample policies (#1272)
* new samples; updates

* typos

* add policy to restrict LoadBalancer

* correct sample numbering

* fix typos

* add EnsurePodProbesDifferent

* add DisallowSecrets policy

* add AddDefaultLabels policy

* typo
2020-11-18 14:58:32 -08:00

1 KiB

Add default labels to objects

Labels are important pieces of metadata that can be attached to just about anything in Kubernetes. They are often used to tag various resources as being associated in some way. Kubernetes has no ability to assign a series of "default" labels to incoming objects. This sample policy shows you how to assign one or multiple labels by default to any object you wish. Here it shows adding a label called custom-foo-label with value my-bar-default to resources of type Pod, Service, and Namespace but others can be added or removed as desired.

Policy YAML

add_default_labels.yaml

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: add-default-labels
spec:
  background: false
  rules:
  - name: add-default-labels
    match:
      resources:
        kinds:
        - Pod
        - Service
        - Namespace
    mutate:
      patchStrategicMerge:
        metadata:
          labels:
            custom-foo-label: my-bar-default