Communityコーディング&開発github.com

akka-net-management

Akka.Management を使用したクラスタブートストラップ、サービスディスカバリ(Kubernetes、Azure、Config)、ヘルスチェック、静的シードノードなしでの動的クラスタ形成。

akka-net-management とは?

このスキルは、Akka.NET クラスタを動的に形成・管理するための Akka.Management および Akka.Cluster.Bootstrap の設定と使用方法を網羅的に説明します。静的シードノードに依存する代わりに、Kubernetes API、Azure Table Storage、または HOCON 設定ファイルなどのサービスディスカバリプロバイダを利用して、クラスタノードが自動的に相互発見し、クラスタを形成できるようにします。これにより、クラウド環境やオートスケーリング環境でのデプロイが容易になり、運用負荷が軽減されます。具体的な NuGet パッケージの導入方法、Akka.Hosting を用いた設定コード例、ヘルスチェックエンドポイントの活用方法、トラブルシューティングのヒント、さらに .NET Aspire との統合パターンまでを含んでいます。また、Kubernetes、Azure、Config の各ディスカバリプロバイダに関する詳細なリファレンスファイルへのリンクも提供され、開発者が強く型付けされた設定モデルを使用して構成を安全に管理できるよう支援します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Aaronontheweb/dotnet-skills/tree/main/skills/akka-management

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Akka.NET 管理とサービスディスカバリ

このスキルを使用するタイミング

以下の場合にこのスキルを使用します:

  • Akka.NET クラスタを Kubernetes やクラウド環境にデプロイする場合
  • 静的シードノードを動的サービスディスカバリに置き換える場合
  • 自動形成のためのクラスタブートストラップを設定する場合
  • ロードバランサー用のヘルスエンドポイントを設定する場合
  • Azure Table Storage、Kubernetes API、または設定ベースのディスカバリと統合する場合

参照ファイル

概要

Akka.Management は、クラスタ管理のための HTTP エンドポイントを提供し、Akka.Cluster.Bootstrap と統合することで、静的シードノードの代わりにサービスディスカバリを使用した動的クラスタ形成を可能にします。

Akka.Management を使用する理由

アプローチ長所短所
静的シードノードシンプル、依存関係なしスケールしない、既知の IP が必要
Akka.Management動的ディスカバリ、N ノードにスケール設定が多い、外部依存関係あり

静的シードノードを使用する場合: 開発環境、単一ノードデプロイ、固定インフラストラクチャ。

Akka.Management を使用する場合: Kubernetes、オートスケーリンググループ、動的環境、本番クラスタ。


アーキテクチャ

┌─────────────────────────────────────────────────────────────┐
│                    クラスタブートストラップ                       │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐     │
│  │  ノード 1   │    │  ノード 2   │    │  ノード 3   │     │
│  │             │    │             │    │             │     │
│  │ Management  │◄──►│ Management  │◄──►│ Management  │     │
│  │ HTTP :8558  │    │ HTTP :8558  │    │ HTTP :8558  │     │
│  └──────┬──────┘    └──────┬──────┘    └──────┬──────┘     │
│         │                  │                  │             │
│         └──────────────────┼──────────────────┘             │
│                            │                                │
│                    ┌───────▼───────┐                        │
│                    │   ディスカバリ  │                        │
│                    │   プロバイダ   │                        │
│                    └───────────────┘                        │
│                            │                                │
└────────────────────────────┼────────────────────────────────┘
                             │
              ┌──────────────┼──────────────┐
              │              │              │
        ┌─────▼─────┐ ┌──────▼─────┐ ┌─────▼──────┐
        │ Kubernetes│ │   Azure    │ │   Config   │
        │    API    │ │   Tables   │ │   (HOCON)  │
        └───────────┘ └────────────┘ └────────────┘

必須 NuGet パッケージ

<ItemGroup>
  <!-- コア管理 -->
  <PackageReference Include="Akka.Management" />
  <PackageReference Include="Akka.Management.Cluster.Bootstrap" />

  <!-- ディスカバリプロバイダから1つを選択 -->
  <PackageReference Include="Akka.Discovery.KubernetesApi" />    <!-- Kubernetes用 -->
  <PackageReference Include="Akka.Discovery.Azure" />            <!-- Azure用 -->
  <PackageReference Include="Akka.Discovery.Config.Hosting" />   <!-- 静的設定用 -->
</ItemGroup>

Akka.Hosting 設定

モード選択による基本設定

public static class AkkaConfiguration
{
    public static IServiceCollection ConfigureAkka(
        this IServiceCollection services,
        Action<AkkaConfigurationBuilder, IServiceProvider>? additionalConfig = null)
    {
        services.AddOptions<AkkaSettings>()
            .BindConfiguration("AkkaSettings")
            .ValidateDataAnnotations()
            .ValidateOnStart();

        return services.AddAkka("MySystem", (builder, sp) =>
        {
            var settings = sp.GetRequiredService<IOptions<AkkaSettings>>().Value;
            var configuration = sp.GetRequiredService<IConfiguration>();

            ConfigureNetwork(builder, settings, configuration);
            ConfigureHealthChecks(builder);

            additionalConfig?.Invoke(builder, sp);
        });
    }

    private static void ConfigureNetwork(
        AkkaConfigurationBuilder builder,
        AkkaSettings settings,
        IConfiguration configuration)
    {
        if (settings.ExecutionMode == AkkaExecutionMode.LocalTest)
            return;

        builder.WithRemoting(settings.RemoteOptions);

        if (settings.ClusterBootstrapOptions.Enabled)
            ConfigureAkkaManagement(builder, settings, configuration);
        else
            builder.WithClustering(settings.ClusterOptions);
    }
}

Akka.Management 設定

private static void ConfigureAkkaManagement(
    AkkaConfigurationBuilder builder,
    AkkaSettings settings,
    IConfiguration configuration)
{
    var mgmtOptions = settings.AkkaManagementOptions;
    var bootstrapOptions = settings.ClusterBootstrapOptions;

    // 重要: Akka.Management 使用時はシードノードをクリア
    settings.ClusterOptions.SeedNodes = [];

    builder
        .WithClustering(settings.ClusterOptions)
        .WithAkkaManagement(setup =>
        {
            setup.Http.HostName = mgmtOptions.HostName;
            setup.Http.Port = mgmtOptions.Port;
            setup.Http.BindHostName = "0.0.0.0";
            setup.Http.BindPort = mgmtOptions.Port;
        })
        .WithClusterBootstrap(options =>
        {
            options.ContactPointDiscovery.ServiceName = bootstrapOptions.ServiceName;
            options.ContactPointDiscovery.PortName = bootstrapOptions.PortName;
            options.ContactPointDiscovery.RequiredContactPointsNr = bootstrapOptions.RequiredContactPointsNr;
            options.ContactPointDiscovery.Interval = bootstrapOptions.ContactPointProbingInterval;
            options.ContactPointDiscovery.StableMargin = bootstrapOptions.StableMargin;
            options.ContactPointDiscovery.ContactWithAllContactPoints = bootstrapOptions.ContactWithAllContactPoints;
            options.ContactPoint.FilterOnFallbackPort = bootstrapOptions.FilterOnFallbackPort;
            options.ContactPoint.ProbeInterval = bootstrapOptions.BootstrapperDiscoveryPingInterval;
        });

    // ディスカバリプロバイダを設定
    ConfigureDiscovery(builder, settings, configuration);
}

Config、Kubernetes、Azure ディスカバリの完全な設定コードについては、discovery-providers.md を参照してください。

完全な強く型付けされた設定モデルクラスについては、configuration-reference.md を参照してください。


ヘルスエンドポイント

Akka.Management は、ロードバランサーやオーケストレーター向けにヘルスエンドポイントを公開します:

エンドポイント目的200 を返す条件
/alive生存確認ActorSystem が実行中
/ready準備完了確認クラスタメンバーが Up 状態
/cluster/membersデバッグクラスタメンバーシップを返す

ASP.NET Core ヘルスチェック統合

// Akka ヘルスチェックを登録
builder.Services.AddHealthChecks();

// Akka 設定内で
builder
    .WithActorSystemLivenessCheck()     // "akka-liveness" ヘルスチェックを追加
    .WithAkkaClusterReadinessCheck();   // "akka-cluster-readiness" ヘルスチェックを追加

// エンドポイントをマッピング
app.MapHealthChecks("/health/live", new HealthCheckOptions
{
    Predicate = check => check.Tags.Contains("liveness")
});

app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
    Predicate = check => check.Tags.Contains("readiness")
});

トラブルシューティング

クラスタが形成されない

症状: ノードが個別のシングルノードクラスタのままになる。

チェックリスト:

  1. 全ノードが同じ ServiceName を使用している
  2. RequiredContactPointsNr が実際のレプリカ数と一致している
  3. ディスカバリプロバイダが正しく設定されている
  4. ネットワークが管理ポート (8558) へのトラフィックを許可している
  5. Kubernetes の場合: RBAC 権限が設定されている

スプリットブレイン

症状: 1つのクラスタではなく、複数のクラスタが形成される。

解決策:

  1. ContactWithAllContactPoints = true を設定
  2. 遅い環境では StableMargin を増やす
  3. Aspire の場合: FilterOnFallbackPort = false(動的ポート)
  4. Kubernetes の場合: FilterOnFallbackPort = true(固定ポート)

Azure ディスカバリの問題

症状: ノードが Azure Tables 経由で相互に発見できない。

チェックリスト:

  1. 接続文字列が有効である
  2. ストレージアカウントがテーブル操作を許可している
  3. 全ノードが同じ ServiceName を使用している
  4. ファイアウォールが Azure Storage へのアクセスを許可している

Aspire 統合

詳細な Aspire 固有のパターンについては、akka-net-aspire-configuration スキルを参照してください。

Aspire のクイックリファレンス:

// AppHost 内
appBuilder
    .WithEndpoint(name: "remote", protocol: ProtocolType.Tcp,
        env: "AkkaSettings__RemoteOptions__Port")
    .WithEndpoint(name: "management", protocol: ProtocolType.Tcp,
        env: "AkkaSettings__AkkaManagementOptions__Port")
    .WithEnvironment("AkkaSettings__ClusterBootstrapOptions__Enabled", "true")
    .WithEnvironment("AkkaSettings__ClusterBootstrapOptions__DiscoveryMethod", "AzureTableStorage")
    .WithEnvironment("AkkaSettings__ClusterBootstrapOptions__FilterOnFallbackPort", "false");

まとめ: 何をいつ使うか

シナリオディスカバリ方法FilterOnFallbackPort
ローカル開発(単一ノード)なし(シードノードを使用)N/A
Aspire マルチノードAzureTableStoragefalse
KubernetesKubernetestrue
Azure VM/VMSSAzureTableStoragetrue
固定インフラストラクチャConfigtrue
AWS ECS/EC2AWS ディスカバリプラグインtrue

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

akka-hosting-actor-patterns

Patterns for building entity actors with Akka.Hosting - GenericChildPerEntityParent, message extractors, cluster sharding abstraction, akka-reminders, and ITimeProvider. Supports both local testing and clustered production modes.

akka-net-aspire-configuration

Configure Akka.NET with .NET Aspire for local development and production deployments. Covers actor system setup, clustering, persistence, Akka.Management integration, and Aspire orchestration patterns.

akka-net-best-practices

Critical Akka.NET best practices including EventStream vs DistributedPubSub, supervision strategies, error handling, Props vs DependencyResolver, work distribution patterns, and cluster/local mode abstractions for testability.

akka-net-testing-patterns

Write unit and integration tests for Akka.NET actors using modern Akka.Hosting.TestKit patterns. Covers dependency injection, TestProbes, persistence testing, and actor interaction verification. Includes guidance on when to use traditional TestKit.

api-design

Design stable, compatible public APIs using extend-only design principles. Manage API compatibility, wire compatibility, and versioning for NuGet packages and distributed systems.

aspire-configuration

Configure Aspire AppHost to emit explicit app config via environment variables; keep app code free of Aspire clients and service discovery.

aspire-integration-testing

Write integration tests using .NET Aspire

aspire-service-defaults

Create a shared ServiceDefaults project for Aspire applications. Centralizes OpenTelemetry, health checks, resilience, and service discovery configuration across all services.

crap-analysis

Analyze code coverage and CRAP (Change Risk Anti-Patterns) scores to identify high-risk code. Use OpenCover format with ReportGenerator for Risk Hotspots showing cyclomatic complexity and untested code paths.

csharp-concurrency-patterns

Choosing the right concurrency abstraction in .NET - from async/await for I/O to Channels for producer/consumer to Akka.NET for stateful entity management. Avoid locks and manual synchronization unless absolutely necessary.

database-performance

Database access patterns for performance. Separate read/write models, avoid N+1 queries, use AsNoTracking, apply row limits, and never do application-side joins. Works with EF Core and Dapper.

dependency-injection-patterns

Organize DI registrations using IServiceCollection extension methods. Group related services into composable Add* methods for clean Program.cs and reusable configuration in tests.

dotnet-devcert-trust

Diagnose and fix .NET HTTPS dev certificate trust issues on Linux. Covers the full certificate lifecycle from generation to system CA bundle inclusion, with distro-specific guidance for Ubuntu, Fedora, Arch, and WSL2.

dotnet-local-tools

Managing local .NET tools with dotnet-tools.json for consistent tooling across development environments and CI/CD pipelines.

dotnet-project-structure

Modern .NET project structure including .slnx solution format, Directory.Build.props, central package management, SourceLink, version management with RELEASE_NOTES.md, and SDK pinning with global.json.

dotnet-slopwatch

Use Slopwatch to detect LLM reward hacking in .NET code changes. Run after every code modification to catch disabled tests, suppressed warnings, empty catch blocks, and other shortcuts that mask real problems.

efcore-patterns

Entity Framework Core best practices including NoTracking by default, query splitting for navigation collections, migration management, dedicated migration services, and common pitfalls to avoid.

ilspy-decompile

Understand implementation details of .NET code by decompiling assemblies. Use when you want to see how a .NET API works internally, inspect NuGet package source, view framework implementation, or understand compiled .NET binaries.

mailpit-integration

Test email sending locally using Mailpit with .NET Aspire. Captures all outgoing emails without sending them. View rendered HTML, inspect headers, and verify delivery in integration tests.

marketplace-publishing

Workflow for publishing skills and agents to the dotnet-skills Claude Code marketplace. Covers adding new content, updating plugin.json, validation, and release tagging.

関連スキル