Coder Social home page Coder Social logo

expediagroup / kubernetes-sidecar-injector Goto Github PK

View Code? Open in Web Editor NEW
77.0 6.0 35.0 3.05 MB

Kuberbetes mutating webhook that injects a sidecar container to a pod

License: Apache License 2.0

Go 93.57% Dockerfile 0.63% Shell 0.75% Makefile 3.79% Smarty 1.27%
kubernetes golang haystack mutating-webhook oss-portal-listed

kubernetes-sidecar-injector's Introduction

helm-release-gha semantic-release: conventionalcommits License

Kubernetes Mutating Webhook

https://hub.docker.com/r/expediagroup/kubernetes-sidecar-injector

This mutating webhook was developed to inject sidecars to a Kubernetes pod.

Developing

If one is interested in contributing to this codebase, please read the developer documentation on how to build and test this codebase.

Using this webhook

We have provided two ways to deploy this webhook. Using Helm and using kubectl. Deployment files are in deployment/helm and deployment/kubectl respectively.

ConfigMap Sidecar Configuration

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

How to enable sidecar injection using this webhook

  1. 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
  2. By default, all namespaces are watched except kube-system and kube-public. This can be configured in your helm values.

  3. 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 inject haystack-agent.

  4. 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"

How to use the kubernetes-sidecar-injector Helm repository

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

Kind Testing

make kind
make install-sample-init-container # or make install-sample-container
make follow-logs

kubernetes-sidecar-injector's People

Contributors

ayansen avatar jcchavezs avatar jocelyndrw avatar manali1205 avatar mchandramouli avatar mvaalexp avatar mwm5945 avatar rwejlgaard avatar tehlers320 avatar tonyo avatar worldtiki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kubernetes-sidecar-injector's Issues

mandatory (not optional) sidecars

Hi,
This is a cool tool!

Is there a way to make it fail to start the pod if the configmap doesn't exist? Right now the service logs an error but the pod continues to start.

Maybe something like an annotation:
sidecar-injector.expedia.com/failAction: block

Multiple patches leads to incorrect JSON patch path

If multiple items are specified in the ConfigMap, i.e. multiple Init Containers, volumes, etc, the createArrayPatches function will incorrectly append /- to the path, even though it has already been updated. This results in an error from the replica controller stating that the Patch Path is missing keys. Example of what happens when trying to add two volumes for a side car:

Internal error occurred: add operation does not apply: doc is missing path: "/spec/volumes/-/-": missing value

Removing the second volume fixes the issue.

A few suggestions

This plugin is very good, but there are a few suggestions.

  1. If the namespace exists kubernetes-sidecar-injector: enabled label, the sidecar is automatically injected.
  2. If the namespace does not exist kubernetes-sidecar-injector: enabled label, but the deployment's .spec.template.metadata.annotation exists sidecar-injector.expedia.com/inject: true when injecting sidecar.
  3. If the namespace has kubernetes-sidecar-injector: enabled label and the deployment's .spec.template.metadata.annotation has sidecar-injector.expedia.com/inject: false, no sidecar is injected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.