Connecting to OpenShift as a pre-requisite

OpenShift is a pre-requisite if the setup is about to be tested on OpenShift. It needs to be completed before Installing Keycloak on OpenShift can begin.

Prerequisites

This requires a running OpenShift instance, any OpenShift instance should work.

To set up OpenShift on AWS, use Red Hat OpenShift Service on AWS (ROSA).

URL to the console of OpenShift

Usually a URL in the form of:

https://console-openshift-console.apps.<domain name>/
URL to the API of OpenShift

Usually a URL in the form of:

https://api.<domain name>:6443/
User credentials

OpenShift user login name and password with cluster-admin role to be able to install custom resource definitions.

Connecting to OpenShift

  1. Log in to the OpenShift console.

  2. Navigate to the question mark icon (?) in the upper right corner and choose Command line tools

  3. Download the oc binary for your operating system.

  4. On Linux, extract it to the folder ~/.bin

  5. Add the following snippet to the file ~/.bashrc to allow auto-completion of commands:

    source <(oc completion bash)

Verifying the installation

The command:

oc version

Should print an output like:

Client Version: 4.12.0-...
Kustomize Version: v4.5.7
Server Version: 4.12.13
Kubernetes Version: v1.25.8+27e744f

The major and minor version for the client and the server should match (4.12 in the example shown above).

Logging in on the command line

Use the following command to log in on the command line and have it prompt for the password. Once you log in, the context switches automatically to that cluster. To switch back for example to the minikube cluster, see Switching between different Kubernetes clusters below.

oc login https://api.<domain name>:6443 -u <username>
The session will expire approximately one a day, and you’ll need to re-login.

Enable alert routing for user-defined projects

By default, OpenShift HCP doesn’t enable alert routing for user-defined projects.

Apply the following ConfigMap cluster-monitoring-config.yaml which is located in the /provision/openshift folder to OpenShift:

kubectl apply -n openshift-monitoring -f cluster-monitoring-config.yaml

After this has been deployed, several new pods spin up in the openshift-user-workload-monitoring namespace:

kubectl get pods -n openshift-user-workload-monitoring

Alerts defined in PrometheusRule CR are then available to view in the menu entry Observe→Alerting in the OpenShift console.

Further reading:

Switching between different Kubernetes clusters

To switch between different clusters, use the following commands:

List available contexts to switch between
kubectl config get-contexts
Select/Input the Context to Switch to
kubectl config use-context <context>