CentOS Stream 8
Sponsored Link

OKD 4 : アプリケーションを展開する
OKD 4 クラスターでのアプリケーション展開の基本操作です。
事前に、ユーザー登録イメージレジストリーの設定 実施済みであることが前提です。
OKD 4 クラスターは以下の通り構成しています。
              |       |
+-------------+-------------+  |
|   [mgr.okd4.srv.world]    |  |
|        Manager Node       |  |
|           DNS             |  |
|          Nginx            |  |
+---------------------------+  |
              |                         |
+-------------+-------------+     +--------------+-------------+
| [master-0.okd4.srv.world] |     |   [node-0.okd4.srv.world]  |
|      Control Plane        |     |        Compute Node        |
|                           |     |                            |
|                           |     |                            |
+---------------------------+     +----------------------------+

[1] 任意のクライアントコンピューターで、登録済みのユーザーでログインし、アプリケーションを展開します。
# ログイン

[centos@client ~]$
oc login -u serverworld https://api.okd4.srv.world:6443

The server uses a certificate signed by an unknown authority.
You can bypass the certificate check, but any data you send to the server could be intercepted by others.
Use insecure connections? (y/n): y

Authentication required for https://api.okd4.srv.world:6443 (openshift)
Username: serverworld
Login successful.

You don't have any projects. You can try to create a new project, by running

    oc new-project <projectname>

Welcome! See 'oc help' to get started.

# [test-project] プロジェクト作成

[centos@client ~]$
oc new-project test-project

Now using project "test-project" on server "https://api.okd4.srv.world:6443".

You can add applications to this project with the 'new-app' command. For example, try:

    oc new-app rails-postgresql-example

to build a new example application in Ruby. Or use kubectl to deploy a simple Kubernetes application:

    kubectl create deployment hello-node --image=k8s.gcr.io/e2e-test-images/agnhost:2.33 -- /agnhost serve-hostname

# [rails-postgresql-example] アプリケーション デプロイ

[centos@client ~]$
oc new-app rails-postgresql-example

--> Deploying template "openshift/rails-postgresql-example" to project test-project

     Rails + PostgreSQL (Ephemeral)
     An example Rails application with a PostgreSQL database. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/rails-ex/blob/master/README.md.

     WARNING: Any data stored will be lost upon pod destruction. Only use this template for testing.

     The following service(s) have been created in your project: rails-postgresql-example, postgresql.

     For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/rails-ex/blob/master/README.md.

     * With parameters:
        * Name=rails-postgresql-example
        * Namespace=openshift
        * Memory Limit=512Mi
        * Memory Limit (PostgreSQL)=512Mi
        * Git Repository URL=https://github.com/sclorg/rails-ex.git
        * Git Reference=
        * Context Directory=
        * Application Hostname=
        * GitHub Webhook Secret=ojjEatN2qRC7JoMLXQ4F2VFySGNP3M1kAL1jn1di # generated
        * Secret Key=yxo10qp3rtatuwnkfm3lf3i3khkc0vjj0ju6x5gdunkwfwy018lvi0d08d07sqd216vxdkolpnde0dt2rw1a3vxktq0k53w35cqob1rwfsy5snp43m70pifye8ci1m5 # generated
        * Application Username=openshift
        * Application Password=secret
        * Rails Environment=production
        * Database Service Name=postgresql
        * Database Username=userHND # generated
        * Database Password=UUXvnLXw # generated
        * Database Name=root
        * Maximum Database Connections=100
        * Shared Buffer Amount=12MB
        * Custom RubyGems Mirror URL=

--> Creating resources ...
    secret "rails-postgresql-example" created
    service "rails-postgresql-example" created
    route.route.openshift.io "rails-postgresql-example" created
    imagestream.image.openshift.io "rails-postgresql-example" created
    buildconfig.build.openshift.io "rails-postgresql-example" created
    deploymentconfig.apps.openshift.io "rails-postgresql-example" created
    service "postgresql" created
    deploymentconfig.apps.openshift.io "postgresql" created
--> Success
    Access your application via route 'rails-postgresql-example-test-project.apps.okd4.srv.world'
    Build scheduled, use 'oc logs -f buildconfig/rails-postgresql-example' to track its progress.
    Run 'oc status' to view your app.

# ステータス確認

[centos@client ~]$
oc status

In project test-project on server https://api.okd4.srv.world:6443

svc/postgresql -
  dc/postgresql deploys openshift/postgresql:12-el8
    deployment #1 deployed 2 minutes ago - 1 pod

http://rails-postgresql-example-test-project.apps.okd4.srv.world (svc/rails-postgresql-example)
  dc/rails-postgresql-example deploys istag/rails-postgresql-example:latest <-
    bc/rails-postgresql-example source builds https://github.com/sclorg/rails-ex.git on openshift/ruby:2.6-ubi8
      build #1 running for 2 minutes - 7214e7c: Fix s2i assemble failing with Ruby 2.6. (Jarek Prokop ***)
    deployment #1 waiting on image or update

View details with 'oc describe <resource>/<name>' or list resources with 'oc get all'.

[centos@client ~]$
oc get pods

NAME                                  READY   STATUS      RESTARTS   AGE
postgresql-1-deploy                   0/1     Completed   0          17m
postgresql-1-nv5kw                    1/1     Running     0          17m
rails-postgresql-example-1-build      0/1     Completed   0          17m
rails-postgresql-example-1-deploy     0/1     Completed   0          12m
rails-postgresql-example-1-dfhjq      1/1     Running     0          12m
rails-postgresql-example-1-hook-pre   0/1     Completed   0          12m

[centos@client ~]$
oc describe svc/rails-postgresql-example

Name:              rails-postgresql-example
Namespace:         test-project
Labels:            app=rails-postgresql-example
Annotations:       description: Exposes and load balances the application pods
                   openshift.io/generated-by: OpenShiftNewApp
                   service.alpha.openshift.io/dependencies: [{"name": "postgresql", "kind": "Service"}]
Selector:          name=rails-postgresql-example
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
Port:              web  8080/TCP
TargetPort:        8080/TCP
Session Affinity:  None
Events:            <none>

# サービスへのアクセスパス確認

[centos@client ~]$
oc get routes

NAME                       HOST/PORT                                                   PATH   SERVICES                   PORT    TERMINATION   WILDCARD
rails-postgresql-example   rails-postgresql-example-test-project.apps.okd4.srv.world          rails-postgresql-example   >all<                 None

# アプリケーションを削除する場合は以下

[centos@client ~]$
oc delete all -l app=rails-postgresql-example

  表示された URL にアクセスできれば OK です。