(O+P)ut

アウトプット



(O+P)ut

エンジニアのアウトプット

【OpenShift入門】アプリケーションの公開のためにrouteを作成する流れ

スポンサーリンク

はじめに

Kubernetesには無いリソースに「route」があり、routeとserviceを紐付けることでクラスター外から同サービスにFQDNでアクセスできるようなります。

本記事ではサービスをrouteにして外部公開する流れについて解説します。

環境情報
  • OpenShift Container Platform 4

事前情報

以下のプロジェクト内に

$ oc get project
NAME                                DISPLAY NAME   STATUS
test-route                            Active

以下のServiceと

$ oc get service
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)             AGE
helloworld   ClusterIP   172.X.X.X   <none>        8080/TCP ..

以下のそれに紐づくPodが存在する環境で

$ oc get ep
NAME             ENDPOINTS                             AGE
helloworld   10.X.X.X:8080  ..

同サービスに外部からアクセスさせたい場合を想定します。

routeを利用する作成

同プロジェクトにはrouteがない状態で

$ oc get route
No resources found in test-route namespace.

対象のサービス名を選択してoc expose serviceを実行すると

$ oc expose service helloworld
route.route.openshift.io/php-helloworld exposed

routeが新規生成されます。

$ oc get route
NAME             HOST/PORT                                                           PATH   SERVICES         PORT       TERMINATION   WILDCARD
helloworld   helloworld-test-route.apps.xx.com          helloworld   8080-tcp                 None

疎通確認

以下のようにステータス上も正常にrouteが動作している状態で

$ oc status
In project test-route on server https://api.xx.com:6443
http://helloworld-test-route.apps.xx.com to pod port 8080-tcp (svc/helloworld)
...
    deployment #1 deployed xx minutes ago - 1 pod

クラスターに属していない端末からcurlコマンドを打つと通信が可能です。

$ curl helloworld-test-route.apps.xx.com

試しにここでserviceのみを削除してみるとステータスの結果にroute情報が表示されず警告が出現し、

$ oc status
In project test-route on server https://api.xx.com:6443
...
  deployment #1 deployed xx minutes ago - 1 pod
1 warning, 2 infos identified, use 'oc status --suggest' to see details.

suggest情報を表示するとServiceが存在しない点が指摘され、疎通確認も確かに失敗します。

$ oc status --suggest
...
Warnings:
  * route/helloworld is supposed to route traffic to svc/php-helloworld but svc/php-helloworld doesn't exist.

尚、routeを作成する際に通信を暗号化する場合は以下のようなオプションの検討が必要です。

Available Commands:
  edge        Create a route that uses edge TLS termination
  passthrough Create a route that uses passthrough TLS termination
  reencrypt   Create a route that uses reencrypt TLS termination

終わりに

Kubernetesにはないrouteですが、実体は以下のPodがIngressとして存在しています。

# oc get pod --all-namespaces -l app=router

Openshiftにてサービスを公開する際に便利な機能なので同記事がハンズオンの参考になれば幸いです。