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:
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).
Log in to the IBM Cloud CLI. Enter your IBM Cloud credentials when prompted.
ibmcloud loginIf 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.
- 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- 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-registryTo 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-serviceVerify that the plug-ins are installed correctly.
ibmcloud plugin listExample output:
Listing installed plug-ins... Plugin Name Version Status container-registry 0.1.404 container-service/kubernetes-service 0.4.66For 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.
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.
- OpenShift Container Platform version 3 oc download link
- OpenShift Container Platform version 4 oc download links
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.
For clusters that run OpenShift 3.11: Download at least version 1.15. Because earlier kubectl versions are no longer supported, the kubectl version that you use for the OpenShift 3.11, Kubernetes 1.11 cluster cannot meet the +/- 1 skew policy. Instead, use at least kubectl version 1.15 to protect the cluster from Common Vulnerability and Exposures (CVEs) that might arise in unsupported versions.
- OS X: https://storage.googleapis.com/kubernetes-release/release/v1.15.11/bin/darwin/amd64/kubectl
- Linux: https://storage.googleapis.com/kubernetes-release/release/v1.15.11/bin/linux/amd64/kubectl
- Windows: Install the Kubernetes CLI in the same directory as the IBM Cloud CLI. This setup saves you some file path changes when you run commands later. https://storage.googleapis.com/kubernetes-release/release/v1.15.11/bin/windows/amd64/kubectl.exe
For clusters that run OpenShift 4: Download kubectl version that matches the Kubernetes version of our OpenShift cluster. For supported versions, see OpenShift versions.
- OS X: https://storage.googleapis.com/kubernetes-release/release/v1.18.9/bin/darwin/amd64/kubectl
- Linux: https://storage.googleapis.com/kubernetes-release/release/v1.18.9/bin/linux/amd64/kubectl
- Windows: Install the Kubernetes CLI in the same directory as the IBM Cloud CLI. This setup saves you some file path changes when you run commands later. https://storage.googleapis.com/kubernetes-release/release/v1.18.9/bin/windows/amd64/kubectl.exe
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.
If you use Mac OS or Linux, complete the following steps to add the binary files to your PATH system variable.
Move the oc and kubectl executable files to the /usr/local/bin directory.
mv /<filepath>/oc /usr/local/bin/ocmv /<filepath>/kubectl /usr/local/bin/kubectlMake 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 $PATHExample CLI output:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin- 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:
Update the IBM Cloud CLI. Download the latest version and run the installer.
Log in to the IBM Cloud CLI. Enter your IBM Cloud credentials when prompted.
ibmcloud loginIf 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.
Update the Red Hat OpenShift on IBM Cloud plug-in.
Install the update from the IBM Cloud plug-in repository.
ibmcloud plugin update kubernetes-serviceVerify the plug-in installation by running the following command and checking the list of the plug-ins that are installed.
ibmcloud plugin listThe Red Hat OpenShift on IBM Cloud plug-in is displayed in the results as kubernetes-service.
Initialize the CLI.
ibmcloud oc initUpdate the IBM Cloud Container Registry plug-in.
Install the update from the IBM Cloud plug-in repository.
ibmcloud plugin update container-registryVerify the plug-in installation by running the following command and checking the list of the plug-ins that are installed.
ibmcloud plugin listThe 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:
Uninstall the Red Hat OpenShift on IBM Cloud plug-in.
ibmcloud plugin uninstall kubernetes-serviceUninstall the IBM Cloud Container Registry plug-in.
ibmcloud plugin uninstall container-registryVerify the plug-ins were uninstalled by running the following command and checking the list of the plug-ins that are installed.
ibmcloud plugin listThe kubernetes-service and the container-registry plug-in are not displayed in the results.
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:
- In the IBM Cloud console menu bar, click the Cloud Shell icon
.
- A session starts and automatically logs you in to the IBM Cloud CLI with your current account credentials.
- Access the cluster by getting the oc login token.
- In the Red Hat OpenShift on IBM Cloud console, click the cluster that we want to access.
- In the Actions... drop-down list, select Connect via CLI.
- 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.