bhashas/k8s-proxmox-lab
GitHub: bhashas/k8s-proxmox-lab
基于 Proxmox 和 Kubernetes 的全自动化 DevSecOps 实验平台,通过 Terraform、Ansible 和 ArgoCD 实现从虚拟机开通到安全应用部署的完整 GitOps 流程。
Stars: 0 | Forks: 0
# ☸️ DevSecOps 平台 — Proxmox + Kubernetes + GitOps



## 🏗️ 架构
```
Hetzner Dedicated Server (64Go RAM / 2x500Go ZFS)
└── Proxmox VE 8.x
├── VM k8s-master (192.168.192.50) — Control Plane
├── VM k8s-worker1 (192.168.192.51) — Worker + Ceph OSD
└── VM k8s-worker2 (192.168.192.52) — Worker + Ceph OSD
```
### GitOps 流水线
```
git push
↓
GitHub Actions (self-hosted runner)
↓
ci.yml + security.yml → lint + Checkov + Trivy
↓
terraform.yml → VMs Proxmox (si infra/** modifié)
↓
ansible.yml → K8s + Cilium + ArgoCD (si ansible/** modifié)
↓
gitops.yml → ArgoCD sync (si k8s/** modifié)
↓
✅ Apps déployées automatiquement
```
## 🛠️ 技术栈
### 基础设施与开通
| 工具 | 作用 |
|---|---|
| **Terraform** bpg/proxmox v0.70+ | 在 Proxmox 上开通 VM |
| **Ansible** | 初始化 OS + Kubernetes |
| **cloud-init** | 初始 VM 配置 |
| **Proxmox VE** | 裸金属虚拟机监控程序 |
### Kubernetes 与网络
| 工具 | 作用 |
|---|---|
| **kubeadm v1.28** | 初始化 Kubernetes 集群 |
| **Cilium 1.15** | CNI eBPF + kube-proxy 替代 |
| **Hubble** | 网络可观测性 (UI + Relay) |
| **Gateway API** | 新一代 Ingress |
### GitOps 与 CI/CD
| 工具 | 作用 |
|---|---|
| **ArgoCD** | GitOps — 持续部署 |
| **GitHub Actions** | 专用 CI/CD 流水线 |
| **Checkov** | IaC 安全扫描 |
| **Trivy** | 文件系统漏洞扫描 |
### 通过 ArgoCD 部署的应用
| 命名空间 | 应用 |
|---|---|
| `monitoring` | Prometheus + Grafana + Loki |
| `security` | Falco + Wazuh agent + Zeek + Kyverno + Trivy Operator |
| `auth` | Keycloak (OIDC) |
| `automation` | n8n + Telegram |
| `storage` | Rook-Ceph |
| `backup` | Velero |
| `ingress` | Cert-manager + Cloudflare Tunnel |
## 🚀 部署
### 前置条件
- 带有 Ubuntu 24.04 cloud-init 模板 (VM ID 9000) 的 Proxmox VE
- Proxmox API Token
- Terraform >= 1.7.0
- Ansible
### 1. 克隆仓库
```
git clone https://github.com/bhashas/k8s-proxmox-lab
cd k8s-proxmox-lab
```
### 2. 配置变量
```
cat > infra/terraform.tfvars << EOF
proxmox_api_url = "https://PROXMOX_IP:8006"
proxmox_token_id = "terraform-user@pam!token"
proxmox_token_secret = "SECRET"
proxmox_node = "pve-1"
gateway = "192.168.192.5"
ssh_public_key = "ssh-ed25519 ..."
EOF
```
### 3. 开通 VM
```
cd infra
terraform init
terraform apply
```
### 4. 安装 Kubernetes
```
cd ansible
ansible-playbook -i inventory.ini site.yml
```
### 5. 验证集群
```
kubectl get nodes
kubectl get pods -A
```
## 📁 项目结构
```
k8s-proxmox-lab/
├── .github/workflows/
│ ├── ci.yml # Lint + Validate (tout push)
│ ├── security.yml # Checkov + Trivy (tout push)
│ ├── terraform.yml # Apply si infra/** modifié
│ ├── ansible.yml # Bootstrap si ansible/** modifié
│ └── gitops.yml # ArgoCD sync si k8s/** modifié
├── infra/ # Terraform — VMs Proxmox
├── ansible/ # Ansible — K8s bootstrap
│ └── roles/
│ ├── common/ # OS config, swap, sysctl
│ ├── containerd/ # Container runtime
│ ├── kubernetes/ # kubeadm, kubelet, kubectl
│ ├── master/ # kubeadm init + Cilium + ArgoCD
│ └── worker/ # kubeadm join
└── k8s/ # Manifests ArgoCD (GitOps)
├── base/
│ └── app-of-apps.yaml
└── apps/
├── monitoring/
├── security/
├── auth/
├── automation/
├── storage/
├── backup/
└── ingress/
```
## 🔒 安全性
- **CPU 类型 host** — 为 Ceph/eBPF 提供 SSE4.2 指令集
- **UEFI + TPM 2.0** — VM 级别安全
- **Cilium eBPF** — L7 NetworkPolicy
- **Kyverno** — Policy as Code
- **Trivy Operator** — 持续镜像扫描
- **Falco** — runtime 异常检测
- **Wazuh agents** — K8s 节点上的 EDR
- **Checkov** — 每次提交的 IaC 扫描
- **Secrets** — 绝不提交(严格的 .gitignore)
## 📊 最佳实践
- ✅ 100% IaC 基础设施 — 零手动操作
- ✅ 按职责划分的 CI/CD 流水线 (1 个工作流 = 1 个角色)
- ✅ GitOps — Git 作为唯一事实来源
- ✅ 自托管运行器 — 安全的私有网络访问
- ✅ Ansible 幂等性 — 可重放的 Playbook
- ✅ CPU 类型 host — eBPF/Ceph 的最佳性能
## 👤 作者
**Brahim HASHAS** — Cloud 与 SecOps 架构师
[github.com/bhashas](https://github.com/bhashas)
标签:Ansible, ArgoCD, Ceph, Cilium, CISA项目, DevSecOps, ECS, Falco, GitHub Actions, GitOps, Grafana, Hubble, NPM, Proxmox, Terraform, Wazuh, ZFS, 上游代理, 子域名突变, 安全合规, 安全扫描, 容器编排, 开源框架, 微服务架构, 持续部署, 持续集成, 敏感词过滤, 时序注入, 服务器虚拟化, 系统提示词, 网络代理, 网络安全, 自动化运维, 自动笔记, 自定义请求头, 隐私保护