oc
Manage OpenShift clusters
TLDR
Log in to the OpenShift Container Platform server
Create a new project
Switch to an existing project
Add a new application to a project
Open a remote shell session to a container
List pods in a project
Log out from the current session
SYNOPSIS
oc <command> [<subcommand>] [options] [arguments]
The oc command operates on a subcommand structure, where the main command is followed by a specific action (e.g., get, apply, login, new-app), which may in turn have further subcommands and associated options and arguments.
PARAMETERS
--help, -h
Displays help information for the oc command or a specific subcommand.
--config=<path>
Path to the kubeconfig file to use for connection details.
--context=<name>
The name of the kubeconfig context to use, overriding the current context.
--namespace=<name>, -n <name>
If present, the namespace scope for the CLI request.
--server=<url>
The address and port of the OpenShift API server to connect to.
--token=<token>
Bearer token for authentication, used in conjunction with --server.
--insecure-skip-tls-verify
If true, the server's certificate will not be checked for validity. Use with caution.
--loglevel=<level>
Set the level of logging detail (e.g., 0 for silent, 9 for verbose).
DESCRIPTION
The oc command is the command-line interface (CLI) for interacting with OpenShift clusters. It provides a powerful set of tools for developers and administrators to manage applications, build processes, deployments, projects, and various OpenShift resources directly from the terminal.
While sharing much of its core functionality with kubectl (the Kubernetes CLI), oc extends capabilities with OpenShift-specific concepts like ImageStreams, BuildConfigs, DeploymentConfigs, Routes, and Projects. It allows users to log into a cluster, create and manage applications, initiate builds, scale deployments, inspect logs, debug issues, and perform administrative tasks such as managing users, roles, and security policies.
It is the primary tool for automating tasks and scripting interactions with OpenShift, providing comprehensive control over the platform's features.
CAVEATS
The oc command is not a standard Linux command available on all distributions by default. It is specifically designed for and used with Red Hat OpenShift Container Platform. It requires separate installation and a configured connection (via a kubeconfig file) to an OpenShift cluster to function correctly. Its functionality is heavily reliant on the OpenShift API and the specific version of the cluster being interacted with.
COMMON USAGE PATTERNS
The oc command is used for a variety of tasks:
- oc login: Authenticate to an OpenShift cluster.
- oc new-app: Create new applications from source code, images, or templates.
- oc project: Switch between OpenShift projects (namespaces).
- oc get <resource>: List various OpenShift resources (e.g., pods, services, deployments, routes).
- oc apply -f <file>: Apply configuration changes defined in a file.
- oc logs <pod>: View logs for a specific pod.
- oc rsh <pod>: Open a shell inside a running container.
HISTORY
The oc command was developed as part of the OpenShift Container Platform, an enterprise-grade Kubernetes distribution from Red Hat. Initially, OpenShift had its own orchestration engine (v2), but with OpenShift v3, it re-architected on top of Kubernetes. Consequently, the oc CLI was built upon the Kubernetes client libraries, inheriting much of kubectl's design and functionality while adding OpenShift-specific commands and resource types. Its development continues in tandem with OpenShift releases, constantly evolving to support new features and improvements in the platform.