Sign inSign up

ceroic/kubectl-watch

By ceroic

•Updated over 10 years ago

Renders and continually checks `kubectl get` results.

Image
0

386

ceroic/kubectl-watch repository overview

⁠kubectl-watch

kubectl-watch is a docker image that allows a user to continuously check the results of a kubectl get command, and pipe it through a template when the results change.

The original purpose of the image was to help drive an automatic k8s edge router that updated its configuration whenever services became available with specific labels.

⁠Usage:

To use kubectl-watch, you are basically configuring a kubectl get command and then mount volumes for the templates and output.

Here's a docker-compose example:

label-watcher:
    image: ceroic/kubectl-watch
    volumes:
      - ~/.kube:/root/.kube:ro
      - ./templates:/var/kubectl-watch/templates
      - ./output:/var/kubectl-watch/output
    environment:
      TYPE: svc
      SELECTOR: app=my-app
      TEMPLATE: my-fancy-template.txt
      OUTPUT_FILE: my-fancy-output.txt

NOTE: This example assumes you are testing locally and mounts authentication directly as a volume. Ideally in a production setting this container would be running with access to a service account that authorizes kubectl to the k8s API.

⁠Environment Variables:

kubectl-watch requires the following environment variables to work.

VariableDescription
TYPEThe k8s service type to pass to the kubectl get call.
SELECTORThe kubectl get label selector passed to the -l parameter
TEMPLATEThe filename of the template to render. Needs to be available in the templates directory
OUTPUT_FILEThe name of the file to output to the output directory.
⁠Optional Environment Variables:
VariableDescription
INTERVALThe amount of time between each check. Defaults to 5 seconds.
⁠Volumes:

kubectl-watch assumes you will be mounting two volumes to the container at run time.

VolumeInternal PathDescription
Templates/var/kubectl-watch/templatesTemplates available to render.
Output/var/kubectl-watch/outputWhere rendered templates are output to.
⁠Template Syntax:

kubectl-watch renders all templates using the -o go-template-file and --template= flags. All templates use Go template syntax. More information can be found here:

https://golang.org/pkg/text/template/⁠

Tag summary

Content type

Image

Digest

Size

347.8 MB

Last updated

over 10 years ago

docker pull ceroic/kubectl-watch