Openshift Cheat Sheet

  about 303 words   2 min


I find myself losing time always looking for some Openshift commands that I stumbled upon once in the documentation.

This page is just a reminder of these commands :

List all cluster-admins of your cluster

  % oc get clusterrolebindings -o json | jq '.items[] | select("cluster-admins") | .userNames'

Add the admin role to some user of an project

  % oc adm policy add-role-to-user admin userX -n project-Y 

Binds a given role to specified users for all projects in the cluster.

  % oc adm policy add-cluster-role-to-user <role> USER      

Add some labels on your nodes or pods when you use NodeSelectors

  % oc label node myLabel=myValue
  % oc label pod  pod-27-f7eo7 myLabel=myValue

Remove some labels on your nodes or pods

  % oc label node myLabel-
  % oc label pod  pod-27-f7eo7 myLabel-

Show labels

  % oc get node --show-labels

You can filter them by os and architecture by example :

   % oc get node -L, 
   NAME                                        STATUS     ROLES     AGE       VERSION           ARCH      OS                         Ready      compute   250d      v1.11.0+d4cacc0   amd64     linux                         Ready      compute   250d      v1.11.0+d4cacc0   amd64     linux                        Ready      compute   13d       v1.11.0+d4cacc0   amd64     linux

Show namespaces

Namespaces are defined to be used as a workspace for an environment shared in a team by example. You have as an admin handle the users accesses and/or quotas to avoid other namespaces to use all available ressources.

  % oc get ns 
  NAME                                STATUS        AGE
  lazy-dev                            Active        12d
  lazy-prod                           Active        2d

To get more information about a namespace, you can use describe

  % oc describe ns lazy-dev 
  Name:         lazy-dev
  Labels:       target-router=lazy-dev-router
  Annotations: env 
  Status:       Active

  No resource quota.

  Resource Limits
  Type       Resource  Min  Max  Default Request  Default Limit  Max Limit/Request Ratio
  ----       --------  ---  ---  ---------------  -------------  -----------------------
  Container  cpu       -    -    100m             -              -
  Container  memory    -    -    256Mi            -              -

openshift kubernetes cli okd