Chapter 2. Developing for the Cloud with OpenShift in CodeReady Studio

2.1. Creating an OpenShift Container Platform application in CodeReady Studio

Using the OpenShift Container Platform tools you can create, import, and modify OpenShift Container Platform applications.

2.1.1. Creating a new OpenShift Container Platform connection

To use OpenShift tools in CodeReady Studio, you must create an OpenShift connection in the OpenShift Explorer view. An OpenShift connection connects CodeReady Studio to an OpenShift instance (based on CDK, OpenShift Online, Kubernetes or minishift). The connection is listed in the OpenShift Explorer view. You can have more than one OpenShift connection configured in CodeReady Studio.

Prerequisites

  • A running OpenShift cluster.

Procedure

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

    The Show View window appears.

    crs os explorer view
  3. Enter OpenShift in the search field.
  4. Select OpenShift Explorer.
  5. Click Open.

    The OpenShift Explorer view appears.

    crs os explorer new connection
  6. Right-click any area in the OpenShift Explorer.
  7. Click NewConnection.

    The Sign in to OpenShift window appears.

    crs os new connection sign in
  8. Paste the URL of your OpenShift server into the Server field.
  9. Authenticate with a token or login credentials.

    Note

    Alternatively, you can copy the Login Command from the OpenShift Container Platform web UI.

    To get login credentials, click the drop-down menu in the top right cornerCopy Login Command.

    os3 clicking copy login command
  10. Click Finish.

Your newly added connection is now listed in the OpenShift Explorer view.

2.1.2. Creating a new OpenShift Container Platform project

You must create an OpenShift Container Platform project, which essentially is a namespace with additional annotations, to centrally manage the access to resources for regular users of your OpenShift Container Platform.

Prerequisites

Procedure

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

    The Show View window appears.

    crs os explorer view
  3. Enter OpenShift in the search field.
  4. Select OpenShift Explorer.
  5. Click Open.

    The OpenShift Explorer view appears.

    crs os new project
  6. Right-click the OpenShift Container Platform connectionNewProject.

    The New OpenShift Project window appears.

    crs new os project window
  7. Name your project.
  8. Click Finish.

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

crs os project created

2.1.3. Creating a new OpenShift Container Platform application

You can use the OpenShift Application wizard in CodeReady Studio to create OpenShift Container Platform applications from default or custom templates.

Prerequisites

Procedure

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

    The Show View window appears.

    crs os explorer view
  3. Enter OpenShift in the search field.
  4. Select OpenShift Explorer.
  5. Click Open.

    The OpenShift Explorer view appears.

    crs os new app
  6. Right-click the OpenShift Container Platform connectionNewApplication.

    The Select template window appears.

    crs crc os selecting template
  7. Select a template.
  8. Click Next.

    The Template Parameters window appears.

    crs template parameters
  9. Ensure that the template parameters are correct.
  10. Click Next.

    The Resource Labels window appears.

    crs os resource label
  11. Click Add to add labels.
  12. Click Finish.

    The Create Application Summary window appears.

    crs os app summary
  13. Ensure that the application details are correct.
  14. Click OK.

    The Import OpenShift Application window appears.

    crs git clone location
  15. Choose the location for your git repository clone.
  16. Click Finish.

Your newly created OpenShift Container Platform application is now listed in the OpenShift Explorer view.

Additional Resources

2.1.4. Importing an existing OpenShift Container Platform application into CodeReady Studio

The OpenShift Explorer view in CodeReady Studio lists applications associated with your OpenShift Container Platform accounts. You can import the source code for these applications individually into CodeReady Studio using the Import OpenShift Application wizard. After the application is imported, you can easily modify the application source code, build the application, and view it in a web browser.

Prerequisites

  • The application that you are importing into CodeReady Studio has its source specified in the build config file.
  • A running OpenShift cluster.
  • An OpenShift Container Platform connection.

    For more information on how to create an OpenShift Container Platform connection, see Creating a new OpenShift Container Platform connection.

Procedure

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

    The Show View window appears.

    crs os explorer view
  3. Enter OpenShift in the search field.
  4. Select OpenShift Explorer.
  5. Click Open.

    The OpenShift Explorer view appears.

    crs import os app
  6. Right-click your OpenShift Container Platform connectionImport OpenShift Application.

    The Select Build Config window appears.

    crs select build config
  7. Select the application you want to import.
  8. Click Next.

    The Import OpenShift Application window appears.

    crs git clone location
  9. Select your Git Clone Location.
  10. Click Finish.

Your newly imported OpenShift Container Platform application is now listed in the OpenShift Explorer view.

2.1.5. Deploying an application using the server adapter

The server adapter enables you to publish the changes that you made in your workspace project to the running OpenShift application on the OpenShift instance. It enables incremental deployment of applications directly into the deployed pods on OpenShift. You can use the server adapter to push changes in your application directly to the running OpenShift application without committing the source code to the Git repository.

Prerequisites

Procedure

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

    The Show View window appears.

    crs os explorer view
  3. Enter OpenShift in the search field.
  4. Select OpenShift Explorer.
  5. Click Open.

    The OpenShift Explorer view appears.

    crs os app server adapter
  6. Expand the OpenShift Container Platform connection.
  7. Right-click your applicationServer Adapter.

    The Server Settings window appears.

    crs os server settings
    Note

    If you are using EAP 7.3, you need to set the path for the deployment of your server adapter due to changes in the templates.

    To do so, uncheck the Use inferred Pod Deployment Path checkbox and set the Pod Deployment Path field to /opt/eap/standalone/deployments/.

  8. Click Finish.

The Servers view appears, starting your server adapter.

To open your application in a browser, right-click applicationShow InWeb Browser.

crs os app show in browser

The CodeReady Studio built-in web browser opens, displaying your application.

2.1.6. Deleting an OpenShift Container Platform project

You may choose to delete a project from the workspace for a fresh start in project development or after you have concluded development in a project. When you delete a project, all resources associated with the project are deleted as well.

Prerequisites

  • An existing OpenShift Container Platform project.

Procedure

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

    The Show View window appears.

    crs os explorer view
  3. Enter OpenShift in the search field.
  4. Select OpenShift Explorer.
  5. Click Open.

    The OpenShift Explorer view appears.

    crs os project delete
  6. Expand the OpenShift Container Platform connection.
  7. Right-click your projectDelete.

    A Delete OpenShift Resource window prompts you for consent.

  8. Click OK.

Your project is now deleted.

2.2. Setting up and remotely monitoring an OpenShift Container Platform application in CodeReady Studio

CodeReady Studio allows users to set up a connection to a remote instance of OpenShift Container Platform and use application and build logs to troubleshoot and monitor running applications.

Prerequisites

2.2.1. Setting up OpenShift Client Binaries

Before setting up port forwarding or streaming application and build logs, set up OpenShift Client Binaries.

Procedure

  1. Start CodeReady Studio.
  2. Click WindowPreferences.

    The Preferences window appears.

    crs jboss os
  3. Enter OpenShift in the search field.
  4. Select OpenShift.
  5. Click Browse to locate the oc executable.
  6. Click Apply and Close.

OpenShift Client Binaries are now set up.

2.2.2. Setting up Port Forwarding

Using the Application Port Forwarding window, you can connect local ports to their remote counterparts to access data or debug your application.

Port forwarding automatically stops due to any of the following reasons:

  • The OpenShift Container Platform connection terminates
  • CodeReady Studio shuts down
  • The workspace is changed

Port forwarding must be enabled each time to connect to OpenShift Container Platform from CodeReady Studio.

Procedure

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

    The Show View window appears.

    crs os explorer view
  3. Enter OpenShift in the search field.
  4. Select OpenShift Explorer.
  5. Click Open.

    The OpenShift Explorer view appears.

    crs port forwarding
  6. Expand the OpenShift Container Platform connection.
  7. Right-click your applicationPort Forwarding.

    The Port Forwarding window appears.

    crs start port forwarding
  8. Check the Find free local ports for remote ports box.
  9. Click Start All.
  10. Click OK.

The Console view appears showing the port-forwarding starting process.

2.2.3. Streaming Pod Logs

Pod logs are general logs for an application running on a remote OpenShift Container Platform instance. The streaming pod logs feature in CodeReady Studio is used to monitor applications and use the previous pod log to troubleshoot if the application fails or returns errors.

Procedure

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

    The Show View window appears.

    crs os explorer view
  3. Enter OpenShift in the search field.
  4. Select OpenShift Explorer.
  5. Click Open.

    The OpenShift Explorer view appears.

    crs pod log
  6. Expand the OpenShift Container Platform connection.
  7. Right-click the applicationPod Log.

The Console view appears displaying the Pod Log.

2.2.4. Streaming Build Logs

Build logs are logs that document changes to applications running on a remote OpenShift Container Platform instance. The streaming build logs feature in CodeReady Studio is used to view the progress of the application build process and to debug the application.

Procedure

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

    The Show View window appears.

    crs os explorer view
  3. Enter OpenShift in the search field.
  4. Select OpenShift Explorer.
  5. Click Open.

    The OpenShift Explorer view appears.

    crs streaming build logs
  6. Expand the OpenShift Container Platform connection.
  7. Right-click the applicationBuild Log.

The Console view appears displaying the Build Log.

2.3. Additional resources