Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubernetes how to inherite anonntation inheritance from namespace annontation

Is there a way to inherit annotations to all resources in a namespace? My naive assumption was that I can annontate the namespace and that resources will get this annontation:

kubectl get --export namespaces non-native  -o yaml
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    foo: bar
  creationTimestamp: null
  name: non-native
  selfLink: /api/v1/namespaces/non-native
spec:
  finalizers:
  - kubernetes
status:
  phase: Active

Running

kubectl get --export pod -n non-native nginx-6f858d4d45-s2xzl  -o yaml

shows no foo=bar annotations.

Am I asking for the impossible? Can you achieve this?

update:

Although my example shows a Pod, I would like to annotate also other resources, like services, or PVCs etc.

like image 409
oz123 Avatar asked Feb 03 '26 14:02

oz123


1 Answers

I think podpreset can help

kind: PodPreset
apiVersion: settings.k8s.io/v1alpha1
metadata:
  annotations:
    foo: bar
  namespace: {youNamespace}

How enable PodPreset:

  1. You have enabled the api type settings.k8s.io/v1alpha1/podpreset
  2. You have enabled the admission controller PodPreset
  3. You have defined your pod presets
like image 64
Denis Avatar answered Feb 06 '26 03:02

Denis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!