On a Kubernetes cluster, I have multiple Deployment
resources. For security, I am using a sidecar proxy pattern where the Service
will proxy traffic to the sidecar, which will ensure authentication before passing on to the deployed application.
I am trying to set up Kustomize to do this. Since the sidecar definition is likely environment specific, I don't want to include the sidecar in my base manifests, but would like it to be an overlay. Since I have multiple deployments that will need to attach that sidecar, it seemed appropriate to have the sidecar specification be a common shared component. This seemed like appropriate use of the Kustomize Component
resource, but perhaps I'm wrong.
I have something similar to the following:
.
├── base
│ ├── app1
│ │ ├── deployment.yaml
│ │ └── kustomization.yaml
│ ├── app2
│ │ ├── deployment.yaml
│ │ └── kustomization.yaml
│ └── app3
│ ├── deployment.yaml
│ └── kustomization.yaml
├── components
│ └── sidecar
│ ├── deployment-sidecar.yaml
│ └── kustomization.yaml
└── overlays
└── dev
└── kustomization.yaml
I'd like the sidecar component to be applied to the 3 app deployments, but I can't seem to find a way to do this. Am I misusing components here?
My components/sidecar/kustomization.yaml
file looks like:
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
patches:
- path: deployment-sidecar.yaml
target:
labelSelector: xxx
This works, however it specifies the target of the patch in the component, whereas I would like to leave the component more generic and instead specify the target in overlays/dev
.
Is there a better way to be handling this? In summary, I want the overlay to be able to define when the sidecar should be added, and to which specific deployments to add it to.