搜尋服務
使用 kf marketplace
指令找出要在應用程式中使用的服務。如果在執行指令時未指定引數,系統會顯示所有可用的服務類別。服務類別代表特定類型的服務,例如 MySQL 資料庫或 Postfix SMTP 轉送。
$ kf marketplace
5 services can be used in Space "test", use the --service flag to list the plans for a service
Broker Name Space Status Description
minibroker mariadb Active Helm Chart for mariadb
minibroker mongodb Active Helm Chart for mongodb
minibroker mysql Active Helm Chart for mysql
minibroker postgresql Active Helm Chart for postgresql
minibroker redis Active Helm Chart for redis
服務類別可以提供多個方案。服務方案通常會對應至軟體的版本或定價層級。您可以透過市集指令提供服務名稱,查看特定服務的方案:
$ kf marketplace --service mysql
Name Free Status Description
5-7-14 true Active Fast, reliable, scalable, and easy to use open-source relational database system.
5-7-27 true Active Fast, reliable, scalable, and easy to use open-source relational database system.
5-7-28 true Active Fast, reliable, scalable, and easy to use open-source relational database system.
佈建服務
確認要佈建的服務類別和方案後,您可以使用 kf create-service
建立服務的例項:
$ kf create-service mysql 5-7-28 my-db
Creating service instance "my-db" in Space "test"
Waiting for service instance to become ready...
Success
服務會佈建至單一工作區。您可以執行 kf services
查看目前工作區中的服務:
$ kf services
Listing services in Space: "test"
Name ClassName PlanName Age Ready Reason
my-db mysql 5-7-28 111s True <nil>
您可以使用 kf delete-service
刪除服務:
$ kf delete-service my-db
繫結服務
建立服務後,您可以繫結至應用程式,這樣應用程式就會將憑證插入應用程式,以便使用服務。您可以使用 kf bind-service
建立繫結:
$ kf bind-service my-app my-db
Creating service instance binding "binding-my-app-my-db" in Space "test"
Waiting for service instance binding to become ready...
Success
您可以使用 kf bindings
指令列出工作區中的所有繫結:
$ kf bindings
Listing bindings in Space: "test"
Name App Service Age Ready
binding-my-app-my-db my-app my-db 82s True
服務繫結完成後,請使用 kf restart
重新啟動應用程式,憑證就會儲存在 VCAP_SERVICES
環境變數中。
您可以使用 kf unbind-service
指令刪除服務繫結:
$ kf unbind-service my-app my-db