https://github.com/jsenon/api-cni-cleanup
Kubernetes CNI cleanner
https://github.com/jsenon/api-cni-cleanup
cleanner cni k8s kubernetes
Last synced: 11 months ago
JSON representation
Kubernetes CNI cleanner
- Host: GitHub
- URL: https://github.com/jsenon/api-cni-cleanup
- Owner: jsenon
- License: apache-2.0
- Created: 2018-09-07T17:32:24.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-01T09:24:50.000Z (almost 7 years ago)
- Last Synced: 2024-11-18T02:47:54.906Z (over 1 year ago)
- Topics: cleanner, cni, k8s, kubernetes
- Language: Go
- Homepage:
- Size: 4.92 MB
- Stars: 28
- Watchers: 3
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# CNI Cleaner API
[](https://circleci.com/gh/jsenon/api-cni-cleanup)
[](https://goreportcard.com/report/github.com/jsenon/api-cni-cleanup)
## Func
- Remove unecessary cni file on kubernetes nodes (Running Pod/Orphaned Pod)
- Exports CNI file number in Prometheus endpoint
- Use Opencensus for tracing and metrics support
### Prerequisite
This application must run inside kubernetes cluster.
It's recommended to run it must on Daemonset in order to access to all nodes where the cni files are located.
### Deployment
Deployment on Kubernetes cluster:
```sh
kubectl apply -f k8s/deployment.yml
```
We will deploy:
- RBAC Compatibility
- Cronjob to launch cleanup each Monday
- Service
- Daemonset
### Usage
```sh
CNI File Cleanner and Monitoring
Usage:
api-cni-cleanup [command]
Available Commands:
clean Launch CNI Cleanner
help Help about any command
job Job Cleanner
server Launch CNI Cleanner Server
Flags:
--api string External or Internal K8S cluster (default "internal")
--cnifiles string Set CNI Folder (default "/var/lib/cni")
--config string config file (default is $HOME/.api-cni-cleanup.yaml)
--debug Set log level to Debug
-h, --help help for api-cni-cleanup
--jaegerurl string Set jaegger collector endpoint
Use "api-cni-cleanup [command] --help" for more information about a command.
```
### Run Server Mode
When you launch application in server mode you will have prometheus metrics:
```sh
api-cni-cleanup server --api APITYPE --cnifiles YOURCNIFOLDER
```
Prometheus metrics are available on:
- [http://localhost:9010/metrics](http://localhost:9010/metrics)
Stats are:
```text
# HELP apicnicleanup_number_count number of files
# TYPE apicnicleanup_number_count gauge
apicnicleanup_number_count XX
# HELP apicnicleanup_size_bytes Size of the folder
# TYPE apicnicleanup_size_bytes gauge
apicnicleanup_size_bytes XX
```
Api entrypoint to launch the cleaning is:
- [http://localhost:9010/cleanup](http://localhost:9010/cleanup)
### Run Job Mode
In order to schedule the cleaning with a cronjob you can launch application in job mode:
Contact API CNI Cleanner:
```sh
api-cni-cleanup job --urlserver http://127.0.0.1:9010/cleanup,http://192.168.0.2:9010/cleanup
```
For automatic discovery, actually based on daemonset name and port:
```sh
api-cni-cleanup job --autodiscover
```
Just specify all you `urlserver` that's represent all you api-cni-cleanup servers
### (OPTIONAL) Run Batch Mode
This application could be launch on demand. But you need to know where your pod is deployed in order to clean cni file on a targeted node.
Batch Mode cleaning:
```sh
api-cni-cleanup clean --api APITYPE --cnifiles YOURCNIFOLDER
```
### TIPS
Vendoring [constraint](https://github.com/kubernetes/minikube/issues/3037#issuecomment-418384405)
### TODO
- [x] Create New Metric on Prometheus = Count files + Folder Size
- [x] Diff IP files and API PodIP
- [x] Remove files unused
- [x] Api to launch cleanup
- [x] k8s deployment: DaemonSet + svc + Cronjob
- [ ] Redefine api entrypoint with naming convention