IBM Cloud Docs
Setting up your first classic cluster in the CLI

Setting up your first classic cluster in the CLI

Classic infrastructure

In this tutorial, you deploy an Red Hat OpenShift on IBM Cloud cluster on Classic infrastructure by using the CLI.

Audience

This tutorial is designed for cluster administrators who want to learn how to create a Red Hat OpenShift on IBM Cloud cluster for the first time by using the CLI.

Objectives

In this tutorial, you complete the following tasks.

  • Create a cluster in Washington, DC with 2 worker nodes that have 4 cores and 16 GB memory.
  • Open the Red Hat OpenShift web console.
  • Deploy a sample app.
  • Expose the app on a Route so that external users can access the service.

What you'll get

In this tutorial, you create the following resources by using the CLI. There are optional steps to delete these resources if you don't want to keep them after completing the tutorial.

  • A classic cluster with 2 worker nodes
  • A simple Hello World app deployed to your cluster
  • A route to expose your app

Overview of cluster resources

Review the following diagram for an overview of common cluster resources.

Cluster architecture
Figure 1. Cluster architecture

Prerequisites

  1. Check your permissions. If you are the account owner, you already have the required permissions to create a cluster and can continue to the next step. If you are not the account owner, ask the account owner to set up an API key and assign you required permissions in IBM Cloud IAM.

  2. Install the IBM Cloud CLI tools.

Create a Red Hat OpenShift on IBM Cloud cluster

  1. Log in to your account and resource group. If you have a federated account, include the --sso option.

    ibmcloud login [-g RESOURCE GROUP] [--sso]
    
  2. Run the following command to create a version 4.14 cluster in Washington, DC with 2 worker nodes that have 4 cores and 16 GB memory.

    ibmcloud oc cluster create classic --name my-tutorial-cluster --location wdc04 --version 4.14_openshift --flavor b3c.4x16  --workers 2 --public-service-endpoint
    
  3. Your cluster creation might take some time to complete. After the cluster state shows Normal, the cluster network and Ingress components take about 10 more minutes to deploy and update the cluster domain that you use for the Red Hat OpenShift web console and other routes.

  4. List your cluster details. Review the cluster State, check the Ingress Subdomain, and note the Master URL.

    ibmcloud oc cluster get --cluster <cluster_name_or_ID>
    
  5. Download and add the kubeconfig configuration file for your cluster.

    ibmcloud oc cluster config --cluster <cluster_name_or_ID>
    
  6. In your browser, navigate to the address of your Master URL and append /console. For example, https://c0.containers.cloud.ibm.com:23652/console.

  7. Click your profile IAM#user.name@email.com > Copy Login Command. Display and copy the oc login token command into your command line to authenticate via the CLI.

  8. Verify that the oc commands run properly with your cluster by checking the version.

    oc version
    

    Example output

    Client Version: v4.14.0
    Kubernetes Version: v1.29.4.2
    

    If you can't perform operations that require Administrator permissions, such as listing all the worker nodes or pods in a cluster, download the TLS certificates and permission files for the cluster administrator by running the ibmcloud oc cluster config --cluster <cluster_name_or_ID> --admin command.

Navigate the Red Hat OpenShift console

  1. From the Red Hat OpenShift clusters console, select your Red Hat OpenShift cluster, then click OpenShift web console.
  2. To work with your cluster in the CLI, click your profile IAM#user.name@email.com > Copy Login Command. Display and copy the oc login token command into your command line to authenticate by using the CLI.

Deploy an app to your cluster

  1. Create a project for your Hello World app.

    oc new-project hello-world
    
  2. Build the sample app from the source code by using the oc new-app command.

    oc new-app --name hello-world https://github.com/IBM/container-service-getting-started-wt --context-dir="Lab 1"
    

    A warning message might be displayed in the output, but it does not affect this example.

  3. List the hello-world services and note the service name. Your app listens for traffic on these internal cluster IP addresses unless you create a route for the service so that the Ingress controller can forward external traffic requests to the app.

    oc get svc -n hello-world
    

    Example output

    NAME          TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
    hello-world   ClusterIP   172.21.xxx.xxx   <none>       8080/TCP   31m
    
  4. List the pods and make sure that the hello-world pods status is Running and the build and deploy pods are Completed

    oc get pods -n hello-world
    

    Example output

    NAME                  READY     STATUS             RESTARTS   AGE
    hello-world-1-9cv7d   1/1       Running            0          30m
    hello-world-1-build   0/1       Completed          0          31m
    hello-world-1-deploy  0/1       Completed          0          31m
    
  5. Set up a route so that you can publicly access the hello world service.

    oc create route edge --service=hello-world -n hello-world
    
  6. Get the route hostname address from the Host/Port output.

    oc get route -n hello-world
    

    Example output

    NAME          HOST/PORT                         PATH                                        SERVICES      PORT       TERMINATION   WILDCARD
    hello-world   hello-world-hello.world.CLUSTER-NAME-RANDOM-ID.REGION.containers.appdomain.cloud    hello-world   8080-tcp   edge/Allow    None
    
  7. Access your app. Be sure to append https:// to your route hostname. It might take a minute before the exposed service is visible.

    curl https://hello-world-hello-world.CLUSTER-NAME-RANDOM-ID.REGION.containers.appdomain.cloud
    

    Example output

    Hello world from hello-world-9cv7d! Your app is up and running in a cluster!
    

Clean up the tutorial resources

  1. List the resources in the hello-world project.
    oc get all -l app=hello-world -o name -n hello-world
    
    Example output
    pod/hello-world-1-dh2ff
    replicationcontroller/hello-world-1
    service/hello-world
    deploymentconfig.apps.openshift.io/hello-world
    buildconfig.build.openshift.io/hello-world
    build.build.openshift.io/hello-world-1
    imagestream.image.openshift.io/hello-world
    imagestream.image.openshift.io/node
    route.route.openshift.io/hello-world
    
  2. Delete the resources.
    oc delete all -l app=hello-world -n hello-world
    

What's next?

For more information about working with your apps, see the Red Hat OpenShift developer activities documentation.

Install two popular Red Hat OpenShift on IBM Cloud add-ons: IBM Log Analysis and IBM Cloud Monitoring.