|
| 1 | +--- |
| 2 | +title: OpenShift CLI (oc) |
| 3 | + |
| 4 | +author: Jason Andrews |
| 5 | + |
| 6 | +official_docs: https://docs.redhat.com/en/documentation/openshift_container_platform/4.18/html/cli_tools/openshift-cli-oc#cli-getting-started |
| 7 | +minutes_to_complete: 10 |
| 8 | + |
| 9 | +additional_search_terms: |
| 10 | +- OpenShift |
| 11 | +- Kubernetes |
| 12 | + |
| 13 | +layout: installtoolsall |
| 14 | +multi_install: false |
| 15 | +multitool_install_part: false |
| 16 | +test_images: |
| 17 | +- ubuntu:latest |
| 18 | +test_maintenance: false |
| 19 | +tool_install: true |
| 20 | +weight: 1 |
| 21 | +--- |
| 22 | +The OpenShift command-line interface (CLI), `oc`, allows you to work with OpenShift Container Platform projects from a terminal. You can use `oc` to create applications, manage OpenShift Container Platform projects, and perform administrative tasks. |
| 23 | + |
| 24 | +The OpenShift CLI is a superset of the Kubernetes `kubectl` command. When you install `oc`, you get both the OpenShift-specific functionality and all standard Kubernetes `kubectl` commands in a single tool. This means you can use `oc` to manage both OpenShift and standard Kubernetes resources. |
| 25 | + |
| 26 | +The OpenShift CLI is available for macOS and Linux and supports the Arm architecture. |
| 27 | + |
| 28 | +## What should I consider before installing the OpenShift CLI? |
| 29 | + |
| 30 | +This article provides a quick solution to install the latest version of the OpenShift CLI for Ubuntu on Arm and macOS with Apple Silicon. |
| 31 | + |
| 32 | +Confirm that you are using an Arm-based computer by running: |
| 33 | + |
| 34 | +```bash { target="ubuntu:latest" } |
| 35 | +uname -m |
| 36 | +``` |
| 37 | + |
| 38 | +If you are on Arm Linux the output should be: |
| 39 | + |
| 40 | +```output |
| 41 | +aarch64 |
| 42 | +``` |
| 43 | + |
| 44 | +If you are on macOS with Apple Silicon the output should be: |
| 45 | + |
| 46 | +```output |
| 47 | +arm64 |
| 48 | +``` |
| 49 | + |
| 50 | +## How do I download and install the OpenShift CLI? |
| 51 | + |
| 52 | +There are multiple ways to install the OpenShift CLI. The methods below download the latest stable version directly from the OpenShift mirror. |
| 53 | + |
| 54 | +### Install on Arm Linux |
| 55 | + |
| 56 | +To install the OpenShift CLI on Arm Linux: |
| 57 | + |
| 58 | +```bash { target="ubuntu:latest" } |
| 59 | +curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux-arm64.tar.gz |
| 60 | +tar -xzf openshift-client-linux-arm64.tar.gz |
| 61 | +sudo mv oc kubectl /usr/local/bin/ |
| 62 | +rm openshift-client-linux-arm64.tar.gz README.md |
| 63 | +``` |
| 64 | + |
| 65 | +### Install on macOS |
| 66 | + |
| 67 | +To install the OpenShift CLI on macOS with Apple Silicon: |
| 68 | + |
| 69 | +```console |
| 70 | +curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-mac-arm64.tar.gz |
| 71 | +tar -xzf openshift-client-mac-arm64.tar.gz |
| 72 | +sudo mv oc kubectl /usr/local/bin/ |
| 73 | +rm openshift-client-mac-arm64.tar.gz README.md |
| 74 | +``` |
| 75 | + |
| 76 | +Both installations include both `oc` and `kubectl` commands. The `oc` command provides the full OpenShift functionality, while the `kubectl` command gives you compatibility with standard Kubernetes clusters. Since `oc` is a superset of `kubectl`, you can use `oc` for all Kubernetes operations, but having both commands available gives you flexibility in your workflow. |
| 77 | + |
| 78 | +{{% notice Tip %}} |
| 79 | +You can use either `oc` or `kubectl` to manage standard Kubernetes resources. However, `oc` includes OpenShift-specific features and is preferred for working with OpenShift clusters. |
| 80 | +{{% /notice %}} |
| 81 | + |
| 82 | + |
| 83 | +## Understanding oc and kubectl |
| 84 | + |
| 85 | +The OpenShift CLI (`oc`) is built as a superset of the Kubernetes CLI (`kubectl`). |
| 86 | + |
| 87 | +This means: |
| 88 | + |
| 89 | +- You can use `oc` anywhere you would use `kubectl` |
| 90 | +- OpenShift-specific features such as `oc login`, `oc new-project`, `oc new-app`, are available to manage OpenShift resources |
| 91 | + |
| 92 | +## How do I verify the OpenShift CLI installation? |
| 93 | + |
| 94 | +Verify the OpenShift CLI is installed by checking the version: |
| 95 | + |
| 96 | +```bash { target="ubuntu:latest" } |
| 97 | +oc version --client |
| 98 | +``` |
| 99 | + |
| 100 | +The output shows the client version information: |
| 101 | + |
| 102 | +```output |
| 103 | +Client Version: 4.19.3 |
| 104 | +Kustomize Version: v5.5.0 |
| 105 | +``` |
| 106 | + |
| 107 | +You can also verify that `kubectl` is available and shows the same version (since it's the same binary): |
| 108 | + |
| 109 | +```bash { target="ubuntu:latest" } |
| 110 | +kubectl version --client |
| 111 | +``` |
| 112 | + |
| 113 | +The output shows the kubectl client version: |
| 114 | + |
| 115 | +```output |
| 116 | +Client Version: v1.32.1 |
| 117 | +Kustomize Version: v5.5.0 |
| 118 | +``` |
| 119 | + |
| 120 | +Both commands are now available for managing Kubernetes and OpenShift resources. |
| 121 | + |
| 122 | +## How do I get started with the OpenShift CLI? |
| 123 | + |
| 124 | +To get help with available commands, run: |
| 125 | + |
| 126 | +```console |
| 127 | +oc help |
| 128 | +``` |
| 129 | + |
| 130 | +This displays the main command groups and options: |
| 131 | + |
| 132 | +```output |
| 133 | +OpenShift Client |
| 134 | +
|
| 135 | +This client helps you develop, build, deploy, and run your applications on any |
| 136 | +OpenShift or Kubernetes cluster. It also includes the administrative |
| 137 | +commands for managing a cluster under the 'adm' subcommand. |
| 138 | +
|
| 139 | +Usage: |
| 140 | + oc [flags] |
| 141 | +
|
| 142 | +Basic Commands: |
| 143 | + login Log in to a server |
| 144 | + new-project Request a new project |
| 145 | + new-app Create a new application |
| 146 | + status Show an overview of the current project |
| 147 | + project Switch to another project |
| 148 | + projects Display existing projects |
| 149 | + explain Get documentation for a resource |
| 150 | +
|
| 151 | +Build and Deploy Commands: |
| 152 | + rollout Manage the rollout of a resource |
| 153 | + rollback Revert part of an application back to a previous deployment |
| 154 | + new-build Create a new build configuration |
| 155 | + start-build Start a new build |
| 156 | + cancel-build Cancel running, pending, or new builds |
| 157 | + import-image Import images from a Docker registry |
| 158 | + tag Tag existing images into image streams |
| 159 | +
|
| 160 | +Application Management Commands: |
| 161 | + create Create a resource from a file or from stdin |
| 162 | + apply Apply a configuration to a resource by file name or stdin |
| 163 | + get Display one or many resources |
| 164 | + describe Show details of a specific resource or group of resources |
| 165 | + edit Edit a resource on the server |
| 166 | + set Commands that help set specific features on objects |
| 167 | + label Update the labels on a resource |
| 168 | + annotate Update the annotations on a resource |
| 169 | + expose Expose a replicated application as a service or route |
| 170 | + delete Delete resources by file names, stdin, resources and names, or by resources and label selector |
| 171 | + scale Set a new size for a deployment, replica set, or replication controller |
| 172 | + autoscale Autoscale a deployment or replica set |
| 173 | + secrets Manage secrets |
| 174 | + serviceaccounts Manage service accounts in your project |
| 175 | +
|
| 176 | +Troubleshooting and Debugging Commands: |
| 177 | + logs Print the logs for a resource |
| 178 | + rsh Start a shell session in a pod |
| 179 | + rsync Copy files between a local file system and a pod |
| 180 | + port-forward Forward one or more local ports to a pod |
| 181 | + debug Launch a new instance of a pod for debugging |
| 182 | + exec Execute a command in a container |
| 183 | + proxy Run a proxy to the Kubernetes API server |
| 184 | + attach Attach to a running container |
| 185 | + run Run a particular image on the cluster |
| 186 | + cp Copy files and directories to and from containers |
| 187 | + wait Experimental: Wait for a specific condition on one or many resources |
| 188 | +
|
| 189 | +Advanced Commands: |
| 190 | + adm Tools for managing a cluster |
| 191 | + create Create a resource from a file or from stdin |
| 192 | + replace Replace a resource by file name or stdin |
| 193 | + patch Update fields of a resource |
| 194 | + process Process a template into list of resources |
| 195 | + export Export resources so they can be used elsewhere |
| 196 | + extract Extract secrets or config maps to disk |
| 197 | + observe Observe changes to resources and react to them (experimental) |
| 198 | + policy Manage authorization policy |
| 199 | + auth Inspect authorization |
| 200 | + image Useful commands for managing images |
| 201 | + registry Commands for working with the registry |
| 202 | + idle Idle scalable resources |
| 203 | + api-versions Print the supported API versions on the server, in the form of "group/version" |
| 204 | + api-resources Print the supported API resources on the server |
| 205 | + cluster-info Display cluster information |
| 206 | + diff Diff the live version against a would-be applied version |
| 207 | + kustomize Build a kustomization target from a directory or URL |
| 208 | +
|
| 209 | +Settings Commands: |
| 210 | + logout End the current server session |
| 211 | + config Modify kubeconfig files |
| 212 | + whoami Return information about the current session |
| 213 | + completion Output shell completion code for the specified shell (bash, zsh, fish, or powershell) |
| 214 | +
|
| 215 | +Other Commands: |
| 216 | + help Help about any command |
| 217 | + plugin Provides utilities for interacting with plugins |
| 218 | + version Print the client and server version information |
| 219 | +
|
| 220 | +Use "oc <command> --help" for more information about a given command. |
| 221 | +Use "oc options" for a list of global command-line options (applies to all commands). |
| 222 | +``` |
| 223 | + |
| 224 | +To connect to an OpenShift cluster, you need to log in using: |
| 225 | + |
| 226 | +```console |
| 227 | +oc login <cluster-url> |
| 228 | +``` |
| 229 | + |
| 230 | +Replace `<cluster-url>` with your OpenShift cluster's URL. You will be prompted for your username and password. |
| 231 | + |
| 232 | +You are now ready to use the OpenShift CLI to manage your OpenShift Container Platform projects and applications. |
0 commit comments