Deploying and Debugging Containers

The source code for this section is contained in the 02_02 branch of the GitHub repository for this course.

The whole point of OpenShift is to be able to deploy, run, and monitor containerized applications. DevOps engineers can deploy containers in OpenShift clusters through various means, for example:

  • Using a YAML manifest.

  • Deploying a single container using the web console.

  • Building a project stored in a Git repository anywhere on the Internet and deploying the resulting container.

  • Using the integrated CI/CD pipelines.

  • Using the odo tool together with "Devfiles."

Each approach has pros and cons; in this chapter, we will review how to use the web console and how to use the odo tool.

Deploying Applications with the Web Console

DevOps engineers can deploy applications immediately using the Web Console. Launch your CRC instance and open the web console in your preferred web browser. The URL of the OpenShift web console is "https://console-openshift-console.apps-crc.testing."

The OpenShift Web Console offers two major perspectives:

  • The "Administrator" perspective.

  • And the "Developer" perspective.

For this explanation, select the "Developer" perspective.

The first time you open the Developer perspective, a popup invites you to follow a user interface tour.

On the left-hand side, the perspective menu shows an entry titled "Add," which, as the name implies, provides various mechanisms to deploy applications on an OpenShift cluster.

The "Add" screen shows the various ways DevOps engineers can deploy applications on a cluster:

  • Using the Developer Catalog, browsing and choosing among a long list of available databases, message queues, and other valuable components to build applications, or entering your preferred Helm chart repository to extend the catalog.

  • Specifying the URL to a specific container on any standard container registry.

  • Specifying the URL of a source code project stored on a Git repository, for example, but not limited to GitHub, GitLab, Gitea, or other locations.

  • Importing YAML directly or even a JAR file with a Java application.

Let us select the "Container Image" option, where we can specify the URL of a ready-to-use container.

Enter the URL of the container on the field, and click on the Create button at the bottom of the page. You do not need to change any other value on the form.

A few seconds later, depending on the size of the container and the speed of your Internet connection, OpenShift will have pulled the container and deployed it onto your cluster. This deployment will include the usual standard elements: a "Deployment" object, a "Service" object, and a "Route."

OpenShift offers a visual representation of the applications running on your project: click on the icon of your container, and you will see a panel opening on the right side of the screen. This panel will include the URL automatically assigned to your deployment, and clicking it will show the application in action in another browser tab.

topology screen
Figure 1. Topology screen on Red Hat OpenShift

Creating and Debugging Applications with the odo Tool

With the oc tool, Red Hat provides another one geared toward software developers: the odo tool. Developers can use the odo tool to create applications using "Devfiles," particular files named "devfile.yaml" based on an open standard available at the Devfiles website. Devfiles contain information about your application’s programming language, dependencies, and other essential details.

The odo tool is not available by default on your command line, but you can download it from the "Help" menu on the OpenShift Web Console through the "Command line tools" entry. Click on the "Download odo" link at the bottom, and select the version of odo that corresponds to your system.

The "odo catalog list components was" command shows the various programming languages and frameworks supported off-the-box by "odo."

The odo init command prompts the user for a new application using many programming languages: .NET, Go, Java, JavaScript, PHP, Python, and TypeScript. The last command generates a scaffold ready to be populated with the required logic. Finally, the odo push command builds and pushes the container to the OpenShift container registry, deploying a copy.

Developers can debug applications built with Node.js or Java directly from the command line using the odo tool. The command odo debug port-forward opens the required ports for developers to connect a debugger to their container, usually with the help of an IDE, and debug their application with breakpoints and step-by-step execution.