LinuxCommandLibrary

oc

Manage OpenShift clusters

TLDR

Log in to the OpenShift Container Platform server

$ oc login
copy

Create a new project
$ oc new-project [project_name]
copy

Switch to an existing project
$ oc project [project_name]
copy

Add a new application to a project
$ oc new-app [repo_url] --name [application]
copy

Open a remote shell session to a container
$ oc rsh [pod_name]
copy

List pods in a project
$ oc get pods
copy

Log out from the current session
$ oc logout
copy

SYNOPSIS

oc [options] [command] [arguments]

PARAMETERS

--as=
    Impersonate a user.

--as-group=
    Impersonate a group.

--certificate-authority=
    Path to a certificate authority file.

--config=
    Path to the OpenShift configuration file. Defaults to ~/.kube/config

--context=
    The name of the kubeconfig context to use.

--insecure-skip-tls-verify
    If true, the server's certificate will not be checked for validity. This will make your connections insecure. Defaults to false.

--kubeconfig=
    Path to the kubeconfig file to use for CLI requests.

--loglevel=
    Log level (0-9). Higher values are more verbose.

--namespace=
    If present, the namespace scope for this CLI request.

--password=
    Password for basic authentication.

--request-timeout=
    The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h).

--token=
    Bearer token for authentication.

--user=
    Username for basic authentication.

DESCRIPTION

The oc command is the command line interface (CLI) for interacting with OpenShift Container Platform, a Kubernetes-based platform for developing, deploying, and managing containerized applications. It provides a wide range of functions, allowing users to manage projects, deployments, builds, services, routes, and other OpenShift resources. It is the primary tool for developers and administrators to interact with the OpenShift cluster from the command line. The oc CLI allows users to create, view, update, and delete OpenShift resources. It also offers features for logging into the cluster, managing users and roles, and troubleshooting applications. Its a powerful tool for interacting and managing an OpenShift container Platform.

CAVEATS

The oc command relies on a correctly configured OpenShift cluster and a valid kubeconfig file for authentication and authorization. Ensure that the user has the necessary permissions to perform the desired actions. Some commands may require administrator privileges.

COMMON COMMANDS

Some frequently used commands include:
oc login: Logs into the OpenShift cluster.
oc new-project: Creates a new project.
oc new-app: Creates a new application from a template or image.
oc get: Displays information about OpenShift resources.
oc create: Creates OpenShift resources.
oc apply: Applies a configuration change to a resource.
oc delete: Deletes OpenShift resources.
oc logs: Displays logs for a pod or container.
oc exec: Executes a command in a pod or container.

TEMPLATES

oc can create resources from templates. Templates are pre-defined configurations for creating sets of resources.
They allow users to easily create and deploy applications without manually defining each resource.
Use oc process command to see output and use oc create -f <(oc process -f template.yaml) command to deploy.

HISTORY

The oc command evolved alongside OpenShift Container Platform. Initially, it was tightly coupled with the OpenShift origin project. Over time, as Kubernetes matured, oc was adapted to leverage the underlying Kubernetes API while adding OpenShift-specific extensions and abstractions. The oc CLI is actively maintained and updated with new features and improvements alongside OpenShift releases.

SEE ALSO

kubectl(1)

Copied to clipboard