Code Monkey home page Code Monkey logo

kor's Introduction

GitHub go.mod Go version (subdirectory of monorepo) GitHub release (with filter)

Kor - Kubernetes Orphaned Resources Finder

Kor is a tool to discover unused Kubernetes resources. Currently, Kor can identify and list unused:

  • ConfigMaps
  • Secrets.
  • Services
  • ServiceAccounts
  • Deployments
  • Statefulsets
  • Roles
  • Hpas
  • Pvcs
  • Ingresses
  • Pdbs

Kor Screenshot

Installation

Download the binary for your operating system from the releases page and add it to your system's PATH.

For MacOS users, you can install Kor using Homebrew:

brew install kor

Usage

Kor provides various subcommands to identify and list unused resources. The available commands are:

  • all: Gets all unused resources for the specified namespace or all namespaces.
  • configmap: Gets unused configmaps for the specified namespace or all namespaces.
  • secret: Gets unused secrets for the specified namespace or all namespaces.
  • services: Gets unused services for the specified namespace or all namespaces.
  • serviceaccount: Gets unused service accounts for the specified namespace or all namespaces.
  • deployments: Gets unused service accounts for the specified namespace or all namespaces.
  • statefulsets: Gets unused service accounts for the specified namespace or all namespaces.
  • role: Gets unused roles for the specified namespace or all namespaces.
  • hps: Gets unused hpa for the specified namespace or all namespaces.
  • pvc: Gets unused pvcs for the specified namespace or all namespaces.
  • ingress: Gets unused ingresses for the specified namespace or all namespaces.
  • pdb: Gets unused pdbs for the specified namespace or all namespaces.

Supported Flags

-h, --help                help for role
-k, --kubeconfig string   Path to kubeconfig file (optional)
-n, --namespace string    Namespace to run on
--output string       Output format (table or json) (default "table")

To use a specific subcommand, run kor [subcommand] [flags].

kor all --namespace my-namespace

For more information about each subcommand and its available flags, you can use the --help flag.

kor [subcommand] --help

Supported resources and limitations

Resource What it looks for Known False Positives โš ๏ธ
Configmaps Configmaps not used in the following places:
- Pods
- Containers
- Configmaps used through volumes
- Configmaps used through environment variables
Configmaps used by resources which don't explicitly state them in the config.
e.g Grafana dashboards loaded dynamically opa policies fluentd configs
Secrets Secrets not used in the following places:
- Pods
- Containers
- Secrets used through volumes
- Secrets used through environment variables
- Secrets used by ingress TLS
-Secrets used by ServiceAccounts
Secrets used by resources which don't explicitly state them in the config
Services Services with no endpoints
Deployments Deployments with 0 Replicas
ServiceAccounts ServiceAccounts unused by pods
ServiceAccounts unused by roleBinding or clusterRoleBinding
Statefulsets Statefulsets with 0 Replicas
Roles Roles not used in roleBinding
Pvcs Pvcs not used in pods
Ingresses Ingresses not pointing at any service.
Hpas Hpas not used in Deployments
Hpas not used in Statefulsets
Pdbs Pdbs not used in Deployments
Pdbs not used in Statefulsets

Import Option

You can also use kor as a Go library to programmatically discover unused resources. By importing the github.com/yonahd/kor/pkg/kor package, you can call the relevant functions to retrieve unused resources. The library provides the option to get the results in JSON format by specifying the outputFormat parameter.

import (
"github.com/yonahd/kor/pkg/kor"
)

func main() {
namespace := "my-namespace"
outputFormat := "json" // Set to "json" for JSON output

    if outputFormat == "json" {
        jsonResponse, err := kor.GetUnusedDeploymentsJSON(namespace, kubeconfig)
        if err != nil {
            // Handle error
        }
        // Process the JSON response
        // ...
    } else {
        kor.GetUnusedDeployments(namespace)
    }
}

Contributing

Contributions are welcome! If you encounter any bugs or have suggestions for improvements, please open an issue in the issue tracker.

License

This project is open-source and available under the MIT License. Feel free to use, modify, and distribute it as per the terms of the license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.