アプリケーションのビルドとデプロイ
K8sへのデプロイ
このステップでは、Helmを使用してSplunk Distribution of the OpenTelemetry Collectorをk3dクラスターにデプロイします。
Kubernetesへのデプロイ #
プロジェクトルート [~/workshop/context-propagation] から以下を実行します
bash
make deployこのスクリプトは以下を実行します
deploy/k8s/にあるすべてのKubernetesマニフェストを適用する.envの認証情報からsplunk-otelSecretを作成する- デプロイメントをレジストリイメージに紐付ける
- すべてのロールアウトが完了するまで待機する
検証チェックリスト - デプロイ #
1. すべてのPodが実行中であることを確認 #
bash
kubectl -n cosmic-shop get podstext
NAME READY STATUS RESTARTS AGE
catalog-api-xxxxxxxxxx-xxxxx 1/1 Running 0 2m
frontend-xxxxxxxxxx-xxxxx 1/1 Running 0 2m
gateway-xxxxxxxxxx-xxxxx 1/1 Running 0 2m
order-worker-xxxxxxxxxx-xxxxx 1/1 Running 0 2m
rabbitmq-xxxxxxxxxx-xxxxx 1/1 Running 0 2m
splunk-otel-collector-agent-xxxxx 1/1 Running 0 10m
storefront-api-xxxxxxxxxx-xxxxx 1/1 Running 0 2m障害の指標:
| STATUS | 考えられる原因 |
|---|---|
ImagePullBackOff | イメージがプッシュされていない - make build を再実行してください |
CrashLoopBackOff | kubectl -n cosmic-shop logs deployment/<name> でログを確認してください |
Pending | クラスターリソースが不足 - kubectl describe pod <name> を確認してください |
2. ServiceとNodePortの確認 #
bash
kubectl -n cosmic-shop get svctext
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
catalog-api ClusterIP 10.43.xxx.xxx <none> 3002/TCP 2m
frontend NodePort 10.43.xxx.xxx <none> 80:30080/TCP 2m
gateway ClusterIP 10.43.xxx.xxx <none> 80/TCP 2m
order-worker ClusterIP 10.43.xxx.xxx <none> 3003/TCP 2m
rabbitmq NodePort 10.43.xxx.xxx <none> 5672:xxxxx/TCP,15672:15672/TCP 2m
storefront-api ClusterIP 10.43.xxx.xxx <none> 3001/TCP 2m3. バックエンドのヘルスエンドポイントの確認 #
bash
kubectl -n cosmic-shop exec deploy/frontend-api -- wget -qO- http://localhost:3007/health
kubectl -n cosmic-shop exec deploy/catalog-api -- wget -qO- http://localhost:3002/health
kubectl -n cosmic-shop exec deploy/order-api -- wget -qO- http://localhost:3001/healthjson
{"status":"ok","service":"frontend-api","stage":"bff"}
{"status":"ok","service":"catalog-api"}
{"status":"ok","service":"order-api","stage":"order"}4. ショップUIの応答確認 #
bash
curl -s -o /dev/null -w "HTTP %{http_code}\n" http://localhost:30080/
curl -s http://localhost:30080/ | head -5text
HTTP 200
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />5. Gateway経由でAPIカタログエンドポイントの確認 #
bash
curl -s http://localhost:30080/api/catalog | python3 -m json.tool | head -20json
{
"products": [
{
"id": "telescope-orion-8",
"name": "Orion 8\" Dobsonian Telescope",
"price": 449.99,
...
}
]
}6. RabbitMQ管理UIの確認 #
RabbitMQ Serviceは NodePort 15672 を使用しており、k3dがロードバランサーを通じて管理UIを公開できるようになっています。
k3dロードバランサーがポート15672をマッピングしていることを確認 #
bash
docker ps --filter name=k3d-cosmic-shop-serverlb --format '{{.Ports}}'text
0.0.0.0:30080->30080/tcp, 0.0.0.0:15672->15672/tcp, ...出力に 15672が含まれていない 場合、クラスターがRabbitMQのポートマッピングなしで作成されています。以下の「RabbitMQ UIが読み込めない場合」を参照してください。
HTTPの応答確認 #
bash
curl -s -o /dev/null -w "HTTP %{http_code}\n" http://localhost:15672/text
HTTP 200RabbitMQへのログイン(任意) #
ブラウザで http://(your-instance-url):15672 を開き、guest / guest でログインします。
RabbitMQ UIが読み込めない場合、別のターミナル でport-forwardを実行します(開いたままにしてください)
bash
kubectl -n cosmic-shop port-forward svc/rabbitmq 15672:15672その後、再度 http://(your-instance-url):15672 を開きます。
