This repo contains the complete code for my Kubernetes Sidecar Container Injection Medium article to create a Kubernetes mutating admission controller that injects a busybox-curl sidecar container into pods.
- Install the
kubernetes-sidecar-injector
chart
helm install kubernetes-sidecar-injector charts/kubernetes-sidecar-injector/ \
--values charts/kubernetes-sidecar-injector/values.yaml \
--namespace default
- Install the
httpbin
chart
helm install httpbin charts/httpbin/ \
--values charts/httpbin/values.yaml \
--namespace default
- Listing all containers in the httpbin Deployment's Pod, you can notice that a new container is running in it named
curl
.
export POD_NAME=$(kubectl get pods \
--namespace default \
-l "app.kubernetes.io/name=httpbin,app.kubernetes.io/instance=httpbin" \
-o jsonpath="{.items[0].metadata.name}")
kubectl get pods $POD_NAME \
--namespace default \
-o jsonpath='{.spec.containers[*].name}'
- Accessing the httpbin HTTP server from inside the curl container.
export POD_NAME=$(kubectl get pods \
--namespace default \
-l "app.kubernetes.io/name=httpbin,app.kubernetes.io/instance=httpbin" \
-o jsonpath="{.items[0].metadata.name}")
kubectl exec $POD_NAME \
--namespace default \
-c curl \
-- curl http://localhost/anything