このガイドでは、明示的な SMI traffic access policiesを必要とせずに、サービスディスカバリを使用してアプリケーション接続を設定する、osm-edge の 許容なトラフィックポリシー モードを使用して通信する、サービスメッシュ内のクライアントおよびサーバー アプリケーションについて説明する。
前提条件
- Kubernetesv1.19.0あるいはそれより高いバージョンを実行しているKubernetesクラスター。
- osm-edgeはインストールされている。
- API サーバーとやり取りするための
kubectl
は使用可能。 - サービスメッシュを管理するための
osm
CLIは使用可能。
デモ
次のデモは、許容なトラフィックポリシーモードを使用して、HTTP 「curl」クライアントが「httpbin」サービスに HTTP リクエストを送信する様子を示す。
-
許可モードが有効になっていない場合は有効にする。
export osm_namespace=osm-system # Replace osm-system with the namespace where osm-edge is installed kubectl patch meshconfig osm-mesh-config -n "$osm_namespace" -p '{"spec":{"traffic":{"enablePermissiveTrafficPolicyMode":true}}}' --type=merge
-
名前空間をメッシュに登録した後、「httpbin」サービスを「httpbin」名前空間にデプロイする。
httpbin
サービスはポート14001
で実行される。# Create the httpbin namespace kubectl create namespace httpbin # Add the namespace to the mesh osm namespace add httpbin # Deploy httpbin service in the httpbin namespace kubectl apply -f https://raw.githubusercontent.com/openservicemesh/osm-docs/release-v1.1/manifests/samples/httpbin/httpbin.yaml -n httpbin
「httpbin」サービスとポッドが稼働中であることを確認する。
$ kubectl get svc -n httpbin NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE httpbin ClusterIP 10.96.198.23 <none> 14001/TCP 20s
$ kubectl get pods -n httpbin NAME READY STATUS RESTARTS AGE httpbin-5b8b94b9-lt2vs 2/2 Running 0 20s
-
その名前空間をメッシュに登録した後、
curl
クライアントをcurl
名前空間にデプロイする。# Create the curl namespace kubectl create namespace curl # Add the namespace to the mesh osm namespace add curl # Deploy curl client in the curl namespace kubectl apply -f https://raw.githubusercontent.com/openservicemesh/osm-docs/release-v1.1/manifests/samples/curl/curl.yaml -n curl
curl
クライアントポッドが稼働中であることを確認する。$ kubectl get pods -n curl NAME READY STATUS RESTARTS AGE curl-54ccc6954c-9rlvp 2/2 Running 0 20s
-
curl
クライアントがポート14001
でhttpbin
サービスにアクセスできることを確認する。$ kubectl exec -n curl -ti "$(kubectl get pod -n curl -l app=curl -o jsonpath='{.items[0].metadata.name}')" -c curl -- curl -I http://httpbin.httpbin:14001 HTTP/1.1 200 OK server: gunicorn/19.9.0 date: Wed, 29 Jun 2022 08:50:33 GMT content-type: text/html; charset=utf-8 content-length: 9593 access-control-allow-origin: * access-control-allow-credentials: true connection: keep-alive
「200 OK」応答は、「curl」クライアントから「httpbin」サービスへの HTTP リクエストが成功したことを示す。
-
許容なトラフィックポリシー モードが無効になっている場合、HTTP リクエストが失敗することを確認する。
kubectl patch meshconfig osm-mesh-config -n "$osm_namespace" -p '{"spec":{"traffic":{"enablePermissiveTrafficPolicyMode":false}}}' --type=merge
$ kubectl exec -n curl -ti "$(kubectl get pod -n curl -l app=curl -o jsonpath='{.items[0].metadata.name}')" -c curl -- curl -I http://httpbin.httpbin:14001 curl: (7) Failed to connect to httpbin.httpbin port 14001: Connection refused command terminated with exit code 7
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.