https://hub.docker.com/r/expediagroup/kubernetes-sidecar-injector
This mutating webhook was developed to inject sidecars to a Kubernetes pod.
If one is interested in contributing to this codebase, please read the developer documentation on how to build and test this codebase.
We have provided two ways to deploy this webhook. Using Helm and using kubectl. Deployment files are in deployment/helm
and deployment/kubectl
respectively.
NOTE: Applications only have access to sidecars in their own namespaces.
apiVersion: v1
kind: ConfigMap
metadata:
name: my-app-sidecar
namespace: my-app-namespace
data:
sidecars.yaml: |
- name: # Sidcar Name
initContainers:
- name: # Example 1
image: # Example 1
containers:
- name: # Example 2
image: # Example 2
volumes:
- name: # Example 3
configMap:
name: # Example 3
imagePullSecrets:
- name: # Example 4
-
Deploy this mutating webhook by cloning this repository and running the following command (needs kubectl installed and configured to point to the kubernetes cluster or minikube)
make helm-install
-
By default, all namespaces are watched except
kube-system
andkube-public
. This can be configured in your helm values. -
Add the annotation (
sidecar-injector.expedia.com/inject
by default) with ConfigMap sidecar name to inject in pod spec where sidecar needs to be injected. This sample spec shows such an annotation added to a pod spec to injecthaystack-agent
. -
Create your ConfigMap sidecar configuration
apiVersion: v1
kind: ConfigMap
metadata:
name: my-app-sidecar
namespace: {{ .Release.Namespace }}
data:
sidecars.yaml: |
- name: busybox
initContainers:
- name: busybox
image: busybox
command: [ "/bin/sh" ]
args: [ "-c", "echo '<html><h1>Hi!</h1><html>' >> /work-dir/index.html" ]
volumeMounts:
- name: workdir
mountPath: "/work-dir"
You need to add this repository to your Helm repositories:
helm repo add kubernetes-sidecar-injector https://opensource.expediagroup.com/kubernetes-sidecar-injector/
helm repo update
make kind
make install-sample-init-container # or make install-sample-container
make follow-logs