OpenShift: Deployment Using CLI

Khemnath chauhan
3 min readFeb 10, 2024

OpenShift provide command line utility called OC.

Install an application from a container image using oc new-app:

Installing an application in OpenShift using a container image involves using the oc new app command along with declaring the full path to a container image hosted in a container image repository.

  1. Go to the local system on which you installed the oc CLI tool and enter the following command in a terminal.
$ oc new-app

Get Pods, Service, Deployments.

2. Expose and view the application via a URL:
Once the application is installed, it needs to be exposed to the internet. Run the below command to expose the service.

$ oc expose service/greeter

You will see a response similar to the following:

Now view the route created after exposing the service:

To access the application use the HOST given in the route output:

new app URL.

Delete the application using the oc CLI tool:

We can delete an installed application using the oc CLI tool. Use the oc delete all command to delete all of the underlying Kubernetes resources that are associated with the given application.
A resource is associated with a Kubernetes label that OpenShift assigns to the given resource. For example, in above deployment the Greeter application we installed, all Kubernetes resources associated with the application will be assigned the label=value pair, app=greeter.

The syntax mechanism for declaring the label of interest is the -l option in the oc delete all command, where -l indicates your level of interest.

Delete the application:

  1. Run the following command in the terminal to remove the greeter demonstration application from the Red Hat OpenShift.
  # Delete pods and services with same names "baz" and "foo"
$ oc delete pod,service baz foo

# Delete pods and services with label name=myLabel
$ oc delete pods,services -l name=myLabel