4.6. Python アプリケーションのデプロイ

以下の手順では、parksmap アプリケーション用にバックエンドサービスをデプロイします。Python アプリケーションは、MongoDB データベースに対して二次元地理空間クエリーを実行して、世界中のすべての国立公園を探して地図上の座標を返します。

デプロイされるバックエンドサービスは、nationalparks です。

前提条件

  • OpenShift Container Platform クラスターへのアクセス。
  • OpenShift CLI (oc) がインストールされている。
  • イメージがデプロイされている。

手順

  1. 新しい Python アプリケーションを作成するには、以下のコマンドを入力します。

    $ oc new-app python~https://github.com/openshift-roadshow/nationalparks-py.git --name nationalparks -l 'app=national-parks-app,component=nationalparks,role=backend,app.kubernetes.io/part-of=national-parks-app,app.kubernetes.io/name=python' --allow-missing-images=true

    出力例

    --> Found image 0406f6c (13 days old) in image stream "openshift/python" under tag "3.9-ubi8" for "python"
    
        Python 3.9
        ----------
        Python 3.9 available as container is a base platform for building and running various Python 3.9 applications and frameworks. Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
    
        Tags: builder, python, python39, python-39, rh-python39
    
        * A source build using source code from https://github.com/openshift-roadshow/nationalparks-py.git will be created
          * The resulting image will be pushed to image stream tag "nationalparks:latest"
          * Use 'oc start-build' to trigger a new build
    
    --> Creating resources with label app=national-parks-app,app.kubernetes.io/name=python,app.kubernetes.io/part-of=national-parks-app,component=nationalparks,role=backend ...
        imagestream.image.openshift.io "nationalparks" created
        buildconfig.build.openshift.io "nationalparks" created
        deployment.apps "nationalparks" created
        service "nationalparks" created
    --> Success

  2. アプリケーション nationalparks を公開するルートを作成するには、以下のコマンドを入力します。

    $ oc create route edge nationalparks --service=nationalparks

    出力例

    route.route.openshift.io/parksmap created

  3. 作成したアプリケーションのルートを取得するには、以下のコマンドを入力します。

    $ oc get route

    出力例

    NAME             HOST/PORT                                                           PATH   SERVICES        PORT       TERMINATION   WILDCARD
    nationalparks    nationalparks-user-getting-started.apps.cluster.example.com                nationalparks   8080-tcp   edge          None
    parksmap         parksmap-user-getting-started.apps.cluster.example.com                     parksmap        8080-tcp   edge          None

関連情報