kubernetes how to inherite anonntation inheritance from namespace annontation

10/16/2018

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.

-- Oz123
annotations
kubernetes
namespaces

1 Answer

10/16/2018

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
-- Arslanbekov
Source: StackOverflow