WebAssembly コンポーネントは、アプリケーションをビルドしてデプロイするための新しい方法です。 プログラミング言語の移植可能なコンパイル ターゲットとして設計されており、さまざまな環境で実行できます。 WebAssembly コンポーネントは、設計によってサンドボックス化され、定義されたインターフェイスを使用してその機能を公開します。 コンポーネントは、起動がはるかに小さく高速な単一のバイナリであるという点で、コンテナーとは異なります。 モデルの完全な説明と、仕様内のコンポーネントが何であるかを確認します。
wasmCloud は、WebAssembly コンポーネントの開発、デプロイ、オーケストレーションを迅速に追跡するように設計された、Cloud Native Computing Foundation (CNCF) プロジェクトです。 このドキュメントでは、Azure Kubernetes Service (AKS) クラスターに wasmCloud をデプロイする方法について詳しく説明します。
開始する前に
- この記事では、Kubernetes の基本的な概念を理解していることを前提としています。 詳細については、「Azure Kubernetes Services (AKS) における Kubernetes の中心概念」を参照してください。
- アクティブな Azure サブスクリプションが必要です。 アカウントをお持ちでない場合は、開始する前に 無料アカウント を作成してください。
- AKS クラスターが必要です。 既存のクラスターがない場合は、Azure CLI、Azure PowerShell、または Azure portal を使用して作成できます。
- wasmCloud CLI (wash) をバージョン 0.39.0 以降でインストールする必要があります。 インストール オプションについては、 wasmcloud-cli を参照してください。
[前提条件]
- Azure portal を使用して wasmCloud を AKS クラスターにデプロイすることはできません。
wasmCloud をデプロイする
AKS クラスターに wasmCloud をデプロイするには、1 つの Helm チャート内のすべてをクラスターにインストールする必要があります。 これにより、次のサービスが 1 つの名前空間にインストールされます。
- NATS: NATS は、wasmCloud 内のコンポーネント間のすべての通信のバックボーンを提供します。
- wadm: wasmCloud アプリケーション マネージャー。それ以外の場合は wadm と呼ばれ、wasmCloud 上で実行されているアプリケーションを管理するためのオーケストレーターです。
- wasmCloud オペレーター: wasmCloud オペレーターは、wasmCloud ホストのライフサイクルを管理する Kubernetes オペレーターです。
専用の Kubernetes 名前空間に wasmCloud をデプロイすることをお勧めします。
kubectlを使用して wasmCloud の名前空間を作成します。kubectl create namespace wasmcloudhelm upgradeコマンドを使用して、wasmCloud 名前空間に NATS と wadm をインストールします。# By default, the chart installs NATS, Wadm, and wasmCloud Operator subcharts helm upgrade --install \ wasmcloud-platform \ --values https://raw.githubusercontent.com/wasmCloud/wasmcloud/main/charts/wasmcloud-platform/values.yaml \ oci://ghcr.io/wasmcloud/charts/wasmcloud-platform:0.1.2 \ --dependency-updateこのコマンドの出力は次のようになります。
NAME: wasmcloud-platform LAST DEPLOYED: Thu Nov 7 14:58:54 2024 NAMESPACE: default STATUS: deployed REVISION: 1 NOTES:すべてのポッドが
kubectlの使用を開始するまで待ちます。kubectl rollout status deploy,sts -l app.kubernetes.io/name=nats kubectl wait --for=condition=available --timeout=600s deploy -l app.kubernetes.io/name=wadm kubectl wait --for=condition=available --timeout=600s deploy -l app.kubernetes.io/name=wasmcloud-operatorCRD と
kubectlを使用して wasmCloud ホストを起動します。cat << EOF | kubectl apply -f - apiVersion: k8s.wasmcloud.dev/v1alpha1 kind: WasmCloudHostConfig metadata: name: wasmcloud-host spec: lattice: default version: "1.4.1" EOFwasmCloud ホストが実行されていることを確認します。
kubectl get pod -l app.kubernetes.io/instance=wasmcloud-host出力は次のようになります。
NAME READY STATUS RESTARTS AGE wasmcloud-host-f9d67b8cf-lvsq6 2/2 Running 0 84swashを使用して wasmCloud ホストに接続できることを確認します。別のシェルで次のコマンドを実行して、実行中の NATS ポッドのいずれかに移植します。
kubectl port-forward nats-0 4222このコマンドは、ポート 4222 のすべてのトラフィックを、クラスターで実行されている NATS ポッドにローカルに転送します。
washを使用して wasmCloud に接続するには、このポートを転送する必要があります。元のシェルで、
washで次のコマンドを実行して、wasmCloud ホストが実行されていることを確認します。wash get hosts出力は次のようになります。
Host ID Friendly name Uptime (seconds) ND2G4FRXLBCV3YL52OD4NRSS66Z5YOR3JOSL3Q7T5I6ZJM4EII3Y73CZ frosty-resonance-6227 312
wasmCloud アプリケーションをデプロイする
これで、wasmCloud が AKS クラスターで実行されたので、wasmCloud アプリケーションをデプロイできます。 wasmCloud アプリケーションは、wasmCloud Application Manager (wadm) によって調整される WebAssembly コンポーネントのコレクションです。
wasmCloud アプリケーション マニフェスト ファイルを作成します。 このファイルには、アプリケーションを構成するコンポーネントが記述されています。 次の yaml ファイルを
hello-world.yamlとして保存します。apiVersion: core.oam.dev/v1beta1 kind: Application metadata: name: hello-world annotations: description: 'HTTP hello world demo in Rust, using the WebAssembly Component Model and WebAssembly Interfaces Types (WIT)' spec: components: - name: http-component type: component properties: image: ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0 traits: # Govern the spread/scheduling of the component - type: spreadscaler properties: instances: 1 # Add a capability provider that enables HTTP access - name: httpserver type: capability properties: image: ghcr.io/wasmcloud/http-server:0.23.2 traits: # Establish a unidirectional link from this http server provider (the "source") # to the `http-component` component (the "target") so the component can handle incoming HTTP requests, # # The source (this provider) is configured such that the HTTP server listens on 0.0.0.0:8080 - type: link properties: target: http-component namespace: wasi package: http interfaces: [incoming-handler] source_config: - name: default-http properties: address: 0.0.0.0:8080washを使用して wasmCloud アプリケーションをデプロイします。wash app deploy hello-world.yaml出力は次のようになります。
Deployed application "hello-world", version "01JC44TVDBC2V6MJ1NJTKNNX1J"washを使用してアプリケーションが実行されていることを確認します。wash app status hello-world出力は次のようになります。
Name Kind Status http_component SpreadScaler Deployed httpserver -(wasi:http)-> http_component LinkScaler Deployed httpserver SpreadScaler Deployed必要に応じて、すべてのコンポーネントが
Deployed状態になるまで、このコマンドを繰り返します。curlとkubectl port-forwardを使用して http コンポーネントを呼び出します。別のシェルで、次のコマンドを実行して、
hello-worldアプリケーションに転送しますkubectl port-forward port-forward deployment/wasmcloud-host 8080このコマンドは、ポート 8080 上のすべてのトラフィックを、クラスターで実行されている wasmCloud ホストにローカルに転送します。
curlを使用して wasmCloud に接続するには、このポートを転送する必要があります。元のシェルで、次のコマンドを実行して http コンポーネントを呼び出します。
curl http://localhost:8080出力は次のようになります。
Hello from Rust!インストールされているリソースをクリーンアップする
作成したリソースをクリーンアップするには、次のコマンドを実行します。
kubectl delete namespace wasmcloudこのコマンドを実行すると、AKS クラスターから wasmCloud コンポーネントが削除されます。
次のステップ
引き続き学習するには、 wasmCloud クイック スタート ガイドに従ってください。このガイドでは、さまざまな wasmCloud 機能を使用し、アプリケーションをスケーリングして、WebAssembly コンポーネントを最初から作成する手順について説明します。