-
Notifications
You must be signed in to change notification settings - Fork 0
DNET_OpenShiftSecondStep
-
戻る
- OpenShiftファースト・ステップ
- OpenShiftセカンド・ステップ
-
「ファースト・ステップ」(OpenShiftファースト・ステップ)では、
基本的操作とJBossアプリケーションのデプロイを行った。 -
「セカンド・ステップ」では、
ASP.NET Coreアプリケーションのデプロイを行う。 -
必要であればローカルに.NET Coreが必要(ASP.NET Coreの開発を参照)。
-
いきなり
「まずは手順に従って、imagestreamを設定するのですが、
最初は検証用のプロジェクトを作ってそのプロジェクトに
imagestreamを作ってみましょう。」とあって、「imagestream」(OpenShiftの該当節を参照)なんて
「ファースト・ステップ」で出てきてないので、
潔く「Red Hat Customer Portal」を読むことに。 -
「ファースト・ステップ」のツールのバージョンが
古いようなので、新しいバージョンを取得する。
https://github.com/openshift/origin/releases
※ 以下、Image Streams / サービス / Build Configuration は OpenShift の該当節を参照。
-
既に OpenShift の一部である場合がある。
-
次のコマンドで、名前空間で使用可能なdotnetを一覧表示する。
>oc describe is dotnet --namespace openshift Name: dotnet Namespace: openshift Created: 51 minutes ago Labels: <none> Annotations: openshift.io/display-name=.NET Core Builder Images openshift.io/image.dockerRepositoryCheck=2018-06-05T02:51:14Z Docker Pull Spec: docker-registry.default.svc:5000/openshift/dotnet Unique Images: 3 Tags: 4 2.0 (latest) tagged from registry.access.redhat.com/dotnet/dotnet-20-rhel7:2.0 Build and run .NET Core 2.0 applications on RHEL 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/redhat-developer/s2i-dotnetcore/tree/master/2.0/build/README.md. Tags: builder, .net, dotnet, dotnetcore, rh-dotnet20 Supports: dotnet:2.0, dotnet Example Repo: https://github.com/redhat-developer/s2i-dotnetcore-ex.git * registry.access.redhat.com/dotnet/dotnet-20-rhel7@sha256:1314e7693a0eb07f5d699f5c0eb878f2e7b92200d0a3e31b6a3dad235efad5c8 51 minutes ago 1.1 tagged from registry.access.redhat.com/dotnet/dotnetcore-11-rhel7:1.1 Build and run .NET Core 1.1 applications on RHEL 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/redhat-developer/s2i-dotnetcore/tree/master/1.1/README.md. Tags: builder, .net, dotnet, dotnetcore, rh-dotnetcore11 Supports: dotnet:1.1, dotnet Example Repo: https://github.com/redhat-developer/s2i-dotnetcore-ex.git * registry.access.redhat.com/dotnet/dotnetcore-11-rhel7@sha256:6016edaadc99a516aa0d3d1db22a5384739647bcd8cc6a3420d793e214e62c43 51 minutes ago 1.0 tagged from registry.access.redhat.com/dotnet/dotnetcore-10-rhel7:1.0 Build and run .NET Core 1.0 applications on RHEL 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/redhat-developer/s2i-dotnetcore/tree/master/1.0/README.md. Tags: builder, .net, dotnet, dotnetcore, rh-dotnetcore10 Supports: dotnet:1.0, dotnet Example Repo: https://github.com/redhat-developer/s2i-dotnetcore-ex.git * registry.access.redhat.com/dotnet/dotnetcore-10-rhel7@sha256:51b354a03dba498c3ea505c0aa9e3d864da6331c17eea02af0f3f89b48f375be 51 minutes ago
希望のバージョンがない場合、Image Streamsを追加できる。
>oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/dotnet_imagestreams.json
権限があれば、Image Streamsをグローバルに追加できる。
>oc create --namespace openshift -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/dotnet_imagestreams.json
github.comのredhat-developer/s2i-dotnetcore-exの
dotnetcore-2.0ブランチのaspnetcore2アプリをappフォルダにデプロイする。
(dotnet:2.0で)読み込んだImage Streamsと紐付け?
>oc new-app --name=exampleapp 'dotnet:2.0~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-2.0' --build-env DOTNET_STARTUP_PROJECT=app
>oc logs -f bc/exampleapp
>oc expose svc/exampleapp
>oc get routes
-
.NET Coreイメージは、.NET Core用の環境変数をサポートしている。
-
これらの変数は、
- ビルド構成の一部として設定することも、
- リポジトリの「.s2i/environment」ファイルに追加することも
できる。
| # | 名前 | 説明 | 既定値 |
|---|---|---|---|
| 1 | DOTNET_STARTUP_PROJECT | プロジェクト・ファイルを含むフォルダ | |
| 2 | DOTNET_ASSEMBLY_NAME | アセンブリ名(.dll拡張子を含めない) | プロジェクト・ファイル名 |
| 3 | DOTNET_RESTORE_SOURCES | NuGetパッケージソースのスペース区切りリスト。NuGet.configを上書き。 | Unset |
| 4 | DOTNET_NPM_TOOLS | NPMパッケージのリスト | Unset |
| 5 | DOTNET_TEST_PROJECTS | テストプロジェクトのフォルダのリスト | Unset |
| 6 | DOTNET_CONFIGURATION | リリースモード(Release)/デバッグモード(Debug) | Release |
| 7 | ASPNETCORE_URLS | 公開ポート(OpenShiftに於いて変更は非推奨) | http://*:8080 |
3つのサンプルアプリケーションが利用可能
| # | 名前 | 説明 |
|---|---|---|
| 1 | dotnet-example | デフォルトのMVCアプリケーション |
| 2 | dotnet-runtime-example | ランタイム・イメージとビルド・チェーンを使用して MVCアプリをビルドする方法を示す。 |
| 3 | dotnet-pgsql-persistent | Music Storeサンプルアプリケーション |
-
ポータルを使用
- プロジェクトを参照
- [プロジェクトに追加]をクリック
-
CLIを使用
-
プロジェクトに追加
-
dotnet-example
>oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-example.json -
dotnet-runtime-example
>oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-runtime-example.json -
dotnet-pgsql-persistent.json
>oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-pgsql-persistent.json
-
-
グローバルに追加
-
dotnet-example
>oc create -n openshift -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-example.json >oc replace -n openshift -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-example.json -
dotnet-runtime-example
>oc create -n openshift -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-runtime-example.json >oc replace -n openshift -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-runtime-example.json -
dotnet-pgsql-persistent.json
>oc create -n openshift -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-pgsql-persistent.json >oc replace -n openshift -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-pgsql-persistent.json
-
-
-
chaining-buildsのBuild Configuration(OpenShiftの該当節を参照)は、
dotnet-runtime-example templateが参考になる。 -
このテンプレートでは、
- 「*-build」と
- 「*-runtime」の
Build Configuration を定義する。
-
GitHubプロジェクトから構築され、
-
変更を自動的に再構築するトリガを持つ。
- プロジェクトが変更されたとき
- またはベース・イメージ(dotnet-20-rhel7)が更新されたとき
-
dotnet-20-runtime-rhel7ベース・イメージから構築される。
- ビルド・イメージからtar.gzファイルを取得。
- ビルド設定でこのソース定義を使用。
-
変更を自動的に再構築するトリガを持つ。
- プロジェクトの内部Image Streamsでビルドイメージが更新されたとき、
- またはdotnet-20-runtime-rhel7ベースイメージが更新されたときに、
-
ランタイムイメージ用に定義されたデプロイメントを持つ。
- ビルドイメージにはデプロイメントは必要ない。
トリガを使用すると、イメージやコードが更新されたときに、
チェーン内のオブジェクトが必要に応じて再構築される。
-
ログイン
>oc login https://opnshdnsxx.centralus.cloudapp.azure.com --token=XXXXX
-
プロジェクトを生成
>oc new-project pj11 -
Image Streamsの読込。
>oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/dotnet_imagestreams.json imagestream "dotnet" created imagestream "dotnet-runtime" created -
アプリケーションを生成
>oc new-app --name=exampleapp "dotnet:2.0~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-2.0" --build-env DOTNET_STARTUP_PROJECT=app --> Found image 98871f3 (8 days old) in image stream "pj11/dotnet" under tag "2.0" for "dotnet:2.0" .NET Core 2.0 ------------- Platform for building and running .NET Core 2.0 applications Tags: builder, .net, dotnet, dotnetcore, rh-dotnet20 * A source build using source code from https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-2.0 will be created * The resulting image will be pushed to image stream "exampleapp:latest" * Use 'start-build' to trigger a new build * This image will be deployed in deployment config "exampleapp" * Port 8080/tcp will be load balanced by service "exampleapp" * Other containers can access this service through the hostname "exampleapp" --> Creating resources ... imagestream "exampleapp" created buildconfig "exampleapp" created deploymentconfig "exampleapp" created service "exampleapp" created --> Success Build scheduled, use 'oc logs -f bc/exampleapp' to track its progress. Run 'oc status' to view your app. -
進行状況の確認
>oc logs -f bc/exampleapp Cloning "https://github.com/redhat-developer/s2i-dotnetcore-ex" ... Commit: 0543be02d0be779d08e6c43f82ef9f0610f5d4e3 (Update for .NET Core 2.0 release. (#32)) Author: Severin Gehwolf <jerboaa@gmail.com> Date: Mon Aug 21 18:00:03 2017 +0200 Using SDK: 2.0.3 ---> Copying application source ... ---> Restoring application dependencies... Restoring packages for /opt/app-root/src/app/app.csproj... Restoring packages for /opt/app-root/src/app/app.csproj... Installing System.Xml.XmlSerializer 4.0.11. ・・・ Generating MSBuild file /opt/app-root/src/app/obj/app.csproj.nuget.g.props. Generating MSBuild file /opt/app-root/src/app/obj/app.csproj.nuget.g.targets. Restore completed in 20.24 sec for /opt/app-root/src/app/app.csproj. ---> Publishing application... Microsoft (R) Build Engine version 15.4.8.50081 for .NET Core Copyright (C) Microsoft Corporation. All rights reserved. app -> /opt/app-root/src/app/bin/Release/netcoreapp2.0/app.dll app -> /opt/app-root/app/ Pushing image docker-registry.default.svc:5000/pj11/exampleapp:latest ... Pushed 0/5 layers, 5% complete Pushed 1/5 layers, 30% complete Pushed 2/5 layers, 44% complete Pushed 3/5 layers, 79% complete Pushed 4/5 layers, 96% complete Pushed 5/5 layers, 100% complete Push successful -
サービスのルートを作成する。
>oc get routes No resources found. >oc expose svc/exampleapp route "exampleapp" exposed >oc get routes NAME HOST/PORT PATH SERVICES PORT TERMINATION exampleapp exampleapp-pj11.XXX.XXX.XXX.XXX.nip.io exampleapp 8080-tcp None -
サービスにアクセスする。
プレーンなMVCアプリが起動する。
-
プロジェクトを生成
>oc new-project pj12 -
テンプレートの読込
>oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-example.json template "dotnet-example" created -
アプリケーションを生成
>oc new-app dotnet-example --name=exampleapp --> Deploying template "openshift/dotnet-example" to project pj12 .NET Core Example --------- An example .NET Core application. * With parameters: * Name=dotnet-example * Memory Limit=512Mi * .NET builder=dotnet:2.0 * Namespace=openshift * Git Repository URL=https://github.com/redhat-developer/s2i-dotnetcore-ex.git * Git Reference=dotnetcore-2.0 * Context Directory= * Application Hostname= * GitHub Webhook Secret=Hagf1B7MCijAH1myO8dWjQRcMvl8Xs3WwrfoK2WB # generated * Generic Webhook Secret=FjstfIOXLbWdFixVqo0cyJ5qT1gUDbyBpqgSocs0 # generated * Startup Project=app * Startup Assembly= * Npm Tools=bower gulp * Test projects= * Configuration=Release * NuGet package sources= --> Creating resources ... route "dotnet-example" created service "dotnet-example" created imagestream "dotnet-example" created buildconfig "dotnet-example" created deploymentconfig "dotnet-example" created --> Success Build scheduled, use 'oc logs -f bc/dotnet-example' to track its progress. Run 'oc status' to view your app. -
進行状況の確認
>oc logs -f bc/dotnet-example C:\Users\nishi>oc logs -f bc/dotnet-example Cloning "https://github.com/redhat-developer/s2i-dotnetcore-ex.git" ... Commit: 0543be02d0be779d08e6c43f82ef9f0610f5d4e3 (Update for .NET Core 2.0 release. (#32)) Author: Severin Gehwolf <jerboaa@gmail.com> Date: Mon Aug 21 18:00:03 2017 +0200 ---> Installing npm tools ... ・・・ ---> Copying application source ... ---> Restoring application dependencies... Restoring packages for /opt/app-root/src/app/app.csproj... Restoring packages for /opt/app-root/src/app/app.csproj... Installing System.Xml.XmlSerializer 4.0.11. ・・・ Generating MSBuild file /opt/app-root/src/app/obj/app.csproj.nuget.g.props. Generating MSBuild file /opt/app-root/src/app/obj/app.csproj.nuget.g.targets. Restore completed in 20.62 sec for /opt/app-root/src/app/app.csproj. ---> Publishing application... Microsoft (R) Build Engine version 15.4.8.50081 for .NET Core Copyright (C) Microsoft Corporation. All rights reserved. app -> /opt/app-root/src/app/bin/Release/netcoreapp2.0/app.dll app -> /opt/app-root/app/ Pushing image docker-registry.default.svc:5000/pj12/dotnet-example:latest ... Pushed 4/5 layers, 82% complete Pushed 5/5 layers, 100% complete Push successful -
サービスのルートを確認。
>oc get routes NAME HOST/PORT PATH SERVICES PORT TERMINATION dotnet-example dotnet-example-pj12.XXX.XXX.XXX.XXX.nip.io dotnet-example <all> -
サービスにアクセスする。
プレーンなMVCアプリが起動する。
-
プロジェクトを生成
>oc new-project pj2 -
テンプレートの読込
>oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-runtime-example.json template "dotnet-runtime-example" created -
アプリケーションを生成
>oc new-app dotnet-runtime-example --name=runtimeexampleapp -
進行状況の確認
>oc logs -f bc/dotnet-runtime-example-build >oc logs -f bc/dotnet-runtime-example-runtime -
サービスのルートを確認。
>oc get routes NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD dotnet-runtime-example dotnet-runtime-example-pj2.XXX.XXX.XXX.XXX.nip.io dotnet-runtime-example <all> None -
サービスにアクセスする。
プレーンなMVCアプリが起動する。
-
プロジェクトを生成
>oc new-project pj3 -
テンプレートの読込
>oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-pgsql-persistent.json template "dotnet-pgsql-persistent" created -
アプリケーションを生成
>oc new-app dotnet-pgsql-persistent --name=persistentapp -
進行状況の確認
>oc logs -f bc/musicstore -
サービスのルートを確認。
>oc get routes NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD musicstore musicstore-pj3.XXX.XXX.XXX.XXX.nip.io musicstore <all> None -
エラーになって起動できない。
>oc get pods NAME READY STATUS RESTARTS AGE musicstore-1-build 0/1 Completed 0 16m musicstore-1-deploy 0/1 Error 0 14m postgresql-1-deploy 0/1 Error 0 16m -
サービスにアクセスする。
musicstoreアプリが起動するハズだったが...。
https://github.com/daisukenishino2/opneshift
-
プロジェクトを生成
>oc new-project pj4 -
Image Streamsの読込。
>oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/dotnet_imagestreams.json imagestream "dotnet" created imagestream "dotnet-runtime" created -
アプリケーションを生成
>oc new-app --name=daisukenishino2opneshift "dotnet:2.0~https://github.com/daisukenishino2/opneshift#master" --build-env DOTNET_STARTUP_PROJECT=WebApplication1 -
進行状況の確認
>oc logs -f bc/daisukenishino2opneshift -
サービスのルートを作成する。
>oc get routes No resources found. >oc expose svc/daisukenishino2opneshift route "daisukenishino2opneshift" exposed >oc get routes NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD daisukenishino2opneshift daisukenishino2opneshift-pj4.XXX.XXX.XXX.XXX.nip.io daisukenishino2opneshift 8080-tcp None -
サービスにアクセスする。
プレーンなMVCアプリが起動する。
- OpenShift で .NET Core 2.0を使いはじめる
http://tech.tanaka733.net/entry/2017/09/06/OpenShift_%E3%81%A7_.NET_Core_2.0%E3%82%92%E4%BD%BF%E3%81%84%E3%81%AF%E3%81%98%E3%82%81%E3%82%8B
- Developing .NET Core 2.0 Web Applications on OpenShift - RHD Blog
https://developers.redhat.com/blog/2017/11/22/developing-net-core-2-0-web-applications-openshift/
-
Getting Started Guide
https://access.redhat.com/documentation/en-us/net_core/2.0/html/getting_started_guide/-
Chapter 1. .NET Core 2.0 on Red Hat Enterprise Linux
https://access.redhat.com/documentation/en-us/net_core/2.0/html/getting_started_guide/gs_install_dotnet- 1.1. Install and Register Red Hat Enterprise Linux
- 1.2. Install .NET Core
- 1.3. Create an Application
- 1.4. Publish Applications
1.4.1. Publish .NET Core Applications
1.4.2. Publish ASP.NET Core Applications - 1.5. Run Applications on Docker
-
Chapter 2. .NET Core 2.0 on Red Hat OpenShift Container Platform
https://access.redhat.com/documentation/en-us/net_core/2.0/html/getting_started_guide/gs_dotnet_on_openshift- 2.1. Install Image Streams
- 2.2. Deploy Applications
- 2.3. Configuration
- 2.4. Sample Applications
- 2.5. Create a Runtime Image
-
- Announcing .NET Core 2.0 Support for OpenShift – OpenShift Blog
https://blog.openshift.com/announcing-net-core-2-0-support-openshift/
移行メモ
- 環境変数の一覧の
DOTNET_CONFIGURATIONの説明が 「デバッグモード(Release)/リリースモード(Debug)」と入れ替わっていたため、 「リリースモード(Release)/デバッグモード(Debug)」に修正した。- 元 Wiki では見出しそのものが他ページへのリンクになっていた箇所 (「Image Streams」「サービスのルートを作成する。」 「OpenShiftファースト・ステップ」ほか)は、GitHub Wiki では 見出しからアンカが生成されるため、見出しをプレーン・テキストとし、 リンクは本文に置いた。
- 同名の見出し(「概要」「テンプレートからデプロイする。」 「Image Streams + GitソースURIからデプロイする。」)が複数あり GitHub Wiki でアンカが衝突するため、括弧で文脈を補って一意にした。
- マイクロソフト系技術情報 Wiki(techinfoofmicrosofttech.osscons.jp)への URL リンクは、移行済みの ASP.NET Coreの開発 に張り替えた。
- PukiWiki のページ内アンカ(
#xxxxxxxx)は GitHub Wiki では再現できないため、 同一ページ内のアンカは見出しから生成されるアンカに張り替え、 他ページのアンカを指すリンクは「〜(ページ名の該当節を参照)」の形に置き換えた。
Tags: 移行, OpenShift, .NET Core, ASP.NET Core, Image Streams, S2I, oc, テンプレート, Red Hat
このWikiは「Open棟梁Project」,「OSSコンソーシアム 開発基盤部会」によって運営されています。