OpenShift - List Contexts using the oc config get-context command
                
            
            
            
             
            
            
                           
                
            
            
            
                
    
    
     
            
                
                    by
                    Jeremy Canfield  |  
                    Updated: January 03 2025
                    
                          |  OpenShift articles
                    
                    
                    
                
            
            If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.
When using the oc command to interact with OpenShift, such as using the oc login command to log into OpenShift, each login will be associated with a particular "context". A contexts consists of:
- The name of the OpenShift cluster (e.g. api-openshift-example-com:6443)
- The user that logged into the OpenShift cluster (e.g. john.doe/api-openshift-example-com:6443)
- The namespace the user logged into (e.g. my-project)
Once successfully signed into OpenShift, your /home/your_username/.kube/config file will contain a block for each context.
apiVersion: v1
clusters:
- cluster:
    server: https://api.openshift.example.com:6443
  name: os.example.com:6443
contexts:
- context:
    cluster: api.openshift.example.com:6443
    namespace: default
    user: john.doe
  name: default/api.openshift.example.com:6443/john.doe
current-context: default/api.openshift.example.com:6443/john.doe
kind: Config
preferences: {}
users:
- name: john.doe
  user:
    token: Mn8cvscRkYgEUo_DcoUHUk3Z7Cu8W2RQikRBwmglet8
The oc config get-contexts can be used to list each context that has been registered.
~]$ oc config get-contexts | head
CURRENT   NAME                                                  CLUSTER                           AUTHINFO                                        NAMESPACE
          my-project/api-openshift-example-com:6443/john.doe    api-openshift-example-com:6443    john.doe/api-openshift-example-com:6443          my-project
          foo/api-openshift-example-com:6443/john.doe           api-openshift-example-com:6443    john.doe/api-openshift-example-com:6443          foo
          bar/api-openshift-example-com:6443/john.doe           api-openshift-example-com:6443    john.doe/api-openshift-example-com:6443          bar
Did you find this article helpful?
If so, consider buying me a coffee over at 