美文网首页
PCF - Pivotal Cloud Foundry

PCF - Pivotal Cloud Foundry

作者: Minnakey | 来源:发表于2020-02-20 17:28 被阅读0次

Pivotal Web Service是Pivotal公司提供的公有云服务,其底层架构是Cloud Foundry。

  1. create a PWS account
  2. installed CF CLI
  3. Deploy the Sample App
git clone https://github.com/cloudfoundry-samples/cf-sample-app-spring.git
cd cf-sample-app-spring
# deploy application
manifest.yml
----------------------------------
applications:
- name: cf-demo
  memory: 768M
  instances: 1
  random-route: true
  buildpacks:
-----------------------------------
cf login -a https://api.run.pivotal.io  -u xxx -p pwd          # login to PWS
cf target -o org_name -s space_name   #  org and space
cf push   cf-demo                 # push the app to PWS
cf apps     # check application status
cf  restart cf-demo   # restart application
cf logs cf-demo --recent   # check log 
  1. Connect a Database
cf marketplace     # See what services PWS provides
cf marketplace -s elephantsql
cf create-service elephantsql turtle cf-demo-db  // create a services, turtle--  this is a free package
cf bind-service cf-demo cf-demo-db   // bind a service instance to an app
cf restage cf-demo 
cf services  #verify services

Configuration service RabbitMQ, Redis, Service Registry, Config Server

    1. RabbitMQ, Redis config
cf marketplace
cf create-service p.rabbitmq single-node my-rabbitmq
cf services
cf create-service-key my-rabbitmq my-rabbit-key
cf service-key my-rabbitmq my-rabbit-key    // service-key  config
# Redis, cf create-service p.redis 2gb my-redis
// Spring Cloud or Spring Boot project
# application.yml
----------------------------------
spring:
  rabbitmq:
host: 10.xx.xx.xx
port: 5672
username: xxx
password:  pwd
----------------------------------
    1. config service-registry
cf create-service p-service-registry standard my-registry
# manifest.yml
----------------------------------
applications:
- name: cf-demo
  memory: 768M
  instances: 1
  random-route: true
  buildpacks:
  path:
  env:
      spring.profiles.active: east
 services:
     -  my-registry
     -  my-rabbitmq
     -  my-config
 routes:
   - route: https://
-----------------------------------
cf bind-service my-app mydb
    1. Config Server
SSH Key
{
    "git":{
        "uri":"ssh://git@github.com/spring-cloud-services-samples/demo.git",
        "privateKey":"-----BEGIN EXAMPLE RSA PRIVATE KEY-----
MIIJKQIB..."
    }
}
cf create-service p-config-server standard my-config
cf update-service my-config -c "{"count":1,"git":{"privateKey":"----- KEY---","hostKey":"XXX","label":"dev","hostKeyAlgorithm":"ecdsa-sha2-nistp256","uri":"ssh://git@github.com/XXX.git"}}"
cf service my-config 
cf push –f manifest.yml  //depoly
  • Architecture
    Within a PCF foundation, a “mirror service” makes a full mirror of each Git repository (“R1”, “R2”, “R3”) used by a Config Server service instance. The Config Server service instance, in turn, clones repositories from this mirror rather than cloning from the external Git server directly.


    config-server-fig

NodeJS application

package.json

{
    "name": "gjflying-app",
    "version": "0.0.1",
    "description": "使用express框架、hbs模板引擎、mongodb数据库的简单nodejs应用,依赖vmware的pass平台cloudFoundary进行发布上线;",
    "main": "index.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "author": "gaojun",
    "private": true,
    "dependencies": {
        "express": "4.9"
    },
    "devDependencies": {
        "hbs": "^2.7.0",
        "body-parser": "^1.9.3"
    }
}
npm install  // 安装相关依赖包
## 应用中需要连接mongodb的驱动及连接池包
npm install mongodb --save   // 保存依赖到package.json中devDependencies
## mongo
show dbs
show collections 
use gjflying
   db.login.insert({name:"admin",pwd:"123456"});
   db.login.find({})
cf push

CLI

1. Before getting started:

cf  config   // Write default values to the config
cf config [--async-timeout TIMEOUT_IN_MINUTES] [--trace (true | false | path/to/file)] [--color (true | false)] [--locale (LOCALE | CLEAR)]
#OPTIONS:
#   --async-timeout      Timeout for async HTTP requests
#   --color              Enable or disable color
#   --locale             Set default locale. If LOCALE is 'CLEAR', previous locale is deleted.
#  --trace              Trace HTTP requests

cf login,l [-a API_URL] [-u USERNAME] [-p PASSWORD] [-o ORG] [-s SPACE] [--sso | --sso-passcode PASSCODE] [--origin ORIGIN]

cf target,t [-o ORG] [-s SPACE]  # Set or view the targeted org or space
cf logout,lo 

2. Application lifecycle:

cf apps,a    # List all apps in the target space
cf push,p  
# Push a new app or sync changes to an existing app
# -b 自定义的buildpack地址,一般如github上打包的.tar.gz的文件包
# -c 指定启动命令,如nodejs中,cf push -c node myappstart.js,指定使用node myappstart.js来启动你的应用
# -d 指定域名,如example.com
# -f  指定manifest.yml文件路径,无此参数时,cf push会将当前你所处文件目录遍历,并上传到pivotal中你申请的空间中,并使用当前目录中manifest.yml文件配置的选项启动应用,如果没有此文件,一般会报错,关于manifest.yml的用法,请参考下面实例部分;
#  -p 指定你要上传发布的应用源码路径;默认是当前路径
# -m 指定分配给该应用的内在大小如:cf push -m 10mb
#  -h 指定主机
cf start,st  app_name  # Start an app
cf stop,sp  app_name  # stop an app
cf restart,rs  app_name # Stop all instances of the app, then start them again. This causes downtime.
cf  restage,rg   #Recreate the app's executable artifact using the latest pushed app files and the latest environment (variables, service bindings, buildpack, stack, etc.). This action will cause app downtime.
cf delete,d app_name [-f,-r]  
# -f      Force deletion without confirmation
# -r      Also delete any mapped routes
cf run-task,rt cf  app_name COMMAND [-k DISK] [-m MEMORY] [--name TASK_NAME]     # Run a one-off task on an app
cf logs  app_name --recent   # Tail or show recent logs for an app
cf ssh  app_name      # SSH to an application container instance
cf app  app_name --guid  #  Display health and status for an app
cf env,e  app_name   # Show all env variables for an app
cf scale   app_name# Change or view the instance count, disk space limit, and memory limit for an app
cf events app_name    # Show recent app events
cf set-env,se   app_name ENV_VAR_NAME ENV_VAR_VALUE #Set an env variable for an app
cf create-app-manifest app_name [-p /path/to/<app-name>_manifest.yml]   #Create an app manifest for an app that has been pushed successfully

3. Services integration:

cf marketplace,m [-s SERVICE] [--no-plans] 
# List available offerings in the marketplace 查看PWS提供了哪些服务
# OPTIONS:
#   -s              Show plan details for a particular service offering
#   --no-plans      Hide plan information for service offerings
cf services,s    #List all service instances in the target space
cf create-service,cs  SERVICE PLAN SERVICE_INSTANCE [-b BROKER] [-c PARAMETERS_AS_JSON] [-t TAGS] 
# Create a service instance 
# cf create-service SERVICE PLAN SERVICE_INSTANCE -c PATH_TO_FILE (with a valid JSON object) 
# cf create-service db-service silver mydb -c '{"ram_gb":4}'
cf update-service SERVICE_INSTANCE [-p NEW_PLAN] [-c PARAMETERS_AS_JSON] [-t TAGS] [--upgrade]
#  cf update-service mydb -p gold
#  cf update-service mydb -c '{"ram_gb":4}'
#  cf update-service mydb -c ~/workspace/tmp/instance_config.json
#  cf update-service mydb -t "list, of, tags"
#  cf update-service mydb --upgrade
#  cf update-service mydb --upgrade --force
# -c                 Valid JSON object containing service-specific configuration parameters, provided either in-line or in a file. For a list of supported configuration parameters, see documentation for the particular service offering.
# -p                 Change service plan for a service instance
# -t                 User provided tags
#  --upgrade, -u      Upgrade the service instance to the latest version of the service plan available. It cannot be combined with flags: -c, -p, -t.
# --force, -f        Force the upgrade to the latest available version of the service plan. It can only be used with: -u, --upgrade
cf delete-service -f 
# -f  Force deletion without confirmation
cf service  service_instance   # Show service instance info
cf bind-service,bs  APP_NAME SERVICE_INSTANCE --binding-name BINDING_NAME 
# Bind[绑定] a service instance to an app
# cf bind-service myapp mydb -c '{"permissions":"read-only"}'
# --binding-name  Name to expose service instance to app process with (Default: service instance name)
# -c       Valid JSON object containing service-specific configuration parameters, provided either in-line or in a file. For a list of supported configuration parameters, see documentation for the particular service offering.
cf unbind-service,us   APP_NAME SERVICE_INSTANCE
#   Unbind a service instance from an app
cf create-user-provided-service,cups SERVICE_INSTANCE [-p CREDENTIALS] [-l SYSLOG_DRAIN_URL] [-r ROUTE_SERVICE_URL] [-t TAGS]
# Make a user-provided service instance available to CF apps
cf create-user-provided-service my-db-mine -p '{"username":"admin","password":"pa55woRD"}' 
cf create-user-provided-service my-db-mine -p /path/to/credentials.json
cf create-user-provided-service my-db-mine -t "list, of, tags"
cf create-user-provided-service my-drain-service -l syslog://example.com
cf create-user-provided-service my-route-service -r https://example.com
#OPTIONS:
#   -l      URL to which logs for bound applications will be streamed
#  -p      Credentials, provided inline or in a file, to be exposed in the VCAP_SERVICES environment variable for bound applications
#  -r      URL to which requests for bound routes will be forwarded. Scheme for this URL must be https
#   -t      User provided tags
cf update-user-provided-service, uups SERVICE_INSTANCE [-p CREDENTIALS] [-l SYSLOG_DRAIN_URL] [-r ROUTE_SERVICE_URL] [-t TAGS]
# Update user-provided service instance
cf create-service-key, csk SERVICE_INSTANCE SERVICE_KEY [-c PARAMETERS_AS_JSON]
# Create key for a service instance
cf create-service-key mydb mykey -c '{"permissions":"read-only"}'
cf create-service-key mydb mykey -c ~/workspace/tmp/instance_config.json
cf delete-service-key,dsk  SERVICE_INSTANCE SERVICE_KEY [-f]
cf service-keys,sk  SERVICE_INSTANCE
# List keys for a service instance
cf service-key
cf bind-route-service,brs DOMAIN [--hostname HOSTNAME] [--path PATH] SERVICE_INSTANCE [-c PARAMETERS_AS_JSON]
# Bind a service instance to an HTTP route
# EXAMPLES:
   cf bind-route-service example.com --hostname myapp --path foo myratelimiter
   cf bind-route-service example.com myratelimiter -c file.json
   cf bind-route-service example.com myratelimiter -c '{"valid":"json"}'
cf unbind-route-service,urs

4. Route and domain management:

cf routes,r  
# List all routes in the current space or the current organization
# --orglevel      List all the routes for all spaces of current organization
cf create-route
# cf create-route SPACE DOMAIN [--hostname HOSTNAME] [--path PATH]
cf delete-route
cf create-domain
cf domains  # List domains in the target org
cf map-route   # Add a url route to an app
# Map an HTTP route:
#      cf map-route APP_NAME DOMAIN [--hostname HOSTNAME] [--path PATH]
# Map a TCP route:
#      cf map-route APP_NAME DOMAIN (--port PORT | --random-port)
cf map-route my-app example.com                              # example.com
cf map-route my-app example.com --hostname myhost            # myhost.example.com
cf map-route my-app example.com --hostname myhost --path foo # myhost.example.com/foo
cf map-route my-app example.com --port 5000                  # example.com:5000
cf unmap-route
OPTIONS:
   --hostname, -n      Hostname used to identify the HTTP route
   --path              Path used to identify the HTTP route
   --port              Port used to identify the TCP route

5. Space management:

cf spaces
cf create-space test    # create a space
cf delete-space test
cf space-users ORG SPACE  # Show space users by role

cf set-space-role USERNAME ORG SPACE ROLE  # Assign a space role to a user
cf unset-space-role USERNAME ORG SPACE ROLE  # remove a space role from a user
# ROLES:
'SpaceManager' - Invite and manage users, and enable features for a given space
'SpaceDeveloper' - Create and manage apps and services, and see logs and reports
'SpaceAuditor' - View logs, reports, and settings on this space

6. Org management:

cf orgs,o   // List all orgs
cf org-users ORG  # Show org users by role
cf set-org-role USERNAME ORG ROLE [--client]
 # Assign an org role to a user
cf unset-org-role
# ROLES:
#   'OrgManager' - Invite and manage users, select and change plans, and set spending limits
#   'BillingManager' - Create and manage the billing account and payment info
#   'OrgAuditor' - Read-only access to org info and reports
# OPTIONS:
#   --client      Treat USERNAME as the client-id of a (non-user) service account

7. CLI plugin management:

cf plugins [--checksum | --outdated]
# List commands of installed plugins
# OPTIONS:
#   --checksum      Compute and show the sha1 value of the plugin binary file
#   --outdated      Search the plugin repositories for new versions of installed plugins
cf install-plugin PLUGIN_NAME [-r REPO_NAME] [-f]
cf install-plugin LOCAL-PATH/TO/PLUGIN | URL [-f]
cf install-plugin ~/Downloads/plugin-foobar
cf install-plugin https://example.com/plugin-foobar_linux_amd64
cf install-plugin -r My-Repo plugin-echo
cf add-plugin-repo REPO_NAME URL
# Add a new plugin repository
cf add-plugin-repo ExampleRepo https://example.com/repo
cf list-plugin-repos
# List all the added plugin repositories
cf repo-plugins [-r REPO_NAME]
# List all available plugins in specified repository or in all added repositories
# -r Name of a registered repository

集群维护-monit工具

1. monit summary   # 查看集群组件状态
2. monit restart postgres   #重启某个组件
3. monit restart all # 重启所有组件

相关文章

网友评论

      本文标题:PCF - Pivotal Cloud Foundry

      本文链接:https://www.haomeiwen.com/subject/britqhtx.html