Skip to content

Commit a2ff767

Browse files
committed
Add Kubernetes deployment manifests: include deployment, service, and HTTP route configurations for TSFlow. Update README for Docker and Kubernetes deployment instructions, enhancing clarity and usability.
1 parent 88be2dc commit a2ff767

File tree

6 files changed

+259
-56
lines changed

6 files changed

+259
-56
lines changed

README.md

Lines changed: 170 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ TSFlow uses a **Go backend + React frontend** architecture for optimal performan
6161
- **Tailscale API key** with appropriate permissions
6262
- **Docker** (recommended) or Go 1.21+ and Node.js 18+
6363

64-
### Option 1: Using Docker (Recommended)
64+
### Using Docker Compose (Fastest)
6565

66-
The fastest way to get started:
66+
The quickest way to get started:
6767

6868
```bash
6969
# Create environment file
@@ -79,74 +79,40 @@ docker-compose logs -f tsflow
7979

8080
Then navigate to `http://localhost:8080` to start exploring your network!
8181

82-
### Option 2: Development Setup
82+
## Deployment Options
8383

84-
1. **Clone the repository**
85-
```bash
86-
git clone https://github.com/rajsinghtech/tsflow.git
87-
cd tsflow
88-
```
89-
90-
2. **Configure environment**
91-
```bash
92-
cp env.example .env
93-
```
94-
95-
Edit `.env` and add your Tailscale credentials:
96-
```env
97-
TAILSCALE_API_KEY=tskey-api-your-api-key-here
98-
TAILSCALE_TAILNET=your-tailnet-name
99-
PORT=8080
100-
ENVIRONMENT=development
101-
```
102-
103-
3. **Build the frontend**
104-
```bash
105-
cd frontend
106-
npm install
107-
npm run build
108-
cd ..
109-
```
84+
### 🐳 Docker Deployment
11085

111-
4. **Run the backend**
112-
```bash
113-
cd backend
114-
go mod download
115-
go run main.go
116-
```
86+
#### Using Pre-built Images from GHCR
11787

118-
5. **Open your browser**
119-
Navigate to `http://localhost:8080` to start exploring your network!
120-
121-
## Docker Deployment
122-
123-
### Using Pre-built Images (Recommended)
124-
125-
Pre-built container images are automatically built and published to GitHub Container Registry:
88+
Run directly using the pre-built container images from GitHub Container Registry:
12689

12790
```bash
128-
# Pull and run the latest image
91+
# Simple docker run
12992
docker run -d \
93+
--name tsflow \
13094
-p 8080:8080 \
13195
-e TAILSCALE_API_KEY=your-api-key \
13296
-e TAILSCALE_TAILNET=your-tailnet \
133-
--name tsflow \
97+
-e ENVIRONMENT=production \
98+
--restart unless-stopped \
13499
ghcr.io/rajsinghtech/tsflow:latest
135100
```
136101

137-
**Available tags:**
102+
**Available image tags:**
138103
- `latest` - Latest stable release from main branch
104+
- `<version>` - Tagged releases (e.g., `v1.0.0`)
139105
- `<commit-sha>` - Specific commit builds
140-
- `<version>` - Tagged releases
141106

142-
### Using Docker Compose (Recommended)
107+
#### Using Docker Compose (Recommended)
143108

144-
The included `docker-compose.yml` file provides the easiest deployment:
109+
Create a `docker-compose.yml` file:
145110

146111
```yaml
147112
services:
148113
tsflow:
149-
build: .
114+
image: ghcr.io/rajsinghtech/tsflow:latest
115+
container_name: tsflow
150116
ports:
151117
- "8080:8080"
152118
environment:
@@ -157,6 +123,11 @@ services:
157123
env_file:
158124
- .env
159125
restart: unless-stopped
126+
healthcheck:
127+
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
128+
interval: 30s
129+
timeout: 10s
130+
retries: 3
160131
```
161132
162133
**Commands:**
@@ -167,26 +138,169 @@ docker-compose up -d
167138
# View logs
168139
docker-compose logs -f tsflow
169140

170-
# Rebuild and restart
171-
docker-compose up --build -d
141+
# Update to latest version
142+
docker-compose pull && docker-compose up -d
172143

173144
# Stop the application
174145
docker-compose down
175146
```
176147

177-
### Building from Source
148+
### ☸️ Kubernetes Deployment
149+
150+
Deploy TSFlow on Kubernetes using the provided manifests:
151+
152+
#### Quick Deploy with Kustomize
153+
154+
```bash
155+
# Clone the repository
156+
git clone https://github.com/rajsinghtech/tsflow.git
157+
cd tsflow/k8s
158+
159+
# Set your Tailscale credentials
160+
export TAILSCALE_API_KEY="your-api-key-here"
161+
export TAILSCALE_TAILNET="your-tailnet-name"
162+
163+
# Deploy using Kustomize
164+
kubectl apply -k .
165+
```
166+
167+
#### Manual Deployment
168+
169+
1. **Create the namespace:**
170+
```bash
171+
kubectl create namespace tailscale
172+
```
173+
174+
2. **Create the secret with your credentials:**
175+
```bash
176+
kubectl create secret generic tsflow \
177+
--namespace=tailscale \
178+
--from-literal=TAILSCALE_API_KEY="your-api-key" \
179+
--from-literal=TAILSCALE_TAILNET="your-tailnet"
180+
```
181+
182+
3. **Deploy the application:**
183+
```bash
184+
# Apply all manifests
185+
kubectl apply -f k8s/deployment.yaml
186+
kubectl apply -f k8s/service.yaml
187+
188+
# Optional: Apply HTTPRoute for Gateway API
189+
kubectl apply -f k8s/httproute.yaml
190+
```
191+
192+
4. **Access the application:**
193+
```bash
194+
# Port forward for local access
195+
kubectl port-forward -n tailscale svc/tsflow 8080:80
196+
197+
# Or use ingress/gateway based on your cluster setup
198+
```
199+
200+
#### Kubernetes Manifests Overview
201+
202+
The k8s directory contains:
203+
- `deployment.yaml` - Main application deployment
204+
- `service.yaml` - ClusterIP service
205+
- `secret.yaml` - Secret template for credentials
206+
- `httproute.yaml` - Gateway API route (optional)
207+
- `kustomization.yaml` - Kustomize configuration
208+
209+
**Key features:**
210+
- Single replica with `Recreate` strategy
211+
- Health checks and resource limits
212+
- ConfigMap and Secret support
213+
- Gateway API compatibility
214+
215+
### 🔧 Local Development Build
216+
217+
For developers who want to build and run TSFlow locally:
218+
219+
#### Prerequisites
220+
- **Go 1.21+** for backend development
221+
- **Node.js 18+** and **npm** for frontend development
222+
- **Git** for version control
223+
224+
#### Development Setup
225+
226+
1. **Clone the repository:**
227+
```bash
228+
git clone https://github.com/rajsinghtech/tsflow.git
229+
cd tsflow
230+
```
231+
232+
2. **Configure environment:**
233+
```bash
234+
cp env.example .env
235+
```
236+
237+
Edit `.env` and add your Tailscale credentials:
238+
```env
239+
TAILSCALE_API_KEY=tskey-api-your-api-key-here
240+
TAILSCALE_TAILNET=your-tailnet-name
241+
PORT=8080
242+
ENVIRONMENT=development
243+
```
244+
245+
3. **Build and run the frontend:**
246+
```bash
247+
cd frontend
248+
npm install
249+
npm run build
250+
cd ..
251+
```
252+
253+
4. **Run the backend:**
254+
```bash
255+
cd backend
256+
go mod download
257+
go run main.go
258+
```
259+
260+
5. **Development workflow:**
261+
```bash
262+
# For frontend development with hot reload
263+
cd frontend
264+
npm run dev # Runs on port 5173 with proxy to backend
265+
266+
# For backend development with auto-reload
267+
cd backend
268+
go install github.com/cosmtrek/air@latest
269+
air # Auto-reloads on Go file changes
270+
```
271+
272+
#### Local Docker Build
273+
274+
Build the Docker image locally from source:
178275

179276
```bash
180277
# Build the image
181-
docker build -t tsflow .
278+
docker build -t tsflow:local .
182279

183280
# Run the container
184281
docker run -d \
282+
--name tsflow-local \
185283
-p 8080:8080 \
186284
-e TAILSCALE_API_KEY=your-api-key \
187285
-e TAILSCALE_TAILNET=your-tailnet \
188-
--name tsflow \
189-
tsflow
286+
--restart unless-stopped \
287+
tsflow:local
288+
```
289+
290+
#### Development Testing
291+
292+
```bash
293+
# Frontend testing
294+
cd frontend
295+
npm run test # Run unit tests
296+
npm run lint # Check code style
297+
npm run type-check # TypeScript validation
298+
299+
# Backend testing
300+
cd backend
301+
go test ./... # Run tests
302+
go fmt ./... # Format code
303+
go vet ./... # Static analysis
190304
```
191305

192306
## Configuration

k8s/deployment.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: tsflow
5+
spec:
6+
replicas: 1
7+
strategy:
8+
type: Recreate
9+
selector:
10+
matchLabels:
11+
app: tsflow
12+
template:
13+
metadata:
14+
labels:
15+
app: tsflow
16+
spec:
17+
containers:
18+
- name: tsflow
19+
image: ghcr.io/rajsinghtech/tsflow:latest
20+
imagePullPolicy: Always
21+
ports:
22+
- name: http
23+
containerPort: 8080
24+
protocol: TCP
25+
env:
26+
- name: TAILSCALE_API_KEY
27+
valueFrom:
28+
secretKeyRef:
29+
name: tsflow
30+
key: TAILSCALE_API_KEY
31+
- name: TAILSCALE_TAILNET
32+
valueFrom:
33+
secretKeyRef:
34+
name: tsflow
35+
key: TAILSCALE_TAILNET
36+
- name: ENVIRONMENT
37+
value: production

k8s/httproute.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: tsflow
5+
spec:
6+
parentRefs:
7+
- group: gateway.networking.k8s.io
8+
kind: Gateway
9+
name: envoy
10+
namespace: envoy
11+
hostnames:
12+
- "tsflow.example.com"
13+
rules:
14+
- backendRefs:
15+
- group: ""
16+
kind: Service
17+
name: tsflow
18+
port: 8080
19+
weight: 1
20+
matches:
21+
- path:
22+
type: PathPrefix
23+
value: /

k8s/kustomization.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
apiVersion: kustomize.config.k8s.io/v1beta1
3+
kind: Kustomization
4+
resources:
5+
- deployment.yaml
6+
- service.yaml
7+
- httproute.yaml
8+
- secret.yaml

k8s/secret.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: tsflow
5+
type: Opaque
6+
stringData:
7+
TAILSCALE_API_KEY: ${TAILSCALE_API_KEY}
8+
TAILSCALE_TAILNET: ${TAILSCALE_TAILNET}

k8s/service.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: tsflow
5+
spec:
6+
selector:
7+
app: tsflow
8+
ports:
9+
- name: http
10+
port: 80
11+
protocol: TCP
12+
targetPort: 8080
13+
type: ClusterIP

0 commit comments

Comments
 (0)