Skip to main content

Update host:port in YAML service URLs by service name and Kubernetes cluster

Project description

Service-Lookup Utility

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.

Table of Contents

Features

  • 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.

Example

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.

Requirements

  • Python 3.12 or later
  • kubectl installed and configured
  • Access to a Kubernetes cluster

For Local Build

Installation from PyPI

pip install service-lookup

Add to PATH

In 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.

Installation From Repository

  1. Clone the Repository:

    git clone https://github.com/iByteABit256/service-lookup.git
    cd service-lookup
    
  2. Install Dependencies:

    uv sync
    
  3. Add to pip modules (Optional)

    pip install .
    
  4. Ensure kubectl is Installed: Make sure you have kubectl installed and configured to access your Kubernetes cluster. You should either have a .kubeconfig file or run the setup command if you're using Lens.

Usage

To use the utility, run the main script with the desired options:

Basic Command

service-lookup --root /path/to/root --namespace your-namespace --services service1,service2 --exclude path/to/exclude,another/path/to/exclude

Setup Environment from Kubernetes Lens

To 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-lens

With Mappings

If 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

Options

  • -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.
  • -k, --kubeconfig: Specify kubeconfig file path.
  • -c, --cluster: Specify Kubernetes cluster, otherwise first matching namespace from any cluster will be used when using the --use-lens option.
  • -l, --use-lens: Use kubeconfigs from Lens.
  • -t, --request-timeout: The length of time to wait before giving up on a single server request, default is 10s.

Configuration

Service Mappings

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.

Exclusion Paths

Use the --exclude option to specify paths in the root directory that should be excluded from updates.

Contributing

All contributions are welcome! To contribute:

  1. Fork the repository on GitHub.
  2. Create a new branch for your feature or fix.
  3. Commit your changes and push your branch to GitHub.
  4. Submit a pull request for review.

License

This project is licensed under the GNU GPL-3.0 License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

service_lookup-0.2.8.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

service_lookup-0.2.8-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file service_lookup-0.2.8.tar.gz.

File metadata

  • Download URL: service_lookup-0.2.8.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for service_lookup-0.2.8.tar.gz
Algorithm Hash digest
SHA256 b6b4b7c66c4f054e50c7791a2a1447698d67d98b889abd02be8f4d2b09fbe95d
MD5 873b1c164f7f911ef5386b5ef95ab124
BLAKE2b-256 af4d086aa34698774fe004bb5f9cdae2610752da05804770dac00dbdeab85e51

See more details on using hashes here.

File details

Details for the file service_lookup-0.2.8-py3-none-any.whl.

File metadata

File hashes

Hashes for service_lookup-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c60efdf071e0245f2509de296c6822572399fd3da850f7f60e6b06d45da0eb39
MD5 baaaa244bc0b265e16a612941e41cc1e
BLAKE2b-256 9cae09a18f7b0f50dd4309d1ccbc65536cbeb2260f5957fb17ca9ec764b7f577

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page