一个本地运行的 Hacker News 和 RSS 阅读器,使用 Vue3 + Django REST Framework + PostgreSQL + Redis,通过 Kubernetes 在 Orbstack 上部署。
hackernews-reader/
├── backend/ # Django REST Framework 后端
│ ├── api/ # API 应用
│ │ ├── models.py # Django 模型
│ │ ├── views.py # API 视图
│ │ ├── serializers.py # DRF 序列化器
│ │ ├── services.py # 业务逻辑
│ │ └── urls.py # API 路由
│ ├── settings.py # Django 配置
│ ├── urls.py # 主路由配置
│ ├── wsgi.py # WSGI 入口
│ ├── manage.py # Django 管理命令
│ ├── requirements.txt # Python 依赖
│ └── Dockerfile
├── frontend/ # Vue3 前端
│ ├── src/
│ │ ├── views/ # 页面组件
│ │ │ ├── HomeView.vue # 合并新闻页
│ │ │ ├── HackerNewsView.vue # HN 文章页
│ │ │ └── RSSView.vue # RSS 管理页
│ │ ├── router/ # 路由配置
│ │ ├── App.vue
│ │ └── main.js
│ ├── package.json
│ ├── vite.config.js
│ └── Dockerfile
├── k8s/ # Kubernetes 配置文件
│ ├── 00-namespace.yaml
│ ├── 01-postgres.yaml
│ ├── 02-redis.yaml
│ ├── 03-backend.yaml
│ ├── 04-frontend.yaml
│ └── 05-ingress.yaml
├── deploy.sh # 一键部署脚本
├── cleanup.sh # 清理脚本
├── status.sh # 状态检查脚本
└── README.md
- 前端: Vue 3 + Vite + Vue Router + Axios + date-fns
- 后端: Django 5 + Django REST Framework
- 数据库: PostgreSQL 15
- 缓存: Redis 7 (django-redis)
- 部署: Kubernetes + Docker
- 📰 实时获取 Hacker News 热门文章
- 📡 支持添加/删除 RSS Feed
- 🔄 自动刷新 RSS 内容
- 💾 Redis 缓存提高性能
- 🎨 响应式 UI 设计
- 🐳 完整 Kubernetes 部署
- 安装 Orbstack 并启用 Kubernetes
- 确保 kubectl 可以连接集群
cd hackernews-reader
./deploy.sh- 安装 Ingress Controller:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml- 添加 hosts:
echo '127.0.0.1 hackernews.local' | sudo tee -a /etc/hosts# 端口转发
kubectl port-forward svc/frontend 8080:80 -n hackernews &
kubectl port-forward svc/backend 8000:8000 -n hackernews &
# 访问
open http://localhost:8080| 端点 | 描述 |
|---|---|
GET / |
API 信息 |
GET /health |
健康检查 |
GET /api/hn/stories?limit=30 |
Hacker News 热门文章 |
GET /api/rss/feeds |
RSS Feed 列表 |
POST /api/rss/feeds |
添加 RSS Feed |
DELETE /api/rss/feeds/{id} |
删除 RSS Feed |
GET /api/rss/items?feed={id} |
RSS 文章列表 |
POST /api/rss/feeds/{id}/refresh |
刷新 RSS Feed |
GET /api/combined?limit=50 |
合并的 HN + RSS |
cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# 设置环境变量
export DEBUG=true
export POSTGRES_HOST=localhost
export POSTGRES_PORT=5432
export REDIS_URL=redis://localhost:6379/0
# 运行开发服务器
python manage.py migrate
python manage.py runserver 0.0.0.0:8000cd frontend
npm install
npm run dev./status.sh./cleanup.sh# 后端日志
kubectl logs -f deployment/backend -n hackernews
# 前端日志
kubectl logs -f deployment/frontend -n hackernews
# PostgreSQL 日志
kubectl logs -f statefulset/postgres -n hackernews
# Redis 日志
kubectl logs -f deployment/redis -n hackernewsPod 一直 Pending
- 检查 PVC 是否绑定:
kubectl get pvc -n hackernews - Orbstack 可能需要手动创建存储
镜像加载失败
- 使用
orbctl k8s load-image加载镜像 - 或手动导入:
docker save | kubectl exec ...
数据库连接失败
- 等待 PostgreSQL 完全启动
- 检查 Service 名称是否正确
Django 迁移失败
- 进入 backend pod:
kubectl exec -it deployment/backend -n hackernews -- /bin/sh - 手动运行迁移:
python manage.py migrate
MIT