Effortlessly tailor Kubernetes deployments with dynamic modifications.
Project details
kTailor is a lightweight Kubernetes Mutating Webhook that simplifies modifications to deployments. With kTailor, you can effortlessly inject sidecars, environment variables and volumes using reusable YAML templates stored in ConfigMaps - all without altering original source manifests. Built for ease and efficiency, it's the solution for managing standard infrastructure components in Kubernetes.

In modern Kubernetes environments, developers often need to inject standard infrastructure components into their applications like monitoring sidecars, proxy configurations, or specific environment variables. In our case we needed to add an initContainer to inject libfaketime into the pods which enables the containers to travel through time.
Instead of cluttering every single Deployment manifest, we built a lightweight Kubernetes Mutating Webhook that centralizes these modifications: kTailor. It's designed to dynamically modify Deployments without altering the original source manifests. The configuration is stored in simple, reusable ConfigMaps, where the essential infrastructure components to inject (like initContainers, sidecars, environment variables and volumes) are defined using the common kubernetes markup.
kTailor is ideal for scenarios requiring standard modifications, such as adding monitoring sidecars or environment variables. However, it is not suited for complex policy enforcement or validations beyond standard Deployments. For those needs, consider other established policy engines like Kyverno or OPA Gatekeeper.
Templates in kTailor are managed as standard Kubernetes ConfigMaps. To activate a template, the Deployment must feature the ktailor.dev/fit label pointing to the template name:
kubectl label --overwrite deployment myapp ktailor.dev/fit="local.ktlr-proxy-tmpl"
Inject an environment variable into an existing container with a simple central template:
apiVersion: v1
kind: ConfigMap
metadata:
name: ktailor-test
namespace: ktailor
labels:
ktailor.dev/template: "true"
data:
template: |
kind: ktailor-template
modifyContainers:
insertOrOverwrite:
env:
- name: KTAILORTEST
value: "Env set by central kTailor template."
Utilizing libfaketime, kTailor can manipulate system time for a specific container while keeping the actual node time unchanged. This template includes shared volumes and an InitContainer setup:
apiVersion: v1
kind: ConfigMap
metadata:
name: lft-plus222d
namespace: ktailor
labels:
ktailor.dev/template: "true"
data:
template: |
kind: ktailor-template
modifyContainers:
insertIfNotExists:
volumeMounts:
- name: shared-lft-volume
mountPath: /lft_volume
insertOrOverwrite:
env:
- name: FAKETIME
value: "+222d"
setOrAppend:
env:
- name: LD_PRELOAD
value: "/lft_volume/libfaketime.so.1"
addInitContainers:
- name: inject-libfaketime
image: katalytic/libfaketime_init:1.0
env:
- name: LFT_DESTPATH
value: /lft_volume
volumeMounts:
- name: shared-lft-volume
mountPath: /lft_volume
addVolumes:
volumes:
- name: shared-lft-volume
emptyDir: {}
Explore kTailor and try it online at killercoda.com. For comprehensive documentation, visit ktailor.dev. This repository enhances the deployment experience within Kubernetes, streamlining the addition of necessary components efficiently.
Comments
0Start the conversation
Share the first comment.