A simple kubernetes controller which ensures proper termination of sidecar containers
- go v1.17
- Kubernetes 1.19
- Deploy this controller. See How to deploy
- Add an annotation to pods which have sidecar containers. Annotation format is
limgit/sidecars: <sidecar>,<container>,<name>
# Example pod configuration.
# After `main` container finishes,
# the sidecar controller will send SIGTERM to `sidecar` container
apiVersion: v1
kind: Pod
metadata:
name: busybox-sleep
namespace: default
annotations:
limgit/sidecars: sidecar
spec:
containers:
- name: sidecar
image: busybox
args:
- sleep
- "1000000"
- name: main
image: busybox
args:
- sleep
- "20"
- Tada! This controller will clean up sidecar containers if every containers but sidecar containers are completed!
- Build docker image with
Dockefile
- Push docker image to image repository
- In
deployment.yaml
, set correct image tag forDeployment
resource kubectl apply -f deployment.yaml