LoginSignup
2
2

More than 5 years have passed since last update.

PCF Devを使ってCloud Foundryローカル環境を作ってみた

Posted at

最近CloudFoundryを調べたり使ったりすることが多いので、ローカルに環境を作って色々試せるようにしてみた。

Vagrantのインストール

ここからダウンロードしてVagrantのインストール。
特に問題なく終わるはずです。

PCF Devのインストール

makingさんの記事を基に実施しますが、今回はstart-osxを使って実施してみます。

$ ./start-osx

PCF Dev has reserved 4 GB out of 16 GB total system memory.
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'pcfdev/pcfdev' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: 0.54.0
==> default: Loading metadata for box 'pcfdev/pcfdev'
    default: URL: https://atlas.hashicorp.com/pcfdev/pcfdev
==> default: Adding box 'pcfdev/pcfdev' (v0.54.0) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/pcfdev/boxes/pcfdev/versions/0.54.0/providers/virtualbox.box
==> default: Box download is resuming from prior download progress
==> default: Successfully added box 'pcfdev/pcfdev' (v0.54.0) for 'virtualbox'!
==> default: Importing base box 'pcfdev/pcfdev'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'pcfdev/pcfdev' is up to date...
==> default: Setting the name of the VM: pcfdev-v0140_default_1467159717255_90983
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: stdin: is not a tty
==> default: Waiting for services to start...
==> default: 0 out of 46 running
==> default: 0 out of 46 running
==> default: 0 out of 46 running
==> default: 0 out of 46 running

ここから一向に動いてくれない。結構待ちますし、その間VirtualBoxがCPUをかなり占有します。
根気強く待つと(今回は15分くらい)少しずつインスタンスが立ち上がってくるようです。

==> default: 0 out of 46 running
==> default: 28 out of 46 running
==> default: 28 out of 46 running
==> default: 40 out of 46 running
==> default: 44 out of 46 running
==> default: 44 out of 46 running
==> default: 44 out of 46 running
==> default: 46 out of 46 running
==> default: PCF Dev is now running.
==> default: To begin using PCF Dev, please run:
==> default:    cf login -a api.local.pcfdev.io --skip-ssl-validation
==> default: Email: admin
==> default: Password: admin

立ち上がりました。デフォルトはadmin/adminでログインできるようです。

ログインしてみる

早速ログインしてみます。

$  cf login -a api.local.pcfdev.io -u admin -p admin --skip-ssl-validation
API エンドポイント: api.local.pcfdev.io
警告: 非セキュアな HTTP API エンドポイントが検出されました: セキュアな HTTPS API エンドポイントが推奨されます

認証中です...
OK

組織 pcfdev-org をターゲットにしました

スペース pcfdev-space をターゲットにしました



API エンドポイント:   https://api.local.pcfdev.io (API バージョン: 2.52.0)
ユーザー:             admin
組織:                 pcfdev-org
スペース:             pcfdev-space

ひとまずmarketplaceに何が登録されているのか確認してみます。

 cf m
admin として組織 pcfdev-org / スペース pcfdev-space 内のマーケットプレイスからサービスを取得しています...
OK

サービス     プラン       説明
p-mysql      512mb, 1gb   MySQL databases on demand
p-rabbitmq   standard     RabbitMQ is a robust and scalable high-performance multi-protocol messaging broker.
p-redis      shared-vm    Redis service to provide a key-value store

ヒント:  特定のサービスの個々のプランの説明を表示するには、'cf marketplace -s SERVICE' を使用します。

MySQL, RabbitMQ, Redisが使えるようです。自分でサービスを登録できるようになってみたいもんですねぇ。。。

アプリケーションをデプロイしてみる

早速Spring Boot製のHello WorldアプリをビルドしてCloudFoundry上にアップロードしてみます。

今回アップロードするアプリは下記のようなシンプルなアプリケーションです。

@SpringBootApplication
@RestController
public class HelloCfApplication {

    @RequestMapping("/")
    String hello() {
        return "Hello World!";
    }

    public static void main(String[] args) {
        SpringApplication.run(HelloCfApplication.class, args);
    }
}
$ mvn clean package
$ cf push hello-cf -p target/hello-cf-0.0.1-SNAPSHOT.jar

admin としてアプリ hello-cf を組織 pcfdev-org / スペース pcfdev-space 内に作成しています...
OK

経路 hello-cf.local.pcfdev.io を作成しています...
OK

hello-cf.local.pcfdev.io を hello-cf にバインドしています...
OK

hello-cf をアップロードしています...
次のパスからアプリ・ファイルをアップロードしています: /var/folders/f2/dn55vt054w5djx70_r7nq1sr0000gn/T/unzipped-app804477025
13.3M、109 個のファイルをアップロードしています
Done uploading               
OK


admin として組織 pcfdev-org / スペース pcfdev-space 内のアプリ hello-cf を開始しています...
Downloading java_buildpack...
Downloading ruby_buildpack...
Downloading nodejs_buildpack...
Downloading go_buildpack...
Downloading python_buildpack...
Downloading php_buildpack...
Downloading staticfile_buildpack...
Downloading binary_buildpack...
Downloaded staticfile_buildpack
Downloaded ruby_buildpack
Downloaded nodejs_buildpack
Downloaded python_buildpack
Downloaded go_buildpack
Downloaded binary_buildpack
Downloaded php_buildpack
Downloaded java_buildpack
Creating container
Successfully created container
Downloading app package...
Downloaded app package (11.8M)
Staging...
-----> Java Buildpack Version: v3.6 (offline) | https://github.com/cloudfoundry/java-buildpack.git#5194155
-----> Downloading Open Jdk JRE 1.8.0_71 from https://download.run.pivotal.io/openjdk/trusty/x86_64/openjdk-1.8.0_71.tar.gz (found in cache)
       Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.1s)
-----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from https://download.run.pivotal.io/memory-calculator/trusty/x86_64/memory-calculator-2.0.1_RELEASE.tar.gz (found in cache)
       Memory Settings: -XX:MaxMetaspaceSize=64M -Xss853K -Xmx160M -Xms160M -XX:MetaspaceSize=64M
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://download.run.pivotal.io/auto-reconfiguration/auto-reconfiguration-1.10.0_RELEASE.jar (found in cache)
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading droplet...
Uploading build artifacts cache...
Uploaded build artifacts cache (108B)
Uploaded droplet (56.7M)
Uploading complete

1 個の中の 0 個のインスタンスが実行中です, 1 個が開始中です
1 個の中の 1 個のインスタンスが実行中です

アプリが開始されました


OK

アプリ hello-cf はこのコマンド `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/.:$PWD/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.10.0_RELEASE.jar org.springframework.boot.loader.JarLauncher` を使用して開始されました

admin として組織 pcfdev-org / スペース pcfdev-space 内のアプリ hello-cf の正常性と状況を表示しています...
OK

要求された状態: started
インスタンス: 1/1
使用法: 256M x 1 インスタンス
URL: hello-cf.local.pcfdev.io
最後アップロード日時: Sun Jul 17 11:49:39 UTC 2016
スタック: unknown
ビルドパック: java-buildpack=v3.6-offline-https://github.com/cloudfoundry/java-buildpack.git#5194155 java-main open-jdk-like-jre=1.8.0_71 open-jdk-like-memory-calculator=2.0.1_RELEASE spring-auto-reconfiguration=1.10.0_RELEASE

     状態   次の日時から             CPU    メモリー             ディスク             詳細
#0   実行   2016-07-17 08:50:13 PM   0.0%   256M の中の 212.3M   512M の中の 135.4M

無事デプロイできたようなのでアクセスしてみます。

$ cf a
admin として組織 pcfdev-org / スペース pcfdev-space 内のアプリを取得しています...
OK

名前       要求された状態   インスタンス   メモリー   ディスク   URL
hello-cf   started          1/1            256M       512M       hello-cf.local.pcfdev.io

$ curl hello-cf.local.pcfdev.io
Hello World!

メモリについては何も指定しないと256MBが指定されるようですね。
無事アクセスできました。

終了時にGraceful Shutdownをしている模様

どのくらいのGraceful Shutdownをしてくれているのか、気になります。

$ ./stop-osx 
==> default: Attempting graceful shutdown of VM...

まとめ

今回は単純にPCF Devを使ってかなり単純なアプリデプロイをしてみました。他にセミナー等で学んできていることも、どこまでできるのか、やってみたいと思っています。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2