kgrep is a command-line utility designed to simplify the process of searching and analyzing logs and resources in Kubernetes. Unlike traditional methods that involve printing resource definitions and grepping through them, kgrep allows you to search across multiple logs or resources simultaneously, making it easier to find what you need quickly.
- Why kgrep?
- Key Features
- Installation
- Usage
- Building the Project
- Running the Application in Dev Mode
- Building the Application
- Installing the Application
- Cross-compiling for Different Platforms
- Creating Releases
- Version Information
- Makefile Targets
- Contributing
- License
- Contact
Searching Kubernetes resources and logs with kubectl and grep can be tedious and error-prone, especially across multiple namespaces or resource types. kgrep streamlines this process by providing a single, powerful CLI for searching logs and resources, supporting pattern matching, namespace selection, and more. This saves time and reduces the risk of missing important information.
- Resource Searching: Search the content of Kubernetes resources such as
ConfigMaps,Secrets,Pods, andServiceAccountsfor specific patterns within designated namespaces. - Log Searching: Inspect logs from a group of pods or entire namespaces, filtering by custom patterns to locate relevant entries.
- Namespace Specification: Every search command supports namespace specification, allowing users to focus their queries on particular sections of their Kubernetes cluster.
- Pattern-based Filtering: Utilize pattern matching to refine search results, ensuring that only the most pertinent data is returned.
- kubectl installed and configured to connect to your Kubernetes cluster.
- Go 1.24+ (for building from source)
Install kgrep using Homebrew:
brew tap kgrep-org/kgrep
brew install kgrepOr install directly without adding the tap:
brew install kgrep-org/kgrep/kgrepFor more information about the Homebrew tap, visit homebrew-kgrep.
Download a release from https://github.com/hbelmiro/kgrep/releases, uncompress it, and add it to your PATH.
⚠️ Unverified app warning on macOS
You can see this warning when trying to run kgrep for the first time on macOS.
"kgrep" Not Opened
Apple could not verify "kgrep" is free of malware that may harm your Mac or compromise your privacy.
If you see that, click "Done" and allow kgrep to run in macOS settings, like the following screenshot.
When you try to run it again, you'll see a final warning. Just click "Open Anyway" and it won't warn you anymore.
Type kgrep --help to check all the commands and options.
kgrep configmaps -n my_namespace -p "example"kgrep secrets -p "password"kgrep logs -n my-namespace -p "error"kgrep serviceaccounts -n my-namespace -p "my-service-account"kgrep resources --kind Deployment --pattern "replicas: 3" --namespace my-namespaceconfigmaps/example-config-4khgb5fg64[7]: internal.config.kubernetes.io/previousNames: "example-config-4khgb5fg64"
configmaps/example-config-4khgb5fg64[48]: name: "example-config-4khgb5fg64"
configmaps/example-config-5fmk4f7h8k[7]: internal.config.kubernetes.io/previousNames: "example-config-5fmk4f7h8k"
configmaps/example-config-5fmk4f7h8k[57]: name: "example-config-5fmk4f7h8k"
configmaps/acme-manager-config[104]: \ frameworks:\n - "batch/job"\n - "example.org/mpijob"\n - "acme.io/acmejob"\
configmaps/acme-manager-config[105]: \n - "acme.io/acmecluster"\n - "jobset.x-k8s.io/jobset"\n - "example.org/mxjob"\
configmaps/acme-manager-config[106]: \n - "example.org/paddlejob"\n - "example.org/acmejob"\n - "example.org/tfjob"\
configmaps/acme-manager-config[107]: \n - "example.org/xgboostjob"\n# - "pod"\n externalFrameworks:\n
This project is written in Go and uses the Cobra library for CLI commands.
You can run the application in development mode using:
go run main.goYou can build the application using:
go build -o kgrepThis will produce a kgrep executable in the current directory.
You can install the application to your GOPATH using:
go installGo makes it easy to cross-compile for different platforms:
For Linux:
GOOS=linux GOARCH=amd64 go build -o kgrep-linux-amd64For macOS:
GOOS=darwin GOARCH=amd64 go build -o kgrep-darwin-amd64For Windows:
GOOS=windows GOARCH=amd64 go build -o kgrep-windows-amd64.exeThis project uses a tag-based release system that automatically builds and publishes binaries when you push a Git tag.
- Make sure you have the latest changes committed
- Ensure all tests pass:
go test ./...
-
Create a release tag and build:
./scripts/release.sh create 1.0.0
This will:
- Run all tests
- Create a Git tag (e.g.,
v1.0.0) - Build the release binary with version information
- Show you the next steps
-
Push the tag to trigger the GitHub Actions release:
git push origin v1.0.0
-
GitHub Actions will automatically:
- Build binaries for Linux and macOS (amd64/arm64)
- Create a GitHub release
- Upload the binaries to the release
If you need to rebuild a release for an existing tag:
# Build for the latest tag
./scripts/release.sh latest
# Build for a specific tag
./scripts/release.sh build v1.0.0For development builds:
# Development build with "dev" version
make build-dev
# Or using the Makefile
go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=dev ..." -o kgrep# Show all available commands
./scripts/release.sh help
# List all available tags
./scripts/release.sh list
# Clean build artifacts
./scripts/release.sh cleanThe built binaries include version information that can be displayed with:
./kgrep versionThis shows:
- Version number (from Git tag or "dev" for development builds)
- Build timestamp
- Git commit hash
You can also use Makefile targets for building and release automation:
# Development build
make build-dev
# Build for latest tag
make build-tag
# Build for specific tag
make build-tag-version TAG=v1.0.0
# Create new tag and build
make tag-and-build VERSION=1.0.0
# List available tags
make list-tags
# Clean build artifacts
make clean
# Run unit tests
make test
# Run integration tests (requires kubectl access)
make test-integration
# Run integration tests with kind (creates local cluster)
make test-integration-kindThis project includes both unit tests and integration tests:
Unit tests use mocked Kubernetes clients and can be run without a real cluster:
# Run unit tests
make test
# Or directly with go
go test ./...Integration tests require a real Kubernetes cluster and test end-to-end scenarios:
# Run integration tests with your current kubectl context
make test-integration
# Run integration tests with a temporary kind cluster (recommended)
make test-integration-kindFor more details about integration tests, see test/integration/README.md.
Contributions are welcome! To get started:
- Fork this repository and clone your fork.
- Create a new branch for your feature or bugfix.
- Make your changes and add tests if applicable.
- Open a pull request describing your changes.
Please ensure your code follows the existing style and passes all tests:
# Run unit tests
make test
# Run integration tests (optional but recommended)
make test-integration-kindThis project is licensed under the Apache 2.0 License.
- Issues and feature requests: GitHub Issues
- Maintainer: @hbelmiro


