doc: added scripts and scripts for extreme low costs
This commit is contained in:
1 parent
e123c1895a
commit
60bd5066ef
5 files changed
+575
No files matched your search
@@ -0,0 +1,117 @@
|
||||
# Deployment Guide: Fleet with no ALB, no NAT, no Redis, no logs
|
||||
|
||||
`extreme-no-logs.tfvars` deploys Fleet at **~$48-52/month** by removing every
|
||||
component that isn't strictly required for a ~10-device deployment:
|
||||
|
||||
| Component | Config | Monthly cost |
|
||||
| ------------------ | ----------------------------------- | ------------ |
|
||||
| Aurora Serverless | 0.5 ACU min / 1.0 ACU max | ~$36 |
|
||||
| ECS Fargate Spot | 0.25 vCPU / 1GB, 1 task, 100% Spot | ~$9-13 |
|
||||
| Secrets Manager | 2 secrets | ~$0.80 |
|
||||
| S3 installers | 1 bucket, no versioning | ~$0.50 |
|
||||
| Data transfer | light | ~$1 |
|
||||
| ALB | **removed** | $0 |
|
||||
| NAT Gateway | **removed** | $0 |
|
||||
| ElastiCache | **removed** | $0 |
|
||||
| CloudWatch Logs | **removed** | $0 |
|
||||
| **Total** | | **~$48-52** |
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
internet
|
||||
│
|
||||
│ :8080 (0.0.0.0/0)
|
||||
▼
|
||||
┌───────────────────────┐
|
||||
│ ECS Fargate Spot task │ public subnet, public IP
|
||||
│ fleetdm/fleet │
|
||||
└───────────┬───────────┘
|
||||
│ :3306 (VPC-internal)
|
||||
▼
|
||||
┌───────────────────────┐
|
||||
│ Aurora Serverless v2 │ database subnet (private)
|
||||
│ 0.5 - 1.0 ACU │
|
||||
└───────────────────────┘
|
||||
```
|
||||
|
||||
There is no TLS termination point. Fleet serves **plain HTTP on :8080**.
|
||||
|
||||
> ⚠️ **Security note**: traffic between you/agents and Fleet is unencrypted.
|
||||
> For a personal/lab deployment this is usually acceptable; the Fleet server
|
||||
> private key and DB credentials stay inside AWS. If you need TLS, see
|
||||
> "Adding TLS" below.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Terraform ≥ 1.12, AWS CLI, credentials with admin-ish rights
|
||||
- No ACM certificate needed (there is no HTTPS listener)
|
||||
|
||||
## Deploy
|
||||
|
||||
```bash
|
||||
terraform init
|
||||
terraform apply -var-file=extreme-no-logs.tfvars
|
||||
```
|
||||
|
||||
Wait ~5-10 minutes for Aurora + the first ECS task.
|
||||
|
||||
## Access Fleet
|
||||
|
||||
### Option A — direct IP
|
||||
|
||||
```bash
|
||||
# discover the task public IP
|
||||
TASK=$(aws ecs list-tasks --cluster fleet --service-name fleet --query 'taskArns[0]' --output text)
|
||||
ENI=$(aws ecs describe-tasks --cluster fleet --tasks "$TASK" \
|
||||
--query "tasks[0].attachments[?status=='ATTACHED']|[0].details[?name=='networkInterfaceId'].value | [0]" --output text)
|
||||
IP=$(aws ec2 describe-network-interfaces --network-interface-ids "$ENI" \
|
||||
--query 'NetworkInterfaces[0].Association.PublicIp' --output text)
|
||||
echo "http://$IP:8080"
|
||||
```
|
||||
|
||||
Then set Fleet's server URL (Settings → Organization) to `http://<IP>:8080`
|
||||
so newly enrolled agents get the right address.
|
||||
|
||||
### Option B — Route53 (recommended)
|
||||
|
||||
```bash
|
||||
./scripts/setup-route53.sh fleet.example.com # one-shot
|
||||
# or keep in sync automatically:
|
||||
*/5 * * * * /path/to/scripts/setup-route53.sh fleet.example.com >>/tmp/fleet-dns.log 2>&1
|
||||
```
|
||||
|
||||
The record uses TTL=60s; the script re-resolves the task IP on each run, so
|
||||
DNS follows Spot restarts within ~5 minutes.
|
||||
|
||||
## Debugging (no logs by default)
|
||||
|
||||
```bash
|
||||
./scripts/emergency-logging.sh enable # adds awslogs driver, /ecs/fleet, 3-day retention
|
||||
aws logs tail /ecs/fleet --follow
|
||||
./scripts/emergency-logging.sh disable # removes driver + deletes log group
|
||||
```
|
||||
|
||||
Each enable/disable registers a new task-definition revision and forces a
|
||||
redeployment (~1 min downtime).
|
||||
|
||||
## Adding TLS (optional)
|
||||
|
||||
The cheapest TLS option without an ALB is Fleet's built-in TLS
|
||||
(`FLEET_SERVER_TLS=true` plus cert files). That requires baking certs into the
|
||||
image or mounting them, which is out of scope for this configuration. A
|
||||
pragmatic middle ground:
|
||||
|
||||
1. Put a **CloudFront distribution** in front of the task IP (~$1-3/month at
|
||||
low traffic) — CloudFront terminates TLS with its own cert and forwards to
|
||||
the origin over HTTP inside the AWS backbone. Note CloudFront adds latency
|
||||
for osquery's long-polling; test before committing.
|
||||
2. Or re-enable the ALB (`alb_config.enabled = true` + `certificate_arn`)
|
||||
which restores managed TLS for ~$16/month.
|
||||
|
||||
## Reverting to a load balancer
|
||||
|
||||
Set `alb_config.enabled = true` in your tfvars (and provide
|
||||
`certificate_arn`) and re-apply. Terraform moves existing state automatically
|
||||
via the `moved` blocks in `byo-vpc/byo-db/moved.tf` — the ALB is recreated,
|
||||
not orphaned.
|
||||
@@ -0,0 +1,114 @@
|
||||
# Migration Guide: ALB → No-ALB (extreme-no-logs)
|
||||
|
||||
This guide covers migrating an existing ALB-based Fleet deployment to the
|
||||
`extreme-no-logs.tfvars` configuration (~$48-52/month).
|
||||
|
||||
> **Fresh install?** Skip this document and read
|
||||
> [DEPLOYMENT-NO-ALB.md](./DEPLOYMENT-NO-ALB.md) instead.
|
||||
|
||||
## What changes
|
||||
|
||||
| Component | Before (extreme-low-cost) | After (extreme-no-logs) |
|
||||
| ------------------ | ------------------------- | ---------------------------- |
|
||||
| ALB | ✔ created (~$16/mo) | ❌ destroyed |
|
||||
| ElastiCache | ✔ t4g.micro (~$12/mo) | ❌ destroyed |
|
||||
| CloudWatch Logs | 1-day retention | ❌ no log groups / no driver |
|
||||
| ECS networking | private subnet (ALB → task) | public subnet + public IP |
|
||||
| Fleet access | `https://fleet.example.com` (ALB + ACM cert) | `http://<task-ip>:8080` or Route53 A record |
|
||||
| TLS | terminated at ALB | none (plain HTTP) by default |
|
||||
|
||||
## 1. Pre-migration checklist
|
||||
|
||||
1. **Backup state**
|
||||
|
||||
```bash
|
||||
terraform state pull > terraform.state.backup.$(date +%Y%m%d-%H%M%S).json
|
||||
```
|
||||
|
||||
2. **Note the current ALB DNS name** and any Route53 records pointing at it:
|
||||
|
||||
```bash
|
||||
terraform output -json | python3 -c "import json,sys; d=json.load(sys.stdin); print(d)"
|
||||
```
|
||||
|
||||
3. **Plan for downtime**: the ECS service is redeployed; expect ~2-5 minutes
|
||||
of unavailability.
|
||||
|
||||
4. **Notify device owners** (optional): osquery agents buffer results and
|
||||
reconnect automatically; nothing is lost during a short outage.
|
||||
|
||||
## 2. Automated migration (recommended)
|
||||
|
||||
```bash
|
||||
./scripts/migrate-from-alb.sh
|
||||
```
|
||||
|
||||
The script backs up state, shows the plan, asks for confirmation, applies,
|
||||
discovers the new task public IP, and optionally syncs a Route53 record.
|
||||
|
||||
## 3. Manual migration
|
||||
|
||||
```bash
|
||||
terraform plan -var-file=extreme-no-logs.tfvars -out=migration.plan
|
||||
# review: ALB, NAT GW, ElastiCache and log groups should show as destroyed
|
||||
terraform apply migration.plan
|
||||
```
|
||||
|
||||
## 4. Post-migration
|
||||
|
||||
1. **Get the new endpoint**:
|
||||
|
||||
```bash
|
||||
# direct IP
|
||||
./scripts/setup-route53.sh --help # shows discovery logic, or:
|
||||
aws ecs list-tasks --cluster fleet --service-name fleet
|
||||
```
|
||||
|
||||
2. **(Optional) Route53**: keep a low-TTL A record in sync:
|
||||
|
||||
```bash
|
||||
./scripts/setup-route53.sh fleet.example.com
|
||||
# and via cron:
|
||||
*/5 * * * * /path/to/scripts/setup-route53.sh fleet.example.com >>/tmp/fleet-dns.log 2>&1
|
||||
```
|
||||
|
||||
3. **Update Fleet server settings**: In Fleet UI → Settings → Organization,
|
||||
set the server URL to the new address so agents enroll with the right URL.
|
||||
|
||||
4. **Verify agents reconnect** within ~10 minutes.
|
||||
|
||||
## 5. Rollback
|
||||
|
||||
If anything goes wrong, restore the pre-migration state and re-apply the old
|
||||
configuration:
|
||||
|
||||
```bash
|
||||
# Restore state backup (local backend)
|
||||
cp terraform.state.backup.<timestamp>.json terraform.tfstate
|
||||
|
||||
# Re-apply previous config
|
||||
terraform apply -var-file=extreme-low-cost.tfvars
|
||||
```
|
||||
|
||||
With a remote backend (S3), use the backend's versioning to restore the
|
||||
previous state version, then apply the previous tfvars.
|
||||
|
||||
## 6. Troubleshooting without logs
|
||||
|
||||
Fleet runs with no log driver in this configuration. To debug:
|
||||
|
||||
```bash
|
||||
# Enable logs temporarily (default 3-day retention)
|
||||
./scripts/emergency-logging.sh enable
|
||||
|
||||
aws logs tail /ecs/fleet --follow
|
||||
|
||||
# When done, resume cost savings:
|
||||
./scripts/emergency-logging.sh disable
|
||||
```
|
||||
|
||||
Health check without logs:
|
||||
|
||||
```bash
|
||||
curl -s http://<task-ip>:8080/healthz
|
||||
```
|
||||
Reference in new issue
Block a user