yusefgamal/gitops-observability-platform
GitHub: yusefgamal/gitops-observability-platform
该项目演示了如何在 Kubernetes 上基于 GitOps 模式构建完整的可观测性平台,覆盖 CI/CD、自动化部署、监控、日志与故障响应全流程。
Stars: 0 | Forks: 0
# GitOps 可观测性平台
一个生产级的 DevOps 作品集项目,展示了如何在 Kubernetes 上构建、扫描、交付、部署、观测和排查容器化 API。
## 展示内容
- Docker 化的 FastAPI 服务,包含健康检查、就绪检查、指标、延迟和错误模拟 endpoint
- GitHub Actions CI,用于测试、镜像构建、Trivy 扫描和 GHCR 发布
- 用于 Deployment、Service、Ingress、ConfigMap、Secret、HPA 和监控集成的 Kubernetes manifest
- 基于 Argo CD 的 GitOps 部署模型
- Prometheus 指标、告警规则、Grafana dashboard 和 Loki 日志 manifest
- 面向 EKS 就绪 AWS 网络的 Terraform 基础架构
- 针对延迟事件的故障响应文档
## 架构
```
Developer push
-> GitHub Actions
-> Tests + image scan + GHCR image publish
-> Kubernetes manifests in Git
-> Argo CD sync
-> Kubernetes workload
-> Prometheus + Grafana + Loki
```
## 项目结构
```
.
|-- app/ # FastAPI service
|-- tests/ # Pytest tests
|-- k8s/
| |-- app/ # Application manifests
| |-- argocd/ # Argo CD Application
| |-- logging/ # Loki/Promtail values
| `-- monitoring/ # Prometheus rules and Grafana dashboard config
|-- terraform/ # AWS VPC foundation
|-- dashboards/ # Dashboard source JSON
|-- incidents/ # Incident response writeups
|-- scripts/ # Local helper scripts
|-- .github/workflows/ # CI pipeline
|-- Dockerfile
|-- docker-compose.yml
|-- Makefile
`-- requirements.txt
```
## 本地运行
```
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload
```
打开:
- API: http://localhost:8000
- Health: http://localhost:8000/health
- Readiness: http://localhost:8000/ready
- Metrics: http://localhost:8000/metrics
## 使用 Docker 运行
```
docker compose up --build
```
## 运行测试
```
pytest
```
## 使用 kind 或 minikube 本地部署
```
kubectl apply -f k8s/app/
kubectl get pods -n gitops-observability
kubectl port-forward -n gitops-observability svc/orders-api 8000:80
```
## 使用 Argo CD 进行 GitOps
1. 在你的集群中安装 Argo CD。
2. 将此仓库推送到 GitHub。
3. 应用 Argo CD Application:
```
kubectl apply -f k8s/argocd/application.yml
```
Argo CD 将从 `k8s/app` 同步 Kubernetes manifest。
## 可观测性
应用在 `/metrics` 暴露 Prometheus 指标,包括请求计数、延迟和模拟的失败行为。
建议的安装路径:
```
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
```
然后安装:
```
helm install monitoring prometheus-community/kube-prometheus-stack -n monitoring --create-namespace
helm install loki grafana/loki-stack -n logging --create-namespace -f k8s/logging/loki-stack-values.yml
kubectl apply -f k8s/monitoring/
```
## 故障模拟
触发延迟:
```
curl http://localhost:8000/simulate-latency
```
触发错误:
```
curl http://localhost:8000/simulate-error
```
然后检查:
- Prometheus 指标
- Grafana dashboard
- Loki 日志
- `k8s/monitoring/prometheus-rules.yml` 中的告警规则
- `incidents/incident-api-latency.md` 中的故障记录
## 建议的 GitHub 仓库描述
```
Production-style GitOps observability platform with Kubernetes, Argo CD, Prometheus, Grafana, Loki, GitHub Actions, Docker, and incident response documentation.
```
标签:API集成, GitOps, 可观测性, 子域名突变, 监控, 自定义请求头, 请求拦截, 逆向工具