Skip to content

Kubernetes LimitRange CLI Plugin - A kubectl extension to create LimitRange resources with configurable CPU and memory constraints. Supports dry-run modes and outputs in YAML/JSON for easy validation.

License

Notifications You must be signed in to change notification settings

mfenerich/kubectl-lr

Repository files navigation

codecov Go CI/CD Pipeline Go Report Card

Kubernetes LimitRange CLI Plugin

A kubectl plugin for creating LimitRange resources with specified CPU and memory limits in Kubernetes namespaces.

Overview

This plugin provides a command-line interface for easily creating LimitRange resources in your Kubernetes cluster. It supports both client-side and server-side dry runs and outputs in YAML or JSON formats for previewing the resource before creation.

Features

  • Create LimitRange resources with configurable CPU and memory limits.
  • Supports dry-run modes (client and server) to preview the resource without applying it.
  • Outputs resource definitions in YAML or JSON format.
  • Easy to use with intuitive command flags.

Installation

Ensure you have Go installed and kubectl configured on your system. Clone this repository and run:

go build cmd/kubectl-lr/kubectl-limitrange.go

Move the binary to a directory in your PATH:

mv kubectl-limitrange /usr/local/bin/

Run tests

go test ./pkg/cmd/... -v

Usage

Basic Example

kubectl limitrange my-limitrange --namespace=my-namespace --max-cpu="1" --min-cpu=100m --max-memory=500Mi --min-memory=100Mi

Client-Side Dry Run

kubectl limitrange my-limitrange --namespace=my-namespace --max-cpu="2" --dry-run=client -o yaml

Client-Side Dry Run

Server-Side Dry Run

kubectl limitrange my-limitrange --namespace=my-namespace --max-cpu="1" --dry-run=server -o json

Server-Side Dry Run

No Dry Run Example

kubectl limitrange my-limitrange --namespace=my-namespace --max-cpu="1" --min-cpu=100m --max-memory=500Mi --min-memory=100Mi

No Dry Run

Command Flags

  • --max-cpu: Maximum CPU limit for containers.
  • --min-cpu: Minimum CPU limit for containers.
  • --default-cpu: Default CPU limit for containers.
  • --default-request-cpu: Default CPU request for containers.
  • --max-memory: Maximum memory limit for containers.
  • --min-memory: Minimum memory limit for containers.
  • -n, --namespace: Namespace for the limitrange resource (shorthand for --namespace).
  • --dry-run: Dry-run mode (client or server).
  • -o, --output: Output format (yaml or json).

Example Commands

  • Create a limitrange with CPU and memory limits:

    kubectl limitrange my-limitrange --namespace=my-namespace --max-cpu="1" --min-cpu=100m --max-memory=500Mi --min-memory=100Mi
  • Client-side dry-run:

    kubectl limitrange my-limitrange --namespace=my-namespace --max-cpu="2" --min-cpu=500m --dry-run=client -o yaml
  • Server-side dry-run:

    kubectl limitrange my-limitrange --namespace=my-namespace --default-cpu=500m --default-request-cpu=200m --dry-run=server -o json

Requirements

  • Go 1.23 or later.
  • kubectl configured on your system.

Contributing

Feel free to contribute by submitting issues or pull requests. Any help to enhance the functionality or add new features is welcome!

About

Kubernetes LimitRange CLI Plugin - A kubectl extension to create LimitRange resources with configurable CPU and memory constraints. Supports dry-run modes and outputs in YAML/JSON for easy validation.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published