Skip to content

ahmedTouati/kubectl-regex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kubectl-regex

This repository implements a kubectl plugin for get/delete kubernetes resources by regex patterns.

Features

🔍 Get resources by regex (Pods, Deployments, Services, ConfigMaps, CRDs, …)

🗑 Delete resources by regex with confirmation

🏷 Works with any resource supported by your cluster’s API

🌐 Supports --namespace, -n, --context, --kubeconfig, --all-namespaces like native kubectl

⚡ Powered by Go’s RE2 regex engine (safe, no catastrophic backtracking)

💡 Tired of long shell pipelines just to clean up resources?

Instead of typing something like to delete all pods that contain "app" in current namespace:

kubectl get pods | grep "app" | awk '{print $1}' | xargs kubectl delete pods

You can simply run:

kubectl regex delete pods "app"

Install (local build)

git clone https://github.com/ahmedTouati/kubectl-regex.git
cd kubectl-regex
go build -o kubectl-regex cmd/kubectl-regex.go
mv kubectl-regex /usr/local/bin/

Check plugin discovery:

kubectl plugin list

🚀 Usage

Get resources

# Get pods starting with "nginx-"
kubectl regex get pods "^nginx-"

# Get services ending with "-svc"
kubectl regex get services ".*-svc"

# Get deployments containing "web" in namespace "foo"
kubectl regex get deployments "web" -n "foo"

Delete resources

# Delete all configmaps containing "app" in namespace foo
kubectl regex delete configmaps "app" -n foo

# Delete all deployments whose names start with "test-" in the default namespace, without asking for confirmation (use with caution)
kubectl regex delete deployments "^test-" --yes

All namespaces

kubectl regex get pods "nginx" -A

⚙️ Regex syntax

Uses Go’s built-in regexp

📄 License

Apache 2.0 License.

About

A kubectl plugin to help you filter kuberentes resources using Regular Expressions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages