+

Search Tips   |   Advanced Search

Installing the OpenShift CLI

We can use the Red Hat OpenShift on IBM Cloud command line interface (CLI) plug-in (ibmcloud oc) to create and manage the OpenShift cluster infrastructure, such as creating clusters and worker nodes. Then, we can use the OpenShift CLI (oc) to manage the resources within the OpenShift cluster, such as projects, pods, and deployments. To use the API, see Set up the API.


Installing the IBM Cloud CLI and plug-ins

Install the required CLIs to create and manage the OpenShift clusters in Red Hat OpenShift on IBM Cloud, and to deploy containerized apps to the cluster.

This task includes the information for installing these CLIs and plug-ins:

  • IBM Cloud CLI (ibmcloud)
  • Red Hat OpenShift on IBM Cloud plug-in (ibmcloud oc alias for OpenShift clusters)
  • IBM Cloud Container Registry plug-in (ibmcloud cr)
  • IBM Cloud Kubernetes Service observability plug-in (ibmcloud ob)

To use the IBM Cloud console instead, we can run CLI commands directly from your web browser in the IBM Cloud Shell.


To install the CLIs:

  1. Install the stand-alone IBM Cloud CLI (ibmcloud).

    Plan to use the CLI often? Try Enabling shell autocompletion for IBM Cloud CLI (Linux/macOS only).

  2. Log in to the IBM Cloud CLI. Enter your IBM Cloud credentials when prompted.

    ibmcloud login
    

    If we have a federated ID, use ibmcloud login --sso to log in to the IBM Cloud CLI. Enter your username and use the provided URL in your CLI output to retrieve your one-time passcode. You know we have a federated ID when the login fails without the --sso and succeeds with the --sso option.

  3. Install the IBM Cloud plug-in for Red Hat OpenShift on IBM Cloud (ibmcloud oc). Use this plug-in to create and manage Red Hat OpenShift on IBM Cloud resources such as clusters, worker nodes, or network load balancers.
    ibmcloud plugin install container-service
    
  4. Install the IBM Cloud plug-in for IBM Cloud Container Registry (ibmcloud cr). Use this plug-in to set up your own namespace in a multi-tenant, highly available, and scalable private image registry that is hosted by IBM, and to store and share Docker images with other users. Docker images are required to deploy containers into a cluster.
    ibmcloud plugin install container-registry
    
  5. To create a logging configuration for IBM Log Analysis with LogDNA or a monitoring configuration for IBM Cloud Monitoring with Sysdig for the cluster, install the IBM Cloud Kubernetes Service observability plug-in (ibmcloud ob).

    ibmcloud plugin install observe-service
    
  6. Verify that the plug-ins are installed correctly.

    ibmcloud plugin list
    

    Example output:

    Listing installed plug-ins...
    
    Plugin Name                            Version   Status
    container-registry                     0.1.404
    container-service/kubernetes-service   0.4.66
    

For reference information about these CLIs, see the documentation for those tools.



Installing the OpenShift Origin CLI (oc)

To view a local version of the OpenShift dashboard and to deploy apps into your Red Hat OpenShift on IBM Cloud clusters, install the OpenShift CLI (oc) and Kubernetes CLI (kubectl). For more information, see the OpenShift docs.

Using both community Kubernetes and OpenShift clusters? Your clusters might run different versions of Kubernetes, such as 1.11 on OpenShift and 1.18.9 on Ubuntu. Make sure to use the kubectl binary file that matches the +/- 1 skew policy for the cluster major.minor OpenShift and Kubernetes versions. For supported versions, see OpenShift versions.

  1. Download the latest OpenShift CLI (oc) for the local operating system and OpenShift version. The current default OpenShift version is 4.4. If you use Windows, install the oc CLI in the same directory as the IBM Cloud CLI. This setup saves you some file path changes when you run commands later.

  2. Download the Kubernetes CLI (kubectl) for the OpenShift cluster. We might use different kubectl versions if we have community Kubernetes clusters that run other Kubernetes versions such as 1.19.2.

    If we have multiple clusters that run different versions of Kubernetes, we can download separate kubectl binary files. Then, set up an alias in the local terminal profile to point to the separate binary files that match the version of kubectl the cluster needs.

  3. If you use Mac OS or Linux, complete the following steps to add the binary files to your PATH system variable.

    1. Move the oc and kubectl executable files to the /usr/local/bin directory.

      mv /<filepath>/oc /usr/local/bin/oc
      
      mv /<filepath>/kubectl /usr/local/bin/kubectl
      
    2. Make sure that /usr/local/bin is listed in your PATH system variable. The PATH variable contains all directories where your operating system can find executable files. The directories that are listed in the PATH variable serve different purposes. /usr/local/bin is used to store executable files for software that is not part of the operating system and that was manually installed by the system administrator.

      echo $PATH
      

      Example CLI output:

      /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
      
  4. Optional: Enable autocompletion for kubectl commands. The steps vary depending on the shell that you use. We can repeat the steps to enable autocompletion for oc commands. For example, in bash on Linux, instead of kubectl completion bash >/etc/bash_completion.d/kubectl, we can run oc completion bash >/etc/bash_completion.d/oc_completion.

Next, start Creating a Red Hat OpenShift on IBM Cloud cluster.

For more information about the oc CLI, see the OpenShift documentation.



Updating the CLI

Update the CLIs regularly to use new features.

This task includes the information for updating the following CLIs:

  • IBM Cloud CLI version 0.8.0 or later
  • Red Hat OpenShift on IBM Cloud plug-in
  • OpenShift CLI
  • IBM Cloud Container Registry plug-in


To update the CLIs:

  1. Update the IBM Cloud CLI. Download the latest version and run the installer.

  2. Log in to the IBM Cloud CLI. Enter your IBM Cloud credentials when prompted.

     ibmcloud login
    

    If we have a federated ID, use ibmcloud login --sso to log in to the IBM Cloud CLI. Enter your username and use the provided URL in your CLI output to retrieve your one-time passcode. You know we have a federated ID when the login fails without the --sso and succeeds with the --sso option.

  3. Update the Red Hat OpenShift on IBM Cloud plug-in.

    1. Install the update from the IBM Cloud plug-in repository.

      ibmcloud plugin update kubernetes-service
      
    2. Verify the plug-in installation by running the following command and checking the list of the plug-ins that are installed.

      ibmcloud plugin list
      

      The Red Hat OpenShift on IBM Cloud plug-in is displayed in the results as kubernetes-service.

    3. Initialize the CLI.

      ibmcloud oc init
      
  4. Update the OpenShift CLI.

  5. Update the IBM Cloud Container Registry plug-in.

    1. Install the update from the IBM Cloud plug-in repository.

      ibmcloud plugin update container-registry
      
    2. Verify the plug-in installation by running the following command and checking the list of the plug-ins that are installed.

      ibmcloud plugin list
      

      The registry plug-in is displayed in the results as container-registry.



Uninstalling the CLI

If you no longer need the CLI, we can uninstall it.

This task includes the information for removing these CLIs:

  • Red Hat OpenShift on IBM Cloud plug-in
  • IBM Cloud Container Registry plug-in

To uninstall the CLIs:

  1. Uninstall the Red Hat OpenShift on IBM Cloud plug-in.

    ibmcloud plugin uninstall kubernetes-service
    
  2. Uninstall the IBM Cloud Container Registry plug-in.

    ibmcloud plugin uninstall container-registry
    
  3. Verify the plug-ins were uninstalled by running the following command and checking the list of the plug-ins that are installed.

    ibmcloud plugin list
    

    The kubernetes-service and the container-registry plug-in are not displayed in the results.

  4. Uninstall the IBM Cloud CLI.

  5. Uninstall the Kubernetes CLI.

    sudo rm /usr/local/bin/oc
    



Using the IBM Cloud Shell in your web browser

IBM® Cloud Shell allows you to use the IBM Cloud CLI and various CLI plug-ins to manage the cluster directly from your web browser.

The IBM Cloud Shell is enabled with several plug-ins and tools, including the base IBM Cloud CLI (ibmcloud), the IBM Cloud Kubernetes Service plug-in (ibmcloud oc), the IBM Cloud Container Registry plug-in (ibmcloud cr), and the OpenShift CLI (oc).

While you use the Cloud Shell, keep in mind the following limitations:

  • We can open up to five concurrent sessions, which operate independently so we can work with different resources, regions, and accounts at once.
  • Any files that you download and edit locally, such as YAML files, are stored temporarily in the Cloud Shell and do not persist across sessions.
  • Cloud Shell has a usage quota that limits you to 50 hours within a week.

To launch and use the IBM Cloud Shell:

  1. In the IBM Cloud console menu bar, click the Cloud Shell icon .
  2. A session starts and automatically logs you in to the IBM Cloud CLI with your current account credentials.
  3. Access the cluster by getting the oc login token.
    1. In the Red Hat OpenShift on IBM Cloud console, click the cluster that we want to access.
    2. In the Actions... drop-down list, select Connect via CLI.
    3. Follow the instructions.

      If we cannot or do not want to open the OpenShift console, we can set the cluster context with the --admin flag through the CLI.