GithubHelp home page GithubHelp logo

atorrescogollo / k8s-volume-injector Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 20 KB

Inject volumes to all Pods inside a namespace using MutatingWebhookConfigurations

Dockerfile 5.79% Go 92.80% Shell 1.41%

k8s-volume-injector's Introduction

Kubernetes Volume Injector

Dynamically add volumes to all pods inside all namespaces with the label k8s-volume-injector: "true".

Use cases

  • You need to mount /etc/ssl/certs as a hostPath for every pod in order to get pods to trust private CA certificates.
  • You need to mount a PersistentVolumeClaim for every pod in order to save logs or data.

Requirements

  • Kubernetes cluster up & running
  • Certmanager needs to be installed

Installation

  1. Create the namespace k8s-volume-injector:
kubectl apply -f deployment/01_namespace.yaml
  1. Configure your k8s-volume-injector instance:
vim deployment/02_configmap.yaml # EDIT volumes and volumeMounts as you consider
kubectl apply -f deployment/02_configmap.yaml
  1. Deploy k8s-volume-injector:
kubectl apply -f deployment/03_deployment.yaml

NOTE: Wait until pod is running and ready: kubectl get po -n k8s-volume-injector NAME READY STATUS RESTARTS AGE k8s-volume-injector-776fb7cd9f-v9vnz 1/1 Running 0 10s

  1. Configure the CA bundle for the webhook:
caBundle=$( kubectl get secrets -n k8s-volume-injector k8s-volume-injector-cert -o go-template='{{ index .data "ca.crt" }}' )
sed "s@___CA_BUNDLE___@$caBundle@g" deployment/04_webhook.yaml.tmpl > deployment/04_webhook.yaml
  1. Deploy the webhook:
kubectl apply -f deployment/04_webhook.yaml

Test webhook

  1. Deploy a demo nginx pod:
kubectl apply -f examples/demo.yaml
  1. Verify volumes and volumeMounts:
$ kubectl -n k8s-volume-injector-demo describe po testpod1
Name:         testpod1
Namespace:    k8s-volume-injector-demo
...
Containers:
  web:
    ...
    Mounts:
      /etc/ssl/certs from etc-ssl-certs (ro)
      ...
...
Volumes:
  ...
  etc-ssl-certs:
    Type:          HostPath (bare host directory volume)
    Path:          /etc/ssl/certs
    HostPathType:
...
  1. Cleanup

Uninstallation

kubectl delete -f deployment/04_webhook.yaml # To ensure that the service is not affected
kubectl delete -f deployment/

k8s-volume-injector's People

Contributors

atorrescogollo avatar

Stargazers

Lucas Romero avatar

Watchers

 avatar

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.