Developer perks: Cloud Foundry

Cloud Foundry is a popular open source Platform as a Service (PaaS). Cloud Foundry can be used on your own deployment infrastructure or on any IaaS (Infrastructure as a Service) such as Tencent Cloud Web Services, VMware or vSphere. It can be deployed using the BOSH deployment system. Cloud Foundry provides an environment to easily run, scale, and maintain applications. Cloud Foundry supports Java, NodeJS, Ruby, Python and most languages ​​and environments.

Pivotal also provides a lightweight distributed application of PCF, called PCF Dev, that can run on a single machine.

Concept of Cloud Foundry

User is a user of Cloud Foundry who can manage org/space/app.

Roles are permissions assigned to different users such as Organization Managers/Space Managers.

Organizations are at the highest level and can be used by different users to group applications. Every organization has one or more spaces.

Spaces are places where applications can be deployed and configurations can be shared. Multiple applications can be deployed in a single space. Single or multiple spaces make up an organization.

Applications are individual applications that run inside Cloud Foundry.

Serve

Every external service used by an application (like database, message queue, etc.) is a service in Cloud Foundry. These services need to be defined at the Cloud Foundry level and can be used by any organization/space via the Service Broker API. All services require registration in the Marketplace. The marketplace is the place to see all the services available on Cloud Foundry.

We can create available service instances that suit our needs. For example, Pivotal offers a MySQL service called p-mysql on Pivotal Web Services with different types of plans like 512MB and 1024MB. If our application requires a MySQL database, we can create an appropriately scheduled service instance of p-mysql as needed and bind this service instance to the application. Cloud Foundry then writes the connection parameters for this MySQL to the environment variable VCAP_SERVICES, which the application can use to connect to the MySQL database.

bind

A binding is a mapping between available services in the application space.

routing

Each application is identified by one or more addresses called routes. These routes can be mapped to and used to access applications.

build package

The build pack resolves/downloads/configures the dependencies of the application according to user requirements. For example java-buildpack. This build pack contains dependencies for Java, Tomcat, Grails, Groovy, Play, etc., of course, the specific dependencies mainly depend on the nature of the application. Cloud Foundry provides buildpacks for most platforms. There are community-supported buildpacks. Cloud Foundry allows the creation of custom buildpacks.

Droplets

When a user creates an application (created with the command 'cf push'), Cloud Foundry generates a droplets. A droplet is like a mirror or blob (binary large object) storage of the actual application binaries and dependencies. The droplet is stored in Cloud Foundry for later use. Whenever a user tries to run/scale an application, a VM is created with this image and the image is run. So whenever application/configuration/env changes. variable, the application needs to be recreated and the droplet generated again. Restarting/restaging just restarts or deploys the same droplet.

environment variable

These are shared variables between Cloud Foundry and the application. Applications can use these to discover various services.

VCAP_SERVICES - Cloud Foundry adds service-related information to this variable.

VCAP_APPLICATIONS - Cloud Foundry adds application-related properties to this variable.

Login to Cloud Foundry

LogAggregator is a Cloud Foundry component that aggregates logs from all apps. Logs can be streamed to terminals, files, or third-party services.

CF CLI Tools

CF CLI is a command line client for using Cloud Foundry; it is used to pass commands to deploy/extend/manage/monitor applications, create/stop services, etc. CF CLI can be installed on any Linux/Windows/Mac machine. List of CF CLI commands. Spring Tool Suite (STS) is an eclipse based IDE for Spring application development and there is also a Cloud Foundry plugin that helps deploy/manage applications, as well as create and manage orgs/spaces from the IDE.

Pivotal provides a lightweight development version of Cloud Foundry called PCF Dev that can be installed on a single developer machine. If you don't want to install PCF Dev on your machine and still want to try Cloud Foundry, you can skip the installation part and just install the CF CLI and use the evaluation version available in Pivotal Web Service. First you need a free Pivotal account.

PCF Dev Installation

1) Install VirtualBox for your OS.

2) Install CF CLI.

3) Download PCF Dev for your favorite OS. Extract PCF Dev into a folder and run pcfdev-[VERSION]-[OS]. This installs the PCFDev plugin to the CF CLI.

4) Open a new terminal in that folder and execute the command cf dev start
write picture description here

screenshot of command

5) This will prompt you for key account credentials, then download the VM, dependencies, start all required services. If you don't have a Pivotal account, please register.
write picture description here

Code screenshot

Once CF is up, you can open a new terminal and run the CF command to connect to Cloud Foundry.

Login to Cloud Foundry

cf login -a [api-endpoint] --skip-ssl-validation The API endpoint for PCF Dev is https://api.local.pcfdev.com and for Pivotal Web Service is https://api.run.pivotal.io . You will be prompted for your email and password. The email/password will be admin/admin if you are PCF Dev edition, and key account email/password if it is the official edition of Pivotal Web Services. Specify the desired organization and space.

write picture description here
cf login

Deploy the sample application in Cloud Foundry

A sample application can be found on this Github. Here is an example of a Spring Boot Web Services application exposing the get API. In the default configuration file, the application creates an in-memory database and fetches data from this database in JSON form. In the cloud profile, the application uses the service name mysqldb to connect to the MySQL database on the cloud. The project uses the Spring Cloud Service Connector to connect to the cloud MySQL service.

Deploy the app in the org/space selected with the command: cf push [App-Name] -b [build-pack] -i [No-of-instances] -m [App-memory]

This deploys and starts the application. If no route is specified, a default route with the same name as app-name is created and bound to the application. Applications can also be pushed using a manifest file. All options are available in the manifest file: cf push -f [Path-To-Manifest-File]

Example content of manifest file:

applications:- name: pcf-demo-appbuildpack: https://github.com/cloudfoundry/java-buildpackmemory: 512Minstances: 1host: pcf-demo-apppath: pcf-demo-1.0.0-SNAPSHOT.jartimeout: 180

write picture description here
cf push

write picture description here
cf push2

View the status of the application

cf apps - Shows the status of all apps in the space. cf app [App-Name] - Displays the status of the application. If all goes well, the application state will look like this:

write picture description here
cf apps

The application can be restarted or restarted:

cf restart [App-Name]cf restage [App-Name]

write picture description here
cf restart

Application logs can be viewed. The environment properties of the application can be viewed:

cf logs [App-Name] –recent
write picture description here

cf logs

The environment in which the program is running can also be seen

cf env [App-Name]

write picture description here
cf env

If the application status shows "running", running this command CURL -k https://pcf-demo-app.pcfdev.com/user will get the data.

write picture description here
curl command to get data

Run the application in Cloud Profile with MySQL service

You can see all the services available in Cloud Foundry: cf marketplace - Shows all available marketplace services. cf marketplace -s [service-name] - Displays details of a specific service available in the marketplace.

write picture description here
Show all available marketplace services

cf create-service [service-name] [service-type] [service-instance-name] - This will create a service with the name [service-instance-name] and type [service-type] in the current space.
write picture description here

Create service

cf services - This shows all services in the current space.

write picture description here
Show Services in Space

cf service [service-instance-name] - This shows detailed information about a specific service within the space.
write picture description here

Show specific services in the space

You can change the content of the manifest file:

applications:- name: pcf-demo-app buildpack: https://github.com/cloudfoundry/java-buildpack memory: 512M instances: 1host: pcf-demo-ap path: pcf-demo-1.0.0-SNAPSHOT.jar timeout: 180env:SPRING_PROFILES_ACTIVE: cloudservices:- mysqldb

This will create the environment variable SPRING_PROFILES_ACTIVE and set the value to cloud. It also creates a binding between the pushed application and the service mysqldb. This binding can also be created manually with this command: cf bind-service [App-Name] [Service-Instance-Name] Now push the app again with new manifest changes: cf push -f [Path-To-Manifest-File] You can run CF env again to see VCAP_SERVICES updated with mysqldb details.

scale application
write picture description here
cf scale [App-name] -i [no-of-instances] -m [memory-limit]

Zoom application

In the CLI there are delete, rename, start and stop applications, log out users, view files, create/update/delete services, create/update/delete custom services provided by users, bind/unbind services, bind/ Unbind routes, create/delete orgs and spaces, create/update/delete buildpacks, create/delete users, etc. commands.

If you are using Pivotal Cloud Foundry (the commercial version of Cloud Foundry) or Pivotal Dev, Cloud Foundry has a web-based console application that can be used as an alternative to the CF CLI to simplify user operations.

write picture description here
Login page
write picture description here
Homepage
Original link: https://dzone.com/articles/cloud-foundry-for-developers

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325471909&siteId=291194637