Giter Club home page Giter Club logo

kubectl-vpa-recommendation's Introduction

kubectl vpa-recommendation

A kubectl plugin to show the differences between the recommendations of a VerticalPodAutoscaler and the actual resources requests of the targeted controller's pod(s).

The plugin is compatible with Kubernetes servers starting from version 1.16, which have the autoscaling.k8s.io/v1 API group installed. See the other prerequisites for using VPAs on your cluster.

Installation

With Krew

Follow these instructions to install krew. Then run the following commands:

$ kubectl krew install vpa-recommendation
$ kubectl vpa-recommendation --help

Manual download

Head to the releases page to download an existing release for your OS/arch, and add the path to the binary to your $PATH.

Build from source

โš ๏ธ The plugin requires Go 1.17+ to build.

To build the plugin yourself from the source, use the following commands:

$ git clone [email protected]:wI2L/kubectl-vpa-recommendation.git
$ cd kubectl-vpa-recommendation
$ make build

It creates a single binary file for the host machine platform/architecture in the dist/ folder. Move it somewhere within your $PATH, such as $GOPATH/bin. You can then invoke it directly (kubectl-vpa-recommendation), or via kubectl (kubectl vpa-recommendation).

Usage

How to interpret the output?

The columns % CPU DIFF and % MEMORY DIFF represents the percentage of increase/decrease for the request in terms of the recommendation.

For example, if a request value is set to 4 CPU (4000m), and the recommendation is only 1 CPU (1000m), the difference printed is +300%. On the contrary, if the request (125m) is lower than the recommendation (250m), the difference is then -50%. As a rule of thumb, you can think of positive values as over commitment and negative values as under commitment.

Demo

The following examples were produced from a brand-new Kubernetes cluster created with k3d. The VerticalPodAutoscaler resources were automatically created by the goldilocks operator.

Single namespace

example1

Wide output (all namespaces)

example2

Options

Apart from the flags defined by the genericclioptions package and some logging flags, the following options are available with the plugin:

  • --all-namespaces, -A: List VerticalPodAutoscaler resources in all namespaces
  • --critical-threshold: Critical threshold of percentage difference for colored output. Default to 50
  • --namespace, -n: If present, the namespace scope for the request
  • --no-colors: Do not use colors to highlight increase/decrease percentage values
  • --no-headers: Do not print table headers
  • --output, -o: Output format. One of: wide | split | split-wide
  • --recommendation-type: The type of recommendation to use in comparisons. One of: lower-bound, target, uncapped-target, upper-bound. Default to target
  • --show-containers, -c: Display containers recommendations for each VerticalPodAutoscaler resource
  • --show-kind, -k: Show the resource type for the requested object(s) and their target
  • --show-namespace: Show resource namespace as the first column
  • --sort-columns: Comma-separated list of column names for sorting the table. Any of: cpu-diff | cpu-rec | cpu-req | mem-diff | mem-rec | mem-req | name | namespace | target. Default to namespace,name
  • --sort-order: The sort order of the table columns. Either asc or desc. Default to asc
  • --warning-threshold: Warning threshold of percentage difference for colored output. Default to 20

To view the full list of available options, use the following command:

$ kubectl vpa-recommendation --help

Limitations

  • Unlike the official VPA recommender, which is fully generic and handle any kind of "scalable" resources, the plugin recognize only some well-known controllers such as: CronJob, DaemonSet, Deployment, Job, ReplicaSet, ReplicationController, StatefulSet.

License

This plugin is licensed under the MIT license. See the LICENSE file.

kubectl-vpa-recommendation's People

Contributors

sidick avatar wi2l avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

erayan slamp mr-leiy

kubectl-vpa-recommendation's Issues

Division by zero in v0.6.0

Running:
kubectl vpa-recommendation --show-stats --output wide --sort-columns mem-diff,cpu-diff

I get the following error:

NAME   MODE   TARGET   CPU REQUEST   CPU TARGET   % CPU DIFF   MEMORY REQUEST   MEMORY TARGET   % MEMORY DIFF

panic: division by zero

goroutine 1 [running]:
math/big.nat.div({0x0?, 0x1?, 0x0?}, {0x0?, 0x0?, 0xc00012f0d8?}, {0x0?, 0xc000708450?, 0x1000000000001?}, {0x0, ...})
        /opt/hostedtoolcache/go/1.19.2/x64/src/math/big/natdiv.go:507 +0x34b
math/big.(*Int).Quo(0xc0005c7410, 0xc0005c73b0, 0xc0005c73e0)
        /opt/hostedtoolcache/go/1.19.2/x64/src/math/big/int.go:211 +0x78
gopkg.in/inf%2ev0.(*Dec).quoRem(0xc0005c7410, 0xc0005c73b0, 0xc0005c73e0, 0x0, 0x0, 0x0, 0x0)
        /home/runner/go/pkg/mod/gopkg.in/[email protected]/dec.go:331 +0x654
gopkg.in/inf%2ev0.(*Dec).quo(0xc000422c80?, 0x0?, 0x28?, {0x1b350e0?, 0x269f140?}, {0x1b3bbf8, 0xc0000b3610})
        /home/runner/go/pkg/mod/gopkg.in/[email protected]/dec.go:267 +0x14b
gopkg.in/inf%2ev0.(*Dec).QuoRound(...)
        /home/runner/go/pkg/mod/gopkg.in/[email protected]/dec.go:257
github.com/wI2L/kubectl-vpa-recommendation/cli.table.meanQuantities({0x0?, 0x0, 0x176d820?}, 0xc0005c7201?)
        /home/runner/work/kubectl-vpa-recommendation/kubectl-vpa-recommendation/cli/table.go:299 +0xc5
github.com/wI2L/kubectl-vpa-recommendation/cli.table.printStats({0x0?, 0x0, 0x0}, {0x1b33fc0?, 0xc000012018?})
        /home/runner/work/kubectl-vpa-recommendation/kubectl-vpa-recommendation/cli/table.go:243 +0x604
github.com/wI2L/kubectl-vpa-recommendation/cli.table.Print({0x0, 0x0, 0x0}, {0x1b33fc0, 0xc000012018}, 0xc0001f0360)
        /home/runner/work/kubectl-vpa-recommendation/kubectl-vpa-recommendation/cli/table.go:200 +0x618
github.com/wI2L/kubectl-vpa-recommendation/cli.(*CommandOptions).Execute(0xc000424000)
        /home/runner/work/kubectl-vpa-recommendation/kubectl-vpa-recommendation/cli/command.go:204 +0x66b
github.com/wI2L/kubectl-vpa-recommendation/cli.(*CommandOptions).Run(0x128aee0?, 0xc0000f9c00?, {0xc0003fc5b0, 0x0, 0x7})
        /home/runner/work/kubectl-vpa-recommendation/kubectl-vpa-recommendation/cli/command.go:103 +0x7b
github.com/spf13/cobra.(*Command).execute(0xc000357400, {0xc00003e090, 0x7, 0x7})
        /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:860 +0x663
github.com/spf13/cobra.(*Command).ExecuteC(0xc000357400)
        /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:974 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:902
k8s.io/component-base/cli.run(0xc000357400)
        /home/runner/go/pkg/mod/k8s.io/[email protected]/cli/run.go:146 +0x317
k8s.io/component-base/cli.Run(0xc0000e7d00?)
        /home/runner/go/pkg/mod/k8s.io/[email protected]/cli/run.go:46 +0x1d
main.main()
        /home/runner/work/kubectl-vpa-recommendation/kubectl-vpa-recommendation/cmd/kubectl-vpa-recommendation/kubectl-vpa-recommendation.go:44 +0x145

It seems like
meanQuantities chokes on some of our vpa's recommandations. I have dumped the vpas to yaml but there is a ton of internal info in those, so I'm not sure if I can share those.

Most of them have one container with something like this:

- containerName: webservices
  lowerBound:
    cpu: 15m
    memory: "248036781"
  target:
    cpu: 15m
    memory: "272061154"
  uncappedTarget:
    cpu: 15m
    memory: "272061154"
  upperBound:
    cpu: 15m
    memory: "336054630"

and a couple will have two containers.

EDIT: Alright kubectl vpa-recommendation doesn't actually return any VPAs. All our VPAs target a custom CRD, might that be the issue? Seems like it doesn't realize the number of matched VPAs is actually 0 because they are all targeting some unsupported kind.

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.