Здесь моя настройка файлов:
$ tree ./kustomize/base
./kustomize/base
├── configurations
│ ├── common-annotations.yaml
│ └── common-labels.yaml
├── kustomization.yaml
├── resources
│ ├── deployment.yaml
│ └── service.yaml
└── transformers
├── annotations-transformer.yaml
└── labels-transformer.yaml
Мой kustomization.yaml
:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configurations:
- configurations/common-annotations.yaml
commonAnnotations:
prometheus.io/path: /actuator/prometheus
prometheus.io/port: '8080'
prometheus.io/scrape: 'true'
resources:
- resources/deployment.yaml
- resources/service.yaml
Мой configurations/common-annotations.yaml
:
commonAnnotations:
- path: spec/template/metadata/annotations
create: true
# group: apps
version: apps/v1
kind: Deployment
Как вы можете видите, я хочу добавить аннотации только к Deployment
объектам. Однако
$ kustomize build kustomize/base
apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/path: /actuator/prometheus
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
name: covid-backend
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
prometheus.io/path: /actuator/prometheus
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
name: covid-backend
spec:
replicas: 2
template:
metadata:
labels:
app2: covid-backend
spec:
containers:
- image: covid-backend
ports:
- containerPort: 8080
Как видите, он добавляет аннотацию ко всем объектам (сервис, развертывание ...), кроме spec/template/metadata/annotations
. Мне нужно прямо противоположное.
Если я прокомментирую configurations
на kustomize.yaml
:
$ kustomize build kustomize/base
apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/path: /actuator/prometheus
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
name: covid-backend
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
prometheus.io/path: /actuator/prometheus
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
name: covid-backend
spec:
replicas: 2
template:
metadata:
annotations:
prometheus.io/path: /actuator/prometheus
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
labels:
app2: covid-backend
spec:
containers:
- image: covid-backend
ports:
- containerPort: 8080
Затем аннотации добавляются также на spec/template/metadata/annotations
.