Accessing OpenShift through the command line

  1. Download the OpenShift terminal client (oc executable) to your workstation. Note: Some commands require a recent version of oc so re-download if you have an old version.

    1. Windows
    2. Linux
    3. macOS on Intel

      • On macOS, you may need to remove the download quarantine before extracting the file. Open Terminal, change directory to where you downloaded the file and run:
        xattr -d com.apple.quarantine openshift*
        
    4. macOS on ARM/AArch

      • On macOS, you may need to remove the download quarantine before extracting the file. Open Terminal, change directory to where you downloaded the file and run:
        xattr -d com.apple.quarantine openshift*
        
  2. Unzip/extract the openshift-client-* download into some directory

  3. Open a Terminal or Command Prompt application and change directory to where you expanded the openshift-client-* download
  4. Add this directory to your PATH by replacing $OCDIR with this directory:

    1. macOS/Linux:

      export PATH=$OCDIR:$PATH
      

      For example:

      export PATH=${HOME}/Downloads/openshift-client-mac/:$PATH
      
    2. Windows Command Prompt:

      set PATH=$OCDIR;%PATH%
      

      For example:

      set PATH=%HOMEPATH%\Downloads\openshift-client-windows\;%PATH%
      
    3. Windows Cygwin terminal:

      export PATH=$OCDIR:$PATH
      

      For example:

      export PATH=${HOMEPATH}/Downloads/openshift-client-windows/:$PATH
      
  5. Open your browser to the OpenShift web console at https://console-openshift-console.$CLUSTER_DOMAIN_NAME/

  6. In the top right, click on your name } Copy Login Command } Log-in again } Display Token } Copy the oc login command
  7. Paste and run the oc login command in the Terminal or Command Prompt opened in step 3 above.
    1. The most common error is certificate is not trusted when using a test cluster. In this case, add --insecure-skip-tls-verify.
    2. See the Frequently Asked Questions (FAQ) for other common login errors.
  8. Run oc whoami to confirm everything works.
  9. If you have been provided a namespace that you should use, then set your current namespace, replacing $NAMESPACE in the following command:
    oc config set-context --current --namespace $NAMESPACE