Bookmark this page

Setting up the Developer Environment

Objectives

  • Set up the classroom and developer environment for the hands-on labs in the course.

Setting Up and Targeting a Development Cluster

To learn Kubernetes application development, you need a cluster where you can experiment and deploy your applications.

Red Hat provides several options to help you meet this requirement. For example, you can use the Developer Sandbox, which is a managed cluster option. You can also run your cluster locally by setting up Red Hat OpenShift Local.

Note

Although this lecture covers Red Hat OpenShift Local, the course does not use this edition of OpenShift in the lab environment. Instead, the lab environment provides a Red Hat OpenShift Container Platform cluster with all the tools that the course requires.

Setting up Red Hat OpenShift Local

Red Hat OpenShift Local facilitates the access to a local development cluster by providing a single node cluster that runs inside a virtual machine.

To install Red Hat OpenShift Local, you must log in to your Red Hat account and navigate to https://console.redhat.com/openshift/create/local. There, you can follow the instructions to download the crc CLI.

The crc CLI provides everything you need to work with Red Hat OpenShift Local. You can use crc to install, configure, and manage your local cluster.

Use the crc setup command to prepare your environment for running Red Hat OpenShift Local.

[user@host ~]$ crc setup

Then, you can run the crc start command to create the VM and set the cluster up. When the command completes, it prints the URL for the web console, and the credentials for the kubeadmin and the developer users.

[user@host ~]$ crc start
...output omitted...
INFO Adding crc-admin and crc-developer contexts to kubeconfig...
Started the OpenShift cluster.

The server is accessible via web console at:
  https://console-openshift-console.apps-crc.testing

Log in as administrator:
  Username: kubeadmin
  Password: xjnby-DXkQx-uaDfR-IChDX

Log in as user:
  Username: developer
  Password: developer

Use the 'oc' command line interface:
  $ eval $(crc oc-env)
  $ oc login -u developer https://api.crc.testing:6443

To stop the cluster, run the crc stop command.

You can use the crc delete command to remove the cluster and its data from your machine.

[user@host ~]$ crc delete

Accessing the Classroom Cluster

The classroom environment provides a Red Hat OpenShift cluster available and ready to use.

You can log in to the cluster web console by navigating to https://console-openshift-console.apps.ocp4.example.com. Then, click htpasswd_provider and log in by using the developer user with the developer password.

After you log in, the web console redirects you to the developer perspective, or to the page that you last visited. In the following screen capture, the web console, displays the Topology screen of the developer perspective.

Installing and Configuring the Development Tools

When you develop a Kubernetes application, you need additional tooling to create, publish, and deploy a container that runs that application. You also need tooling to manage the cluster.

These tools come in the form of CLIs, such as podman, oc and odo. You can also find GUIs like the OpenShift Toolkit IDE extension, or independent applications like Podman Desktop.

As a developer, you can use all these tools. The oc CLI also provides features for cluster administration.

Setting Up oc

You can download the oc CLI from the web console to ensure that the CLI commands are compatible with the cluster. From the Red Hat OpenShift web console, navigate to HelpCommand line tools. The Help menu is represented by a ? icon. The web console provides several installation options for the oc client, such as downloads for the following operating systems:

  • x86_64 Windows, Mac, and Linux systems

  • ARM 64 Linux and Mac systems

  • Linux for IBM Z, IBM Power, and little endian

Download the archive that contains the oc binary by clicking any of the download links. To use the oc binary, you must extract it and give it execute permissions if needed. Then, you can place oc in a directory within your execution path.

You can verify the version of the oc binary by running oc version. If you previously logged in to the cluster, then the command also prints the cluster version.

[user@host ~]$ oc version
Client Version: 4.12.0
Kustomize Version: v4.5.7
Server Version: 4.12.0
Kubernetes Version: v1.25.4+77bec7a

You can also download any oc version from the Red Hat Customer Portal by navigating to https://access.redhat.com/downloads/content/290. To download oc, you must select the Product Variant and the Version.

Then, search for the openshift-clients package on the Packages tab, and click Download Latest.

You can run the oc login command to log in to a cluster.

[user@host ~]$ oc login -u USERNAME -p PASSWORD CLUSTER_URL

The oc CLI uses a configuration file to store login information. This file is called the kubeconfig file. By default, the oc CLI tries to locate this file at the ~/.kube/config path.

Setting Up odo

The odo CLI is a developer-focused tool to build and deploy applications on Kubernetes.

To install the odo CLI, you can download the binary from the Red Hat Developer download page at https://developers.redhat.com/products/openshift/download. You can also find detailed installation instructions at https://odo.dev/docs/overview/installation.

After odo is available, you can use it to connect to the cluster by running the odo login command.

[user@host ~]$ odo login CLUSTER_URL

Note

The odo CLI uses the kubeconfig file to store login information. If you use another tool that updates the kubeconfig file, for example by logging in as a different cluster user, this also affects the current user for the odo session.

Setting up the VSCode OpenShift Toolkit Extension

To install the OpenShift Toolkit extension on VSCode, click Extension on the left menu bar, then search for OpenShift and click Install in the OpenShift Toolkit search result.

If a modal window shows, then Click Trust Workspace & Install.

Click the OpenShift button in the left menu bar to open the OpenShift side panel. To log in, click Login, and introduce the cluster URL.

You can choose to log in by using a token or user credentials. If you select Credentials, then the extension prompts for username and password.

After you log in, you see that the cluster menu is populated with the user projects.

Note

The OpenShift Toolkit extension uses the kubeconfig file to store login information. If you use another tool that updates the kubeconfig file, for example by logging in as a different cluster user, then this also affects the current user for the extension.

Setting up the OpenShift Toolkit Extension for IntelliJ-based IDEs

To install the OpenShift Toolkit extension on IntelliJ-based IDEs, navigate to FileSettings, then click Plugins and select the Marketplace tab. Type OpenShift in the search input box and click Install on the OpenShift Toolkit by Red Hat search result.

If the Install Required Plugins window asks to install the extension dependencies, then click Install. When the installation is complete click Restart IDE to apply the changes to the IDE.

After the IDE restarts, click OpenShift in the left menu bar to open the OpenShift side panel. Then, right-click the side panel, and click Log in to cluster, to open the Cluster login window.

After you log in, you see the cluster menu shows the user projects.

Setting Up Podman

To install podman, you can use your OS package manager, or follow the installation instructions at https://podman.io/docs/installation.

With podman in your system, you must log in to a container image registry to push and download images. To do this, you can run the podman login command.

[user@host ~]$ podman login -u USERNAME -p PASSWORD IMAGE_REGISTRY_URL

The classroom environment of this course provides an internal Quay image registry with the images that the course requires. You can access the registry web interface by navigating to https://registry.ocp4.example.com:8443. To log in, use the developer user with the developer password.

References

Red Hat OpenShift Local

Developer Sandbox

Red Hat OpenShift downloads page

odo Quickstart Guide

What is a kubeconfig file?

For more information about OpenShift Local system requirements, refer to the Minimum system requirements section in the Installation chapter in the Red Hat OpenShift Local 2.20 Getting Started Guide documentation at https://access.redhat.com/documentation/en-us/red_hat_openshift_local/2.20/html-single/getting_started_guide/index#minimum-system-requirements_gsg

For more information about installing OpenShift CLI, refer to the Installing the OpenShift CLI section in the OpenShift CLI (oc) chapter in the Red Hat OpenShift Container Platform 4.12 CLI tools documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.12/html-single/cli_tools/index#installing-openshift-cli

Revision: do288-4.12-0d49506