Skip to content

A fancy tool which manages Nginx configuration according to Kubernetes NodePort type services

License

Notifications You must be signed in to change notification settings

bilalcaliskan/nginx-conf-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nginx Conf Generator

CI Go Report Card Quality Gate Status Reliability Rating Maintainability Rating Security Rating Coverage Release Go version pre-commit License

That tool uses client-go to communicate with multi Kubernetes clusters and gets the port of NodePort type service which contains specific annotation. Then modifies the Nginx configuration and reloads the Nginx process.

Prerequisites

nginx-conf-generator uses the kubeconfig file for authentication and authorization with Kubernetes cluster. You should ensure that given kubeconfig file has read only access on the target cluster.

Also nginx-conf-generator needs to reload nginx process when necessary, you must run it with root user.

Configuration

nginx-conf-generator can be customized with several command line arguments:

Usage:
  nginx-conf-generator [flags]

Flags:
      --custom-annotation string      annotation to specify selectable services (default "nginx-conf-generator/enabled")
  -h, --help                          help for nginx-conf-generator
      --kubeconfig-paths string       comma separated list of kubeconfig file paths to access with the cluster (default "/home/joshsagredo/.kube/config")
      --metrics-endpoint string       endpoint to provide prometheus metrics (default "/metrics")
      --metrics-port int              port of the metrics server (default 5000)
      --template-input-file string    path of the template input file to be able to render and print to --template-output-file (default "resources/ncg.conf.tmpl")
      --template-output-file string   rendered output file path which is a valid Nginx conf file (default "/etc/nginx/conf.d/ncg.conf")
  -v, --verbose                       verbose output of the logging library (default false)
      --version                       version for nginx-conf-generator
      --worker-node-label string      label to specify worker nodes (default "worker")

That tool should be run on a Linux host and the user who runs the binary file nginx-conf-generator should have permissions to edit --template-output-file file and reload nginx process using below command:

$ nginx -s reload

If you want to cover multiple kubernetes clusters, add comma seperated list of kubeconfig paths with --kubeconfig-paths argument.

Installation

Binary

Binary can be downloaded from Releases page.

After then, you can simply run binary by providing required command line arguments:

$ ./nginx-conf-generator --kubeconfig-paths=~/.kube/config1,~/.kube/config2 --custom-annotation nginx-conf-generator/enabled

Homebrew

This project can be installed with Homebrew:

brew tap bilalcaliskan/tap
brew install bilalcaliskan/tap/nginx-conf-generator

Development

This project requires below tools while developing:

After you installed pre-commit, simply run below command to prepare your development environment:

$ pre-commit install -c build/ci/.pre-commit-config.yaml

License

Apache License 2.0