Chapter 5. OpenShift basics in CodeReady Studio

CodeReady Studio includes the OpenShift Application Explorer view, which provides a simplified user experience allowing easy and rapid feedback through the inner loop as well as debugging.

The OpenShift Application Explorer is set in CodeReady Studio as the default view. In case you need to open it manually, follow the instructions in Setting Up Openshift App Explorer View.

Prerequisites

  • A running OpenShift cluster.

5.1. Setting up the OpenShift Application Explorer view

The following section describes how to open OpenShift Application Explorer in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Click WindowShow ViewOther.

    crs window show view other

    The Show View window appears.

    crs select openshift app explorer
  3. Enter OpenShift in the search field.
  4. Select OpenShift Application Explorer.
  5. Click Open.

    The OpenShift Application Explorer view appears.

crs openshift app explorer view

5.2. Connecting to an OpenShift cluster using OpenShift Application Explorer

The following section describes how to login to an OpenShift cluster in CodeReady Studio using OpenShift Application Explorer.

Procedure

  1. Start CodeReady Studio.
  2. Open OpenShift Application Explorer.
  3. Click Can’t connect to cluster. Click to login.

    login to openshift cluster

    The Login window appears.

    crs os browser sign in
  4. Paste your OpenShift API URL into the URL field.

    For more information on accessing your cluster through OpenShift API URL, visit Red Hat OpenShift - Accessing your Services.

  5. Enter your username and password or token.
  6. Click Finish.

5.3. Connecting to an OpenShift cluster using browser-based token retrieval

Alternatively to providing your username and password or token to the OpenShift Application Explorer, you can use browser based token retrieval to log in to your OpenShift cluster. There are two login options, pasting your login command or retrieving your token.

5.3.1. Pasting your login command

Procedure

  1. Paste your OpenShift API URL into the URL field.

    For more information on accessing your cluster through OpenShift API URL, visit Red Hat OpenShift - Accessing your Services.

  2. Visit the OpenShift Container Platform web UI.

    os3 clicking copy login command
  3. Click the drop-down menu in the top right corner.
  4. Click Copy Login Command.
  5. Click Display Token.
  6. Copy the login command.
  7. In the Sign in to OpenShift window, click Paste login command.

    crs os browser sign in
  8. Click Finish.

    Note

    For OpenShift 3, the login command is copied into your clipboard automatically.

5.3.2. Retrieving your token

Procedure

  1. Paste your OpenShift API URL into the URL field.

    For more information on accessing your cluster through OpenShift API URL, visit Red Hat OpenShift - Accessing your Services.

  2. Click Retrieve token.

    crs os browser sign in
  3. Enter your username and password.
  4. Click Log in.
  5. Click Display Token.
  6. Click Finish.

Your projects now appear in the OpenShift Application Explorer view.

5.4. Setting up a Developer Sandbox using OpenShift tools

The following section describes how to bootstrap and login to a Developer Sandbox in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Open OpenShift Application Explorer.

    crs os application explorer login2
  3. Right-click your OpenShift connection.
  4. Click Login.

    The Sign in to OpenShift window appears.

    crs bootstrap a developer sandbox cluster
  5. Click Red Hat Developer Sandbox.
  6. Provide the credentials of your Red Hat account and click Log in.

    Your Developer Sandbox has been bootstrapped.

    The Login to Red Hat Developer Sandbox window appears.

    crs developer sandbox is ready
  7. Click Next.
  8. Click DevSandbox.
  9. Provide the credentials of your Red Hat account again and click Log in.
  10. Click Display Token.
  11. Click Finish.

    Your Token is displayed in the Sign in to OpenShift window.

    crs developer sandbox token displayed
  12. Click Finish.

    You are now logged in to your Developer Sandbox.

Your Developer Sandbox shows in the OpenShift Application Explorer view.

5.5. Building an application based on devfiles

To deploy applications based on devfiles, you need an empty project in your local workspace as well as an empty project in OpenShift, for which you need to create a devfile component. After the component is established, your project will be updated and local and remote artifacts created in OpenShift.

Procedure

  1. Start CodeReady Studio.
  2. Press Ctrl+N.

    The Select a wizard window appears.

    crs create empty project in pe 1
  3. Select GeneralProject.
  4. Click Next.

    The New Project window appears.

    crs create empy project in pe
  5. Name your project.
  6. Select the location for your project.
  7. Click Finish.

    Your newly created empty project is now listed in the Package Explorer view.

  8. Start OpenShift Application Explorer.
  9. Right-click any place in OpenShift Application ExplorerNewProject.

    crs os project

    The New project window appears.

    crs os new project window
  10. Name your project.
  11. Click OK.

    Your newly created project is now listed in the OpenShift Application Explorer view.

  12. Right-click the target ProjectNewComponent.

    crs os new component

    The Create component window appears.

    crs devfile component type

  13. Name your project.
  14. Click Browse to select your Eclipse Project.
  15. Set your Component type to java-vertx.
  16. Set the Project starter to java-vertx.
  17. Name your application.
  18. Clear the Push after create check box.
  19. Click Finish.

    The Console view appears, displaying the validation process.

    Your newly created component is now listed in the OpenShift Application Explorer view under your project.

Your application based on devfiles is built.

5.5.1. Managing your devfile registries

The following section describes how to create, delete, and edit devfile registries using OpenShift Application Explorer in CodeReady Studio.

5.5.1.1. Adding a devfile registry

Prerequisites

  • A running OpenShift cluster.

Procedure

  1. Start CodeReady Studio.
  2. Start OpenShift Application Explorer.
  3. Devfile registries are displayed under the Devfile registries node.

    crs devfile registries node
  4. If you expand the devfile registry node, all devfiles of that registry are shown.

    crs devfile registries node expanded

    • To add a new devfile registry, right-click Devfile registries and click new.

      crs new devfile registry

      The Create devfile registry window appears.

      crs create devfile registry window
  5. Name your devfile registry.
  6. Paste your devfile URL.
  7. Click Finish.

Your newly created devfile registry is now listed in the OpenShift Application Explorer view under Devfile registries.

5.5.1.2. Deleting a devfile registry

Prerequisites

  • A running OpenShift cluster.

Procedure

  1. Start CodeReady Studio.
  2. Start OpenShift Application Explorer.
  3. Devfile registries are displayed under the Devfile registries node.

    crs devfile registries node
  4. An expanded devfile registry node shows all devfiles of that registry.

    crs devfile registries node expanded

    • To delete a devfile registry, right click the node of a devfile registry and click delete.

      crs delete devfile registry

Your devfile registry is now deleted.

5.5.1.3. Editing a devfile registry

Prerequisites

  • A running OpenShift cluster.

Procedure

  • To edit a devfile registry, use the YAML editor. The YAML editor provides syntax validation and content assist.

5.5.1.4. Creating a component from your devfile registry

You can create a new component from your devfile registry from either a component type or a starter project.

Prerequisites

  • An existing Eclipse project.
  • An existing OpenShift project.
  • You are connected to an OpenShift cluster.

Procedure

  1. Expand your devfile registry under the Devfile registry node.
  2. Right-click your component type or starter project and click ProjectNewComponent.

    crs creating a component for devfile registry

    The Create component window appears.

    crs create devfile registry component
  3. Name your component.
  4. Click Browse to select your Eclipse project.
  5. Choose your Component type.
  6. Choose your project starter.
  7. Name your application.
  8. Click Finish.

The new component is created from your devfile registry.

Additional resources

For further information on devfiles, visit Introduction to Devfile.

5.6. Building an application based on S2I files

To deploy applications based on S2I files, you need a launcher project in your local workspace as well as an empty project in OpenShift, for which you need to create a component. After the component is established, your project will be updated and local and remote artifacts created in OpenShift.

Procedure

  1. Start CodeReady Studio.
  2. Press Ctrl+N.

    The Select a wizard window appears.

    crs launcher project wizard
  3. Enter Launcher in the search field.
  4. Select Launcher project.
  5. Click Next.

    The New Launcher project window appears.

    crs launcher project creation
  6. Set Mission to rest-http.
  7. Set Runtime to vert.x community.
  8. Name your project.
  9. Select the location for your project.
  10. Click Finish.

    Note that the process of resolving dependencies might take some time to complete.

    Your newly created launcher project is now listed in the Project Explorer view.

  11. Start OpenShift Application Explorer.
  12. Right-click any place in OpenShift Application ExplorerNewProject.

    crs os project

    The New project window appears.

    crs os new project window
  13. Name your project.
  14. Click OK.

    Your newly created project is now listed in the OpenShift Application Explorer view.

  15. Right-click the target ProjectNewComponent.

    crs os new component

    The Create component window appears.

    crs s2i component

  16. Name your project.
  17. Click Browse to select your Eclipse Project.
  18. Click on the arrow next to S2I and set your Component type to java.
  19. Set the Component version to latest.
  20. Name your application.
  21. Clear the Push after create check box.
  22. Click Finish.

    The Console view appears, displaying the validation process.

    Your newly created component is now listed in the OpenShift Application Explorer view under your project.

Your application based on S2I files is built.

5.7. Deploying a component on a cluster using OpenShift Application Explorer

The following section describes how to deploy a component on a cluster using OpenShift Application Explorer in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Start OpenShift Application Explorer.
  3. Expand your project.
  4. Expand your application.
  5. Right-click your componentPush.

    crs os push

    The Console view appears, displaying the process of file synchronization.

5.8. Defining an external access URL using OpenShift Application Explorer

The following section describes how to define an external access URL using OpenShift Application Explorer in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Start OpenShift Application Explorer.
  3. Expand your project.
  4. Expand your application.
  5. Right-click your componentNewURL.

    crs os new url

    The Create URL window appears.

    crs os create url window
  6. Name your URL.
  7. Set the Port value to 8080.
  8. Click Finish.

    The Console view appears, displaying the process of URL creation.

  9. In OpenShift Application Explorer, right-click your componentPush.

    crs os push

    The Console view appears, displaying the process of file synchronization.

Your newly created URL is now listed in the OpenShift Application Explorer view under your component.

5.9. Debugging an application on a cluster using OpenShift Application Explorer

The following section describes how to debug an application on a cluster using OpenShift Application Explorer in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. In the Project Explorer view, locate the MainVerticle.java(devfiles) or HttpApplication.java(S2I) file and double-click to open it.
  3. Double-click on the left ruler column to set a breakpoint.

    crs os debugging breakpoint
  4. Open OpenShift Application Explorer.
  5. Expand your project.
  6. Expand your application.
  7. Right-click your componentDebug.

    crs os debug

    The Console view appears.

  8. In OpenShift Application Explorer, expand your component.
  9. Right-click your urlOpen in Browser.

    crc os open in browser

    The Confirm Perspective Switch window appears.

  10. Click Switch.

    The Debug Perspective window appears displaying the debugging process.

5.10. Creating application services using OpenShift Application Explorer

Use operators to create services when developing cloud native applications on OpenShift.

Prerequisites

Procedure

  1. In the OpenShift Application Explorer view, right-click your application.

    crs new service
  2. Select NewService.

    crs create service

    The Create service view appears.

  3. Enter a name for your service.
  4. From the Service drop-down menu, select a service from the installed operators on your cluster.
  5. From the Type drop-down menu, select a type of deployment.
  6. Click Finish.

    kafkacluster

Your newly created service is displayed in the OpenShift Application Explorer view.