2.3.5.7. Ingress Controller シャーディングのルート作成
ルートを使用すると、アプリケーションを URL でホストできます。Ingress Controller のシャーディングは、一連の Ingress Controller 間での着信トラフィック負荷のバランスをとるのに役立ちます。Ingress Controller のシャーディング機能を使用すると、トラフィックを特定の Ingress Controller に分離することもできます。たとえば、Company A のトラフィックをある Ingress Controller に指定し、Company B を別の Ingress Controller に指定できます。
以下の手順では、例として hello-openshift アプリケーションを使用して、Ingress Controller シャーディングのルートを作成する方法を説明します。
前提条件
-
OpenShift CLI (
oc) がインストールされている。 - プロジェクト管理者としてログインしている。
- ポートを公開する Web アプリケーションと、そのポート上のトラフィックをリッスンする HTTP または TLS エンドポイントがある。
- シャーディング用に Ingress Controller を設定している。
手順
次のコマンドを実行して、
hello-openshiftというプロジェクトを作成します。$ oc new-project hello-openshift以下のコマンドを実行してプロジェクトに Pod を作成します。
$ oc create -f https://raw.githubusercontent.com/openshift/origin/master/examples/hello-openshift/hello-pod.json以下のコマンドを実行して、
hello-openshiftというサービスを作成します。$ oc expose pod/hello-openshifthello-openshift-route.yamlというルート定義を作成します。シャーディング用に作成したルートの YAML 定義
apiVersion: route.openshift.io/v1 kind: Route metadata: labels: type: sharded name: hello-openshift-edge namespace: hello-openshift spec: subdomain: hello-openshift tls: termination: edge to: kind: Service name: hello-openshift各項目の説明:
type-
ラベルキーとその対応するラベル値は、Ingress Controller で指定されたものと一致する必要があることを指定します。この例では、Ingress Controller にはラベルキーと値
type: shardedがあります。 subdomain-
サブドメインフィールドの値を使用して公開されるルートを指定します。subdomainフィールドを指定するときは、ホスト名を未設定のままにしておく必要があります。ホストフィールドとサブドメインフィールドの両方を指定した場合、ルートはホストフィールドの値を使用し、サブドメインフィールドは無視します。
次のコマンドを実行し、
hello-openshift-route.yamlを使用してhello-openshiftアプリケーションへのルートを作成します。$ oc -n hello-openshift create -f hello-openshift-route.yaml
検証
次のコマンドを使用して、ルートのステータスを取得します。
$ oc -n hello-openshift get routes/hello-openshift-edge -o yaml結果の
Routeリソースは次のようになります。出力例
apiVersion: route.openshift.io/v1 kind: Route metadata: labels: type: sharded name: hello-openshift-edge namespace: hello-openshift spec: subdomain: hello-openshift tls: termination: edge to: kind: Service name: hello-openshift status: ingress: - host: hello-openshift.<apps-sharded.basedomain.example.net> routerCanonicalHostname: router-sharded.<apps-sharded.basedomain.example.net> routerName: sharded各項目の説明:
host-
イングレスコントローラー (ルーター) がルートを公開するために使用するホスト名を指定します。
hostフィールドの値は、Ingress Controller によって自動的に決定され、そのドメインを使用します。この例では、Ingress Controller のドメインは<apps-sharded.basedomain.example.net>です。 <apps-sharded.basedomain.example.net>- Ingress コントローラーのホスト名を指定します。ホスト名が設定されていない場合、ルートは代わりにサブドメインを使用できます。サブドメインを指定すると、ルートを公開する Ingress Controller のドメインが自動的に使用されます。ルートが複数の Ingress Controller によって公開される場合、ルートは複数の URL でホストされます。
routerName-
Ingress コントローラーの名前を指定します。この例では、Ingress Controller の名前は
shardedです。