https://github.com/bilalcaliskan/nginx-conf-generator
A fancy tool which manages Nginx configuration according to Kubernetes NodePort type services
https://github.com/bilalcaliskan/nginx-conf-generator
client-go golang k8s kubernetes nginx
Last synced: 5 months ago
JSON representation
A fancy tool which manages Nginx configuration according to Kubernetes NodePort type services
- Host: GitHub
- URL: https://github.com/bilalcaliskan/nginx-conf-generator
- Owner: bilalcaliskan
- License: apache-2.0
- Created: 2020-10-18T18:50:15.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-28T21:13:19.000Z (over 1 year ago)
- Last Synced: 2024-11-15T04:16:38.367Z (over 1 year ago)
- Topics: client-go, golang, k8s, kubernetes, nginx
- Language: Go
- Homepage:
- Size: 492 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nginx Conf Generator
[](https://github.com/bilalcaliskan/nginx-conf-generator/actions?query=workflow%3ACI)
[](https://goreportcard.com/report/github.com/bilalcaliskan/nginx-conf-generator)
[](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_nginx-conf-generator)
[](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_nginx-conf-generator)
[](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_nginx-conf-generator)
[](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_nginx-conf-generator)
[](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_nginx-conf-generator)
[](https://github.com/bilalcaliskan/nginx-conf-generator/releases/latest)
[](https://github.com/bilalcaliskan/nginx-conf-generator)
[](https://github.com/pre-commit/pre-commit)
[](https://opensource.org/licenses/Apache-2.0)
That tool uses [client-go](https://github.com/kubernetes/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:
> ```shell
> $ 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](https://github.com/bilalcaliskan/nginx-conf-generator/releases) page.
After then, you can simply run binary by providing required command line arguments:
```shell
$ ./nginx-conf-generator --kubeconfig-paths=~/.kube/config1,~/.kube/config2 --custom-annotation nginx-conf-generator/enabled
```
### Homebrew
This project can be installed with [Homebrew](https://brew.sh/):
```
brew tap bilalcaliskan/tap
brew install bilalcaliskan/tap/nginx-conf-generator
```
## Development
This project requires below tools while developing:
- [Golang 1.20](https://golang.org/doc/go1.20)
- [pre-commit](https://pre-commit.com/)
- [golangci-lint](https://golangci-lint.run/usage/install/) - required by [pre-commit](https://pre-commit.com/)
- [gocyclo](https://github.com/fzipp/gocyclo) - required by [pre-commit](https://pre-commit.com/)
After you installed [pre-commit](https://pre-commit.com/), simply run below command to prepare your development environment:
```shell
$ pre-commit install -c build/ci/.pre-commit-config.yaml
```
## License
Apache License 2.0