Difficulty: beginner
Estimated Time: 10-15 minutes

When you create a build or deployment in OpenShift, expose a service, work with persistent storage, or adjust existing configuration, you are creating or operating on resource objects. These resource objects are central to how OpenShift and your applications are managed. They define how everything should look and also control what you can do within the OpenShift cluster. In this course we provide a guide for how to determine what resource objects have been created related to your application, and how you can query or update them.

You will be using just the oc command line tool in this exercise. We have left the OpenShift web console enabled if you wish to also explore the resource objects using it. The OpenShift web console can be reached by selecting Dashboard.

In this course you learnt about oc commands you would use for querying and updating the resource objects that OpenShift uses to track the state of the cluster.

You can find a summary of the key commands covered below. To see more information on each oc command, run it with the --help option.

oc types: Shows an introduction to core OpenShift concepts and types.

oc explain <setting-path>: Shows a description of the purpose of a specific resource object type setting.

oc get: Shows a list of all the resource object types you can make queries about.

oc get <type>: Shows summary details of all resource objects of a specific type.

oc get <type> --selector app=<name>: Shows summary details of all resource objects of a type with the specified label.

oc get <type/name>: Show summary details of a resource object.

oc get <type/name> -o <json|yaml>: Shows raw details of a resource object type as JSON or YAML.

oc get all: Shows summary details of the key resource objects in a project. The list of resource object types matched by all includes buildconfigs, builds, imagestreams, deploymentconfigs, replicationcontrollers, routes, services and pods.

oc get all --selector app=<name>: Shows summary details of the key resource objects in a project with the specified label.

oc describe <type/name>: Shows human readable long form description of a resource object.

oc edit <type/name> -o <json|yaml>: Edit the raw details of a resource object type as JSON or YAML.

oc export <type/name> -o <json|yaml>: Shows raw details of a resource object type as JSON or YAML where any settings not required when creating a resource object have been removed.

oc create -f <definition.json>: Create a resource object from a definition stored in a file. The format of the definition must be JSON or YAML. The metadata.name field of the definition must not correspond to an existing resource object.

oc replace -f <definition.json>: Replace the definition of a resource object with that stored in a file. The format of the definition must be JSON or YAML. The metadata.name field of the definition must correspond to an existing resource object.

oc apply -f <definition.json>: Replace the definition of a resource object if it exists with that stored in a file. The format of the definition must be JSON or YAML. The metadata.name field of the definition must correspond to an existing resource object. If the resource object does not already exist, it will be created.

oc patch <type/name> --patch <patch>: Update a resource object using a patch specification.

oc label <type/name> <name=value>: Add a label to a resource object.

oc label <type/name> <name->: Remove a label from a resource object.

oc delete <type/name>: Delete a resource object.

oc delete <type> --selector app=<name>: Delete all resource objects of a type with the specified label.

oc delete <type> --all: Delete all resource objects of a specific type.

oc delete all --all: Delete all key resource objects in a project. The list of resource object types matched by all includes buildconfigs, builds, imagestreams, deploymentconfigs, replicationcontrollers, routes, services and pods.

oc delete all --selector app=<name>: Delete all key resource objects in a project with the specified label.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Using the CLI to Manage Resource Objects

Step 1 of 9

Topic 1 - Deploying an Application

Before you can start this course you need to deploy a sample application to work with.

The first step is to ensure you are logged in as the developer user.

oc login --username developer --password developer

Next create a new project to add the application to, by running:

oc new-project myproject

This should automatically switch you to the new project, so you are ready to deploy the application.

The application you are going to deploy is the our ParksMap web application used in Getting Started with OpenShift for Developers Katacoda course.

oc new-app openshiftroadshow/parksmap-katacoda:1.0.0 --name parksmap

By default when using oc new-app from the command line to deploy an application, the application will not be exposed to the public. As our final step you therefore need to expose the service so that people can access it.

oc expose svc/parksmap

You are now ready to start investigating the resource objects which were created.