I would like to create 2 deployments out of the same base and all in 1 kustomization.yml. To be a bit more precise, we have 1 base deployment for multiple customer and make our changes inside the kustomization, so all customer has the same base. This works fine until our new customer needs 2 kafka exporter (not replicas).
I would like to use the same base and create out of this base 2 deployments with different args.
/base/
/kustomization.yml
/kafka-exporter.yml
/....
/overlays/
/overlay1/
/kustomization.yml
/kafka-exporter.yml
/kafka-exporter-passive.yml
/....
/overlay2/
/kustomization.yml
/kafka-exporter-patch.yml
/....
/base/kafka-exporter.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: kafka-exporter
name: kafka-exporter
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: kafka-exporter
template:
metadata:
labels:
app: kafka-exporter
spec:
imagePullSecrets:
- name: docker-token
containers:
- name: kafka-exporter
image: XXXXX
ports:
- name: kafka-exporter
containerPort: 9308
protocol: TCP
args:
- "--kafka.server=xxxxxxxx"
- --tls.enabled
- --tls.insecure-skip-tls-verify
- --tls.cert-file=/etc/tls-certs/tls.crt
- --tls.key-file=/etc/tls-certs/tls.key
- --refresh.metadata=60s
#- "--topic.filter=DUMMY"
volumeMounts:
- name: tls-certs
readOnly: true
mountPath: "/etc/tls-certs"
resources:
limits:
cpu: 500m
memory: 200Mi
requests:
cpu: 250m
memory: 100Mi
securityContext:
runAsNonRoot: true
runAsUser: 999
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
restartPolicy: Always
volumes:
- name: tls-certs
secret:
secretName: xxxxxx
- name: policy-volume
emptyDir:
sizeLimit: 5Mi
/base/kustomization.yml
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./kafka-exporter.yml
/overlay/kustomization.yml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: example
nameSuffix: -example
resources:
- ../base
patches:
- path: ./kafka-exporter.yml
target:
kind: Deployment
- path: ./kafka-exporter-passive.yml
target:
kind: Deployment
/overlay/kafka-exporter.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: kafka-exporter
spec:
template:
spec:
containers:
- name: kafka-exporter
args:
- "--kafka.server="
- --tls.enabled
- --tls.insecure-skip-tls-verify
- --tls.cert-file=/etc/tls-certs/tls.crt
- --tls.key-file=/etc/tls-certs/tls.key
- --refresh.metadata=60s
- "--topic.filter=.*test*"
/overlay/kafka-exporter-passive.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: kafka-exporter
spec:
template:
spec:
containers:
- name: kafka-exporter
args:
- "--kafka.server=xxxxx"
- --tls.enabled
- --tls.insecure-skip-tls-verify
- --tls.cert-file=/etc/tls-certs/tls.crt
- --tls.key-file=/etc/tls-certs/tls.key
- --refresh.metadata=60s
- "--topic.filter=.*something_else.*"
I tried to create a second patch yml and add it to patchesStrategicMerge in the kustomization.yml in the overlay, but this still creates only 1 deployment.
You are using same deployment name twice. Second one is replacing values of first one, that's because its deploying only one.
Try create another deployment with different name, and patch it under your overlays with another file.