photoncloud-monorepo/Nix-NOS.md
centra 3eeb303dcb feat: Batch commit for T039.S3 deployment
Includes all pending changes needed for nixos-anywhere:
- fiberlb: L7 policy, rule, certificate types
- deployer: New service for cluster management
- nix-nos: Generic network modules
- Various service updates and fixes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 04:34:51 +09:00

398 lines
17 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# PlasmaCloud/PhotonCloud と Nix-NOS の統合分析
## Architecture Decision (2025-12-13)
**決定:** Nix-NOSを汎用ネットワークモジュールとして別リポジトリに分離する。
### Three-Layer Architecture
```
Layer 3: PlasmaCloud Cluster (T061)
- plasmacloud-cluster.nix
- cluster-config.json生成
- Deployer (Rust)
depends on ↓
Layer 2: PlasmaCloud Network (T061)
- plasmacloud-network.nix
- FiberLB BGP連携
- PrismNET統合
depends on ↓
Layer 1: Nix-NOS Generic (T062) ← 別リポジトリ
- BGP (BIRD2/GoBGP)
- VLAN
- Network interfaces
- PlasmaCloudを知らない汎用モジュール
```
### Repository Structure
- **github.com/centra/nix-nos**: Layer 1 (汎用、VyOS/OpenWrt代替)
- **github.com/centra/plasmacloud**: Layers 2+3 (既存リポジトリ)
---
## 1. 既存プロジェクトの概要
PlasmaCloudPhotonCloudは、以下のコンポーネントで構成されるクラウド基盤プロジェクト
### コアサービス
| コンポーネント | 役割 | 技術スタック |
|---------------|------|-------------|
| **ChainFire** | 分散KVストアetcd互換 | Rust, Raft (openraft) |
| **FlareDB** | SQLデータベース | Rust, KVバックエンド |
| **IAM** | 認証・認可 | Rust, JWT/mTLS |
| **PlasmaVMC** | VM管理 | Rust, KVM/FireCracker |
| **PrismNET** | オーバーレイネットワーク | Rust, OVN連携 |
| **LightningSTOR** | オブジェクトストレージ | Rust, S3互換 |
| **FlashDNS** | DNS | Rust, hickory-dns |
| **FiberLB** | ロードバランサー | Rust, L4/L7, BGP予定 |
| **NightLight** | メトリクス | Rust, Prometheus互換 |
| **k8shost** | コンテナオーケストレーション | Rust, K8s API互換 |
### インフラ層
- **NixOSモジュール**: 各サービス用 (`nix/modules/`)
- **first-boot-automation**: 自動クラスタ参加
- **PXE/Netboot**: ベアメタルプロビジョニング
- **TLS証明書管理**: 開発用証明書生成スクリプト
---
## 2. Nix-NOS との統合ポイント
### 2.1 Baremetal Provisioning → Deployer強化
**既存の実装:**
```
first-boot-automation.nix
├── cluster-config.json による設定注入
├── bootstrap vs join の自動判定
├── マーカーファイルによる冪等性
└── systemd サービス連携
```
**Nix-NOSで追加すべき機能:**
| 既存 | Nix-NOS追加 |
|------|-------------|
| cluster-config.json (手動作成) | topology.nix から自動生成 |
| 単一クラスタ構成 | 複数クラスタ/サイト対応 |
| nixos-anywhere 依存 | Deployer (Phone Home + Push) |
| 固定IP設定 | IPAM連携による動的割当 |
**統合設計:**
```nix
# topology.nixNix-NOS
{
nix-nos.clusters.plasmacloud = {
nodes = {
"node01" = {
role = "control-plane";
ip = "10.0.1.10";
services = [ "chainfire" "flaredb" "iam" ];
};
"node02" = { role = "control-plane"; ip = "10.0.1.11"; };
"node03" = { role = "worker"; ip = "10.0.1.12"; };
};
# Nix-NOSが自動生成 → first-boot-automationが読む
# cluster-config.json の内容をNix評価時に決定
};
}
```
### 2.2 Network Management → PrismNET + FiberLB + Nix-NOS BGP
**既存の実装:**
```
PrismNET (prismnet/)
├── VPC/Subnet/Port管理
├── Security Groups
├── IPAM
└── OVN連携
FiberLB (fiberlb/)
├── L4/L7ロードバランシング
├── ヘルスチェック
├── VIP管理
└── BGP統合設計済み、GoBGPサイドカー
```
**Nix-NOSで追加すべき機能:**
```
Nix-NOS Network Layer
├── BGP設定生成BIRD2
│ ├── iBGP/eBGP自動計算
│ ├── Route Reflector対応
│ └── ポリシー抽象化
├── topology.nix → systemd-networkd
├── OpenWrt/Cisco設定生成将来
└── FiberLB BGP連携
```
**統合設計:**
```nix
# Nix-NOSのBGPモジュール → FiberLBのGoBGP設定に統合
{
nix-nos.network.bgp = {
autonomousSystems = {
"65000" = {
members = [ "node01" "node02" "node03" ];
ibgp.strategy = "route-reflector";
ibgp.reflectors = [ "node01" ];
};
};
# FiberLBのVIPをBGPで広報
vipAdvertisements = {
"fiberlb" = {
vips = [ "10.0.100.1" "10.0.100.2" ];
nextHop = "self";
communities = [ "65000:100" ];
};
};
};
# FiberLBモジュールとの連携
services.fiberlb.bgp = {
enable = true;
# Nix-NOSが生成するGoBGP設定を参照
configFile = config.nix-nos.network.bgp.gobgpConfig;
};
}
```
### 2.3 K8sパチモン → k8shost + Pure NixOS Alternative
**既存の実装:**
```
k8shost (k8shost/)
├── Pod管理gRPC API
├── Service管理ClusterIP/NodePort
├── Node管理
├── CNI連携
├── CSI連携
└── FiberLB/FlashDNS連携
```
**Nix-NOSの役割:**
k8shostはすでにKubernetesのパチモンとして機能している。Nix-NOSは
1. **k8shostを使う場合**: k8shostクラスタ自体のデプロイをNix-NOSで管理
2. **Pure NixOSK8sなし**: より軽量な選択肢として、Systemd + Nix-NOSでサービス管理
```
┌─────────────────────────────────────────────────────────────┐
│ Orchestration Options │
├─────────────────────────────────────────────────────────────┤
│ Option A: k8shost (K8s-like) │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Nix-NOS manages: cluster topology, network, certs │ │
│ │ k8shost manages: pods, services, scaling │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ Option B: Pure NixOS (K8s-free) │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Nix-NOS manages: everything │ │
│ │ systemd + containers, static service discovery │ │
│ │ Use case: クラウド基盤自体の管理 │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
```
**重要な洞察:**
> 「クラウドの基盤そのものを作るのにKubernetesは使いたくない」
これは正しいアプローチ。PlasmaCloudのコアサービスChainFire, FlareDB, IAM等
- K8sの上で動くのではなく、K8sを提供する側
- Pure NixOS + Systemdで管理されるべき
- Nix-NOSはこのレイヤーを担当
---
## 3. 具体的な統合計画
### Phase 1: Baremetal Provisioning統合
**目標:** first-boot-automationをNix-NOSのtopology.nixと連携
```nix
# nix/modules/first-boot-automation.nix への追加
{ config, lib, ... }:
let
# Nix-NOSのトポロジーから設定を生成
clusterConfig =
if config.nix-nos.cluster != null then
config.nix-nos.cluster.generateClusterConfig {
hostname = config.networking.hostName;
}
else
# 従来のcluster-config.json読み込み
builtins.fromJSON (builtins.readFile /etc/nixos/secrets/cluster-config.json);
in {
# 既存のfirst-boot-automationロジックはそのまま
# ただし設定ソースをNix-NOSに切り替え可能に
}
```
### Phase 2: BGP/Network統合
**目標:** FiberLBのBGP連携T055.S3をNix-NOSで宣言的に管理
```nix
# nix/modules/fiberlb-bgp-nixnos.nix
{ config, lib, pkgs, ... }:
let
fiberlbCfg = config.services.fiberlb;
nixnosBgp = config.nix-nos.network.bgp;
in {
config = lib.mkIf (fiberlbCfg.enable && nixnosBgp.enable) {
# GoBGP設定をNix-NOSから生成
services.gobgpd = {
enable = true;
configFile = pkgs.writeText "gobgp.yaml" (
nixnosBgp.generateGobgpConfig {
localAs = nixnosBgp.getLocalAs config.networking.hostName;
routerId = nixnosBgp.getRouterId config.networking.hostName;
neighbors = nixnosBgp.getPeers config.networking.hostName;
}
);
};
# FiberLBにGoBGPアドレスを注入
services.fiberlb.bgp = {
gobgpAddress = "127.0.0.1:50051";
};
};
}
```
### Phase 3: Deployer実装
**目標:** Phone Home + Push型デプロイメントコントローラー
```
plasmacloud/
├── deployer/ # 新規追加
│ ├── src/
│ │ ├── api.rs # Phone Home API
│ │ ├── orchestrator.rs # デプロイワークフロー
│ │ ├── state.rs # ード状態管理ChainFire連携
│ │ └── iso_generator.rs # ISO自動生成
│ └── Cargo.toml
└── nix/
└── modules/
└── deployer.nix # NixOSモジュール
```
**ChainFireとの連携:**
DeployerはChainFireを状態ストアとして使用
```rust
// deployer/src/state.rs
struct NodeState {
hostname: String,
status: NodeStatus, // Pending, Provisioning, Active, Failed
bootstrap_key_hash: Option<String>,
ssh_pubkey: Option<String>,
last_seen: DateTime<Utc>,
}
impl DeployerState {
async fn register_node(&self, node: &NodeState) -> Result<()> {
// ChainFireに保存
self.chainfire_client
.put(format!("deployer/nodes/{}", node.hostname), node.to_json())
.await
}
}
```
---
## 4. アーキテクチャ全体図
```
┌─────────────────────────────────────────────────────────────────────┐
│ Nix-NOS Layer │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ topology.nix │ │
│ │ - ノード定義 │ │
│ │ - ネットワークトポロジー │ │
│ │ - サービス配置 │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │ │
│ generates │ │
│ ▼ │
│ ┌──────────────┬──────────────┬──────────────┬──────────────┐ │
│ │ NixOS Config │ BIRD Config │ GoBGP Config │ cluster- │ │
│ │ (systemd) │ (BGP) │ (FiberLB) │ config.json │ │
│ └──────────────┴──────────────┴──────────────┴──────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ PlasmaCloud Services │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ Control Plane │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ChainFire │ │ FlareDB │ │ IAM │ │ Deployer │ │ │
│ │ │(Raft KV) │ │ (SQL) │ │(AuthN/Z) │ │ (新規) │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ Network Plane │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ PrismNET │ │ FiberLB │ │ FlashDNS │ │ BIRD2 │ │ │
│ │ │ (OVN) │ │(LB+BGP) │ │ (DNS) │ │(Nix-NOS) │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ Compute Plane │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │PlasmaVMC │ │ k8shost │ │Lightning │ │ │
│ │ │(VM/FC) │ │(K8s-like)│ │ STOR │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ │ │
│ └───────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
```
---
## 5. 優先度と実装順序
| 優先度 | 機能 | 依存関係 | 工数 |
|--------|------|----------|------|
| **P0** | topology.nix → cluster-config.json生成 | なし | 1週間 |
| **P0** | BGPモジュールBIRD2設定生成 | なし | 2週間 |
| **P1** | FiberLB BGP連携GoBGP | T055.S3完了 | 2週間 |
| **P1** | Deployer基本実装 | ChainFire | 3週間 |
| **P2** | OpenWrt設定生成 | BGPモジュール | 2週間 |
| **P2** | ISO自動生成パイプライン | Deployer完了後 | 1週間 |
| **P2** | 各サービスの設定をNixで管理可能なように | なし | 適当 |
---
## 6. 結論
PlasmaCloud/PhotonCloudプロジェクトは、Nix-NOSの構想を実装するための**理想的な基盤**
1. **すでにNixOSモジュール化されている** → Nix-NOSモジュールとの統合が容易
2. **first-boot-automationが存在** → Deployerの基礎として活用可能
3. **FiberLBにBGP設計がある** → Nix-NOSのBGPモジュールと自然に統合
4. **ChainFireが状態ストア** → Deployer状態管理に利用可能
5. **k8shostが存在するがK8sではない** → 「K8sパチモン」の哲学と一致
**次のアクション:**
1. Nix-NOSモジュールをPlasmaCloudリポジトリに追加
2. topology.nix → cluster-config.json生成の実装
3. BGPモジュールBIRD2の実装とFiberLB連携