Yisaer / sidecar-inject-server

a simple sidecar-inject server in kubernetes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

Sidecar-Inject is a simple server to inject containers into Pod By Sidecar which defined by CRD

It's easy to use and also offer container selector ability.

Prerequisites

Kubernetes 1.9.0 or above with the admissionregistration.k8s.io/v1beta1 API enabled. Verify that by the following command:

kubectl api-versions | grep admissionregistration.k8s.io/v1beta1

The result should be:

admissionregistration.k8s.io/v1beta1

In addition, the MutatingAdmissionWebhook admission controllers should be added and listed in the correct order in the admission-control flag of kube-apiserver.

Build Image

Sidecar-inject is managed by go mod

run build.sh to build docker image

How to Install

you can install sidecar-inject by Helm

First install sidecar-inejct-init

helm install install/helm/sidecar-inject-init --name sidecar-init --namespace sidecar-system 

Then install sidecar-inject-server

helm install install/helm/sidecar-inject-server --name sidecar-server --namespace sidecar-system --values install/helm/sidecar-inject-server/values.yaml 

How to test

Label the namespace and create a deployment to test sidecar-inject-server

kubectl label namespace sidecar-system sidecar-injector=enabled
kubectl apply -f example/

And Here is the result

$ kubectl get sidecar
NAME                CREATED AT
test-sidecarset     55m
test-sidecarset-2   55m

$ kubectl get pod
NAME                                                    READY   STATUS        RESTARTS   AGE
sidecar-server-sidecar-inject-server-6b9dff7dd6-7b5nq   1/1     Running       0          39m
sleep-578649fc85-xcg2r                                  3/3     Running       0          20s

Sidecar

Sidecar is defined by CRD. It shows which containers developers want to inject Into Pod When they are creating by containers and it also offer the selector condition ability by selector

Here is one example for Sidecar. All Pods will be injected Containers defined in containers if their annotations contain app key and its value is sidecar1

apiVersion: yisaer.github.io/v1alpha1
kind: Sidecar
metadata:
  name: test-sidecarset
spec:
  selector:
    matchLabels:
      app: sidecar1
  containers:
    - name: sidecar1
      image: centos:7
      command: ["sleep", "999d"]
    - name: sidecar2
      image: centos:7
      command: ["sleep", "999d"]

About

a simple sidecar-inject server in kubernetes

License:Apache License 2.0


Languages

Language:Go 79.1%Language:Smarty 18.3%Language:Shell 1.7%Language:Dockerfile 0.9%