Categorygithub.com/bumbacea/k8s-sidecar
repositorypackage
0.0.0-20250118183518-36b60cee22da
Repository: https://github.com/bumbacea/k8s-sidecar.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

Docker Pulls Docker Image Size (latest semver)

What?

This is a docker container intended to run inside a kubernetes cluster to collect config maps with a specified label and store the included files in an local folder. It can also send an HTTP request to a specified URL after a configmap change. The main target is to be run as a sidecar container to supply an application with information from the cluster.

Why?

This is our simple way to provide files from configmaps or secrets to a service and keep them updated during runtime. This was inspired by kiwigrid/k8s-sidecar and is aiming to be a golang port of that app. It started when I considered usage of 100MB of ram too much for the declared scope.

How?

Run the container created by this repo together with your application in a single pod with a shared volume. Specify which label should be monitored and where the files should be stored. By adding additional env variables the container can send an HTTP request to specified URL.

Where?

Images are available at:

All are identical multi-arch images built for amd64, arm64, arm/v7, ppc64le and s390x

Features

  • Extract files from config maps and secrets
  • Filter based on label
  • Update/Delete on change of configmap or secret
  • Support binaryData for both Secret and ConfigMap kinds
    • Binary data content is base64 decoded before generating the file on disk
    • Values can also be base64 encoded URLs that download binary data e.g. executables
      • The key in the ConfigMap/Secret must end with ".url" (see)

Usage

One can override the default directory that files are copied into using a configmap annotation defined by the environment variable FOLDER_ANNOTATION (if not present it will default to k8s-sidecar-target-directory). The sidecar will attempt to create directories defined by configmaps if they are not present. Example configmap annotation:

metadata:
  annotations:
    k8s-sidecar-target-directory: "/path/to/target/directory"

If the filename ends with .url suffix, the content will be processed as a URL which the target file contents will be downloaded from.

Configuration Environment Variables

namedescriptionrequireddefaulttype
LABELLabel that should be used for filteringtrue-string
LABEL_VALUEThe value for the label you want to filter your resources on. Don't set a value to filter by any valuefalse-string
FOLDERFolder where the files should be placedtrue-string
FOLDER_ANNOTATIONThe annotation the sidecar will look for in configmaps to override the destination folder for files. The annotation value can be either an absolute or a relative path. Relative paths will be relative to FOLDER.falsek8s-sidecar-target-directorystring
NAMESPACEComma separated list of namespaces. If specified, the sidecar will search for config-maps inside these namespaces. It's also possible to specify ALL to search in all namespaces.falsenamespace in which the sidecar is runningstring
RESOURCEResource type, which is monitored by the sidecar. Options: configmap, secret, bothfalseconfigmapstring
REQ_URLURL to which send a request after a configmap/secret got reloadedfalse-URI
REQ_METHODRequest method GET or POST for requests tp REQ_URLfalseGETstring
REQ_PAYLOADIf you use REQ_METHOD=POST you can also provide json payloadfalse-json
REQ_RETRY_TOTALTotal number of retries to allow for any http request (*.url triggered requests, requests to REQ_URI and k8s api requests)false5integer
REQ_RETRY_BACKOFF_FACTORA backoff factor to apply between attempts after the second try for any http request (.url triggered requests, requests to REQ_URI and k8s api requests)false1.1float
REQ_TIMEOUTHow many seconds to wait for the server to send data before giving up for .url triggered requests or requests to REQ_URI (does not apply to k8s api requests)false10float
REQ_USERNAMEUsername to use for basic authentication for requests to REQ_URL and for *.url triggered requestsfalse-string
REQ_PASSWORDPassword to use for basic authentication for requests to REQ_URL and for *.url triggered requestsfalse-string
REQ_SKIP_TLS_VERIFYSet to true to skip tls verification for all HTTP requests (except the Kube API server, which are controlled by SKIP_TLS_VERIFY).false-boolean
DEFAULT_FILE_MODEThe default file system permission for every file. Use three digits (e.g. '500', '440', ...)false-string
KUBECONFIGif this is given and points to a file or ~/.kube/config is mounted k8s config will be loaded from this file, otherwise "incluster" k8s configuration is tried.false-string
WATCH_SERVER_TIMEOUTpolite request to the server, asking it to cleanly close watch connections after this amount of seconds (#85)false60integer