A kubectl
plugin for creating LimitRange
resources with specified CPU and memory limits in Kubernetes namespaces.
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.
- Create
LimitRange
resources with configurable CPU and memory limits. - Supports dry-run modes (
client
andserver
) to preview the resource without applying it. - Outputs resource definitions in YAML or JSON format.
- Easy to use with intuitive command flags.
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/
go test ./pkg/cmd/... -v
kubectl limitrange my-limitrange --namespace=my-namespace --max-cpu="1" --min-cpu=100m --max-memory=500Mi --min-memory=100Mi
kubectl limitrange my-limitrange --namespace=my-namespace --max-cpu="2" --dry-run=client -o yaml
kubectl limitrange my-limitrange --namespace=my-namespace --max-cpu="1" --dry-run=server -o json
kubectl limitrange my-limitrange --namespace=my-namespace --max-cpu="1" --min-cpu=100m --max-memory=500Mi --min-memory=100Mi
--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 thelimitrange
resource (shorthand for--namespace
).--dry-run
: Dry-run mode (client
orserver
).-o, --output
: Output format (yaml
orjson
).
-
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
- Go 1.23 or later.
kubectl
configured on your system.
Feel free to contribute by submitting issues or pull requests. Any help to enhance the functionality or add new features is welcome!