OpenShift - List projects using the oc get projects command

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

The oc get projects command will list the available projects, like this. The * character is used to indicate the current project being used.

The oc config view or oc get apiserver commands can be used to display the API Server URL (api.openshift.example.com in this example).

oc get projects

You have access to the following projects and can switch between them with 'oc project <projectname>':

   project1
 * project2
   project3
   et cetera

Using project "project2" on server "https://api.openshift.example.com:6443".

 

The -q or --short flag can be used to display only the project names.

~]# oc get projects --short
project1
project2
project3

 

--short=false can be used to return something like this.

oc get projects --short=false

Using project "project2" on server "https://api.openshift.example.com:6443".

 

The oc describe projects command will describe every project.

oc describe projects

 

The oc describe project/project_name will describe a specific project. In this example, the foo project will be described.

oc describe project/foo

 

Something like this should be returned.

Name:                   foo
Created:                2 months ago
Labels:                 <none>
Annotations:            openshift.io/backup-registry-hostname=docker-registry.default.svc:5000
                        openshift.io/backup-server-version=1.11
                        openshift.io/display-name=
                        openshift.io/sa.scc.mcs=s0:c33,c22
                        openshift.io/sa.scc.supplemental-groups=1001100000/10000
                        openshift.io/sa.scc.uid-range=1001100000/10000
Display Name:           <none>
Description:            <none>
Status:                 Active
Node Selector:          <none>
Quota:                  <none>
Resource limits:        <none>

 

Or, the oc get projects command with the --output json‚Äč or --output yaml option can be used.

~]$ oc get project foo --output json
{
    "apiVersion": "project.openshift.io/v1",
    "kind": "Project",
    "metadata": {
        "annotations": {
            "openshift.io/description": "",
            "openshift.io/display-name": "",
            "openshift.io/requester": "c065234",
            "openshift.io/sa.scc.mcs": "s0:c29,c4",
            "openshift.io/sa.scc.supplemental-groups": "1000820000/10000",
            "openshift.io/sa.scc.uid-range": "1000820000/10000"
        },
        "creationTimestamp": "2021-12-29T05:49:11Z",
        "labels": {
            "kubernetes.io/metadata.name": "foo"
        },
        "name": "foo",
        "resourceVersion": "411411327",
        "uid": "74fe0011-b0d4-4378-827b-971556803367"
    },
    "spec": {
        "finalizers": [
            "kubernetes"
        ]
    },
    "status": {
        "phase": "Active"
    }
}

 

The --output jsonpath option can be used to print the value of a specific JSON key.

~]$ oc get project foo --output jsonpath={.status.phase}
Active

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter cca72 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |