Openshift Cheat Sheet

  about 303 words   2 min

OpenShift

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(.metadata.name=="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 node01.lazybear.io myLabel=myValue
  % oc label pod  pod-27-f7eo7 myLabel=myValue

Remove some labels on your nodes or pods


  % oc label node node01.lazybear.io 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 beta.kubernetes.io/arch,beta.kubernetes.io/os 
   NAME                                        STATUS     ROLES     AGE       VERSION           ARCH      OS
   node-01.lazybear.io                         Ready      compute   250d      v1.11.0+d4cacc0   amd64     linux
   node-02.lazybear.io                         Ready      compute   250d      v1.11.0+d4cacc0   amd64     linux
   hosts-1a.lazybear.io                        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:  openshift.io/description=Dev env 
                openshift.io/display-name=lazy-dev
                openshift.io/node-selector=platform=lazy-dev,region=aws,zone=workload
                openshift.io/sa.scc.mcs=s0:c20,c10
                openshift.io/sa.scc.supplemental-groups=1000400000/10000
                openshift.io/sa.scc.uid-range=1000400000/10000
  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