A Python-based tool for updating YAML configuration files with dynamic host and port information from Kubernetes clusters. This utility is designed to streamline service discovery and configuration management in microservice environments.
- Dynamic Service Discovery: Automatically discover services running in a Kubernetes cluster and update your YAML configuration files accordingly.
- Port Forwarding: Port forward Kubernetes services to your local machine for development and testing purposes.
- Custom Mappings: Use custom mappings to handle services with different names locally and in Kubernetes.
- Exclusion of Files: Specify paths to exclude from YAML updates.
- Setup from Lens Utility: Configure your environment with a simple setup command if using Lens.
service-lookup --root . --namespace dev --services service1,service2 --use-lens --exclude ./target
Port-forwarding service service1 from target port 8080 to local port 24836
Port-forwarding service service2 from target port 8080 to local port 24837
✅ Updated: .\service1\service1-adapter\src\main\resources\application-service1-adapter.yml
✅ Updated: .\service2\service2-adapter\src\main\resources\application-service2-adapter.yml
Press 'ctrl+q' to clean ports and exit.
✅ Process 3740 terminated.
✅ Process 30260 terminated.
✅ Process 31400 terminated.- Python 3.12 or later
kubectlinstalled and configured- Access to a Kubernetes cluster
pip install service-lookupIn order to be able to call service-lookup directly from any directory, you must add the Python scripts directory to your PATH environment variable.
The default location for Windows is <User_Directory>/AppData/Local/Programs/Python/<Python_Version>/Scripts.
-
Clone the Repository:
git clone https://github.com/iByteABit256/service-lookup.git cd service-lookup -
Install Dependencies:
uv sync
-
Add to pip modules (Optional)
pip install . -
Ensure
kubectlis Installed: Make sure you havekubectlinstalled and configured to access your Kubernetes cluster. You should either have a.kubeconfigfile or run the setup command if you're using Lens.
To use the utility, run the main script with the desired options:
service-lookup --root /path/to/root --namespace your-namespace --services service1,service2 --exclude path/to/exclude,another/path/to/excludeTo set up your environment based on your Lens configuration, use the --use-lens parameter:
service-lookup --root /path/to/root --namespace your-namespace --services service1,service2 --exclude path/to/exclude,another/path/to/exclude --use-lensIf you have predefined mappings:
service-lookup --root /path/to/root --map service1=localhost:8080,service2=localhost:8081 --exclude path/to/exclude,another/path/to/exclude-r,--root: Root directory to search YAML files.-e,--exclude: Comma-separated list of paths to exclude.-m,--map: Comma-separated service=host:port pairs.-n,--namespace: Kubernetes namespace to discover services.-s,--services: Comma-separated list of service names to port forward. Default value is '*' which means every service in the mapping file.-f,--mapping-file: Path to JSON file with service_name -> kubernetes_service_name mappings.-l,--use-lens: Use kubeconfigs from Lens.
Create a service_mappings.json file to map local service names to Kubernetes service names:
{
"local-service-a-name": "kubernetes-service-a-name",
"local-service-b-name": "kubernetes-service-b-name"
}Running without the --services option searches for every service in the mappings file above.
Use the --exclude option to specify paths in the root directory that should be excluded from updates.
All contributions are welcome! To contribute:
- Fork the repository on GitHub.
- Create a new branch for your feature or fix.
- Commit your changes and push your branch to GitHub.
- Submit a pull request for review.
This project is licensed under the GNU GPL-3.0 License. See the LICENSE file for more details.