第3章 Skupper を使用した ActiveMQ へのアクセス
パブリッククラウドリソースを使用してプライベートメッセージブローカーからのデータを処理します。
この例は、Skupper を使用してクラウドプロバイダー、データセンター、エッジサイト間でサービスを接続できるさまざまな方法を紹介する 一連の例 の一部です。
概要
この例は、Skupper を使用して、パブリックインターネットに公開せずにリモートサイトの ActiveMQ ブローカーにアクセスする方法を示したシンプルなメッセージングアプリケーションです。
これには 2 つのサービスが含まれます。
- プライベートデータセンターで実行されている ActiveMQ ブローカー。ブローカーには、"notifications" という名前のキューがあります。
- パブリッククラウドで実行している AMQP クライアント。"notifications" に 10 個のメッセージを送信し、再度受信します。
この例では、ブローカーとして ArtemisCloud.io の Apache ActiveMQ Artemis イメージを使用します。クライアントはシンプルな Quarkus アプリケーションです。
この例では、プライベートデータセンターとパブリッククラウドを表すために、"private" と "public" という 2 つの Kubernetes 名前空間を使用します。
手順
- この例のリポジトリーのクローンを作成する
- Skupper コマンドラインツールをインストールする
- 名前空間を設定する
- メッセージブローカーをデプロイする
- サイトを作成する
- サイトをリンクする
- メッセージブローカーを公開する
- この例のリポジトリーをクローンします。https://skupper.io/examples/index.html から適切な GitHub リポジトリーに移動し、リポジトリーをクローンします。
Skupper コマンドラインツールをインします。
この例では、Skupper コマンドラインツールを使用して Skupper をデプロイします。開発環境ごとに
skupper
コマンドを 1 回だけインストールする必要があります。CLI のインストールの詳細は、インストール を参照してください。設定されたシステムの場合は、次のコマンドを使用します。
sudo dnf install skupper-cli
sudo dnf install skupper-cli
Copy to Clipboard Copied! 名前空間を設定します。
Skupper は、通常は異なるクラスター上の複数の Kubernetes 名前空間で使用するように設計されています。
skupper
コマンドとkubectl
コマンドは、kubeconfig と現在のコンテキストを使用して、動作する名前空間を選択します。kubeconfig はホームディレクトリーのファイルに保存されます。
skupper
およびkubectl
コマンドは、KUBECONFIG
環境変数を使用してこれを検索します。1 つの kubeconfig は、ユーザーごとにアクティブコンテキストを 1 つだけサポートします。この演習では複数のコンテキストを一度に使用するため、個別の kubeconfig を作成する必要があります。
名前空間ごとに、新しいターミナルウィンドウを開きます。各ターミナルで、
KUBECONFIG
環境変数を別のパスに設定し、クラスターにログインします。次に、使用する名前空間を作成し、現在のコンテキストに名前空間を設定します。注記ログイン手順はプロバイダーによって異なります。以下のドキュメントを参照してください。
パブリック:
export KUBECONFIG=~/.kube/config-public # Enter your provider-specific login command kubectl create namespace public kubectl config set-context --current --namespace public
export KUBECONFIG=~/.kube/config-public # Enter your provider-specific login command kubectl create namespace public kubectl config set-context --current --namespace public
Copy to Clipboard Copied! プライベート:
export KUBECONFIG=~/.kube/config-private # Enter your provider-specific login command kubectl create namespace private kubectl config set-context --current --namespace private
export KUBECONFIG=~/.kube/config-private # Enter your provider-specific login command kubectl create namespace private kubectl config set-context --current --namespace private
Copy to Clipboard Copied! メッセージブローカーをデプロイします。
プライベートでは、
kubectl apply
コマンドを使用してブローカーをインストールします。プライベート:
kubectl apply -f server
kubectl apply -f server
Copy to Clipboard Copied! 出力サンプル
kubectl apply -f server
$ kubectl apply -f server deployment.apps/broker created
Copy to Clipboard Copied! サイトを作成します。
Skupper サイトは、アプリケーションのコンポーネントが実行される場所です。サイトは相互にリンクされ、アプリケーションのネットワークを形成します。Kubernetes では、サイトは名前空間に関連付けられます。
名前空間ごとに、
skupper init
を使用してサイトを作成します。これにより、Skupper ルーターとコントローラーがデプロイされます。次に、skupper status
を使用して結果を確認します。パブリック:
skupper init skupper status
skupper init skupper status
Copy to Clipboard Copied! 出力サンプル
skupper init skupper status
$ skupper init Waiting for LoadBalancer IP or hostname... Waiting for status... Skupper is now installed in namespace 'public'. Use 'skupper status' to get more information. $ skupper status Skupper is enabled for namespace "public". It is not connected to any other sites. It has no exposed services.
Copy to Clipboard Copied! プライベート:
skupper init skupper status
skupper init skupper status
Copy to Clipboard Copied! 出力サンプル
skupper init skupper status
$ skupper init Waiting for LoadBalancer IP or hostname... Waiting for status... Skupper is now installed in namespace 'private'. Use 'skupper status' to get more information. $ skupper status Skupper is enabled for namespace "private". It is not connected to any other sites. It has no exposed services.
Copy to Clipboard Copied! 以下の手順を実行する場合は、いつでも
skupper status
を使用して進捗状況を確認できます。サイトをリンクします。
Skupper リンクは、2 つのサイト間の通信チャネルです。リンクは、アプリケーションの接続と要求のトランスポートとして機能します。
リンクを作成するには、
skupper token create
とskupper link create
の 2 つのskupper
コマンドを組み合わせて使用する必要があります。skupper token create
コマンドは、リンクを作成する権限を示す秘密トークンを生成します。トークンにはリンクの詳細も含まれます。次に、リモートサイトで、skupper link create
コマンドを実行すると、トークンを使用して、トークンを生成したサイトへのリンクを作成します。注記リンクトークンは実際にはシークレットです。トークンがある場合は、サイトにリンクできます。信頼できる人だけがアクセスできるようにしてください。
まず、パブリックサイトの
skupper token create
を使用してトークンを生成します。次に、プライベートサイトでskupper link create
を使用して、サイトをリンクします。パブリック:
skupper token create ~/secret.token
skupper token create ~/secret.token
Copy to Clipboard Copied! 出力サンプル
skupper token create ~/secret.token
$ skupper token create ~/secret.token Token written to ~/secret.token
Copy to Clipboard Copied! プライベート:
skupper link create ~/secret.token
skupper link create ~/secret.token
Copy to Clipboard Copied! 出力サンプル
skupper link create ~/secret.token
$ skupper link create ~/secret.token Site configured to link to https://10.105.193.154:8081/ed9c37f6-d78a-11ec-a8c7-04421a4c5042 (name=link1) Check the status of the link using 'skupper link status'.
Copy to Clipboard Copied! ターミナルセッションが異なるマシン上にある場合は、トークンを安全に転送するために
scp
または同様のツールを使用する必要がある場合があります。デフォルトでは、トークンは 1 回の使用後、または作成後 15 分後に期限切れになります。メッセージブローカーを公開します。
プライベートでは、
skupper expose
を使用して、ブローカーを Skupper ネットワーク上に公開します。次に、Public で
kubectl get service/broker
を使用して、しばらくするとサービスが表示されることを確認します。プライベート:
skupper expose deployment/broker --port 5672
skupper expose deployment/broker --port 5672
Copy to Clipboard Copied! 出力サンプル
skupper expose deployment/broker --port 5672
$ skupper expose deployment/broker --port 5672 deployment broker exposed as broker
Copy to Clipboard Copied! パブリック:
kubectl get service/broker
kubectl get service/broker
Copy to Clipboard Copied! 出力サンプル
kubectl get service/broker
$ kubectl get service/broker NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE broker ClusterIP 10.100.58.95 <none> 5672/TCP 2s
Copy to Clipboard Copied! クライアントを実行します。
パブリックでは、
kubectl run
を使用してクライアントを実行します。パブリック:
kubectl run client --attach --rm --restart Never --image quay.io/skupper/activemq-example-client --env SERVER=broker
kubectl run client --attach --rm --restart Never --image quay.io/skupper/activemq-example-client --env SERVER=broker
Copy to Clipboard Copied! 出力サンプル
kubectl run client --attach --rm --restart Never --image quay.io/skupper/activemq-example-client --env SERVER=broker
$ kubectl run client --attach --rm --restart Never --image quay.io/skupper/activemq-example-client --env SERVER=broker ____ __ _____ ___ __ ____ ____ --/ __ \/ / / / _ | / _ \/ //_/ / / / / -/ /_/ / /_/ / __ |/ , / ,< / // /\ \ --\___\_\____/_/ |_/_/|_/_/|_|\____/_/ 2022-05-27 11:19:07,149 INFO [io.sma.rea.mes.amqp] (main) SRMSG16201: AMQP broker configured to broker:5672 for channel incoming-messages 2022-05-27 11:19:07,170 INFO [io.sma.rea.mes.amqp] (main) SRMSG16201: AMQP broker configured to broker:5672 for channel outgoing-messages 2022-05-27 11:19:07,198 INFO [io.sma.rea.mes.amqp] (main) SRMSG16212: Establishing connection with AMQP broker 2022-05-27 11:19:07,212 INFO [io.sma.rea.mes.amqp] (main) SRMSG16212: Establishing connection with AMQP broker 2022-05-27 11:19:07,215 INFO [io.quarkus] (main) client 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.9.2.Final) started in 0.397s. 2022-05-27 11:19:07,215 INFO [io.quarkus] (main) Profile prod activated. 2022-05-27 11:19:07,215 INFO [io.quarkus] (main) Installed features: [cdi, smallrye-context-propagation, smallrye-reactive-messaging, smallrye-reactive-messaging-amqp, vertx] Sent message 1 Sent message 2 Sent message 3 Sent message 4 Sent message 5 Sent message 6 Sent message 7 Sent message 8 Sent message 9 Sent message 10 2022-05-27 11:19:07,434 INFO [io.sma.rea.mes.amqp] (vert.x-eventloop-thread-0) SRMSG16213: Connection with AMQP broker established 2022-05-27 11:19:07,442 INFO [io.sma.rea.mes.amqp] (vert.x-eventloop-thread-0) SRMSG16213: Connection with AMQP broker established 2022-05-27 11:19:07,468 INFO [io.sma.rea.mes.amqp] (vert.x-eventloop-thread-0) SRMSG16203: AMQP Receiver listening address notifications Received message 1 Received message 2 Received message 3 Received message 4 Received message 5 Received message 6 Received message 7 Received message 8 Received message 9 Received message 10 Result: OK
Copy to Clipboard Copied!