This project allows you to dynamically add sidecar container for Metrics export by adding a single label inside your Pod Manifest.
:mage_man: :mage_man: :mage_man:
🤫 (In reality you can add any container, just adding the right configuration you can add Exporter for Prometheus, standardize the container definition, backdoor and so on. Please use this with 🧠)
Please run this command before start using this WebHook
kubectl api-versions | grep admissionregistration.k8s.io
The result should be:
admissionregistration.k8s.io/v1
admissionregistration.k8s.io/v1beta1
- Install all the go dependecies with
go mod tidy
- Start in local the webserver with
go run ./src -sidecarCfgFilePath conf/exporters_configuration/config.json
## Stopping the container is based with SIGTERM or SIGKILL signal.
- Move in the target K8s context and namespace
- Modified the values inside
Makefile
for
IMAGE_REPO = YOUR_REPO_HERE
IMAGE_NAME = YOUR_IMAGE_NAME_HERE
IMAGE_TAG = YOUR_TAG_HERE
APP = exporters-webhook
NAMESPACE = YOUR_NAMESPACE
CSR_NAME = exporters-webhook.YOUR_NAMESPACE.svc
- Launch the command
make release-chart
In any case you can directly use my DockerImage and use just release the chart inside the cluster.
For doing so, please run the ./helm/release_chart.sh
script from the root folder of the project.
- Add the label
exporter-injection: enabled
in the PodSpec template definiton (it works also for Deployment or Pod object, check the examples.) - Add the label
inject-exporters: value1,value2...
for the exporter you want to add inside the pod definition - Keep in mind the fact that the exporter Split the label
inject-exporters
for the number of requested exporter and add it dynamically, so you can add 1 or more sidecar at the same time - Some exporters are defined inside the
.Values.configurationMap
field, if you want to add or override the exporters use this field. - The dataPath inside the CM must contain the
config_
prefix (example:config_nginx.yaml
and you will addinject-exporters: nginx
for correctly retrieve the sidecarConfiguration) - The sidecar definition are based on the Container Struct from K8s.io. For example:
name: nginx-exporter
image: nginx/nginx-prometheus-exporter:0.4.2
ports:
- containerPort: 9113
resources:
requests:
memory: 10Mi
cpu: 10m
limits:
memory: 50Mi
cpu: 200m
args: ["-nginx.scrape-uri", "http://localhost:81/nginx-status"]
Sometimes you may find that pod is injected with sidecar container as expected, check the following items:
- The sidecar-injector webhook is in running state and no error logs.
- The namespace in which application pod is deployed has the correct labels as configured in
mutatingwebhookconfiguration
. - Check the
caBundle
is patched tomutatingwebhookconfiguration
object by checking ifcaBundle
fields is empty. - Check if the application pod has annotation
exporter-injection: enabled
.
Please refeer at the example inside the helm folder, files:
- test-deployment.yaml
- test-pod.yaml