A Kubernetes-native URL shortener service using custom resources and an operator pattern.
This application consists of several components:
- Custom Resource Definition (CRD): Defines the
ShortURLresource type - Operator: Manages
ShortURLcustom resources - API Service: Provides HTTP endpoints for creating and accessing shortened URLs
The ShortURL custom resource allows you to define URLs to be shortened:
apiVersion: urlshortener.tapsi.ir/v1
kind: ShortURL
metadata:
name: example-url
spec:
targetURL: "https://example.com/very/long/path/to/shorten"The operator will process this resource and update its status with the shortened path and click tracking:
status:
shortPath: "abc123"
clickCount: 42The URL shortener operator:
- Watches for
ShortURLresources - Generates short codes
- Maintains the mapping between short codes and target URLs
- Updates resource status with metrics
The API service provides:
- Endpoints for creating new shortened URLs
- Redirection from short URLs to their targets
- Click tracking and metrics
- Kubernetes 1.19+
- Helm 3.2.0+
- Ingress controller (such as nginx-ingress)
- Container registry access for the application images
-
Clone the repository:
git clone https://github.com/dibaro/url-shortener.git cd url-shortener/releases/url-shortener -
Install using helmfile:
helmfile apply
This will install all components defined in the helmfile.yaml.