Work on OpenShift with CLI

Step 1. after download oc.exe from OpenShift website, you can get the login token from web console => Copy Login Command

Step 2. oc login and work on your project

C:\Hans>oc login --token=sha256~BOkusrH7Npa5N9OWp6WomU98jox8UwjPm --server=https://c109-e.us-east.containers.cloud.ibm.com:30955
Logged into "https://c109-e.us-east.containers.cloud.ibm.com:30955" as "IAM#rh-dev-1093" using the token provided.

You have access to 63 projects, the list has been suppressed. You can list all projects with ' projects'

Using project "default".
Welcome! See 'oc help' to get started.

C:\Hans>oc project workshop
Now using project "workshop" on server "https://c109-e.us-east.containers.cloud.ibm.com:30955".

C:\Hans>oc get pods
NAME                        READY   STATUS    RESTARTS   AGE
parksmap-56fcbb7db4-gqfdc   1/1     Running   0          2m25s
C:\Hans>oc get pod parksmap-56fcbb7db4-gqfdc -o yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    cni.projectcalico.org/podIP: 172.30.218.69/32
    cni.projectcalico.org/podIPs: 172.30.218.69/32
......
C:\Hans>oc get deployment
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
parksmap   1/1     1            1           6m34s

C:\Hans>oc get rs
NAME                  DESIRED   CURRENT   READY   AGE
parksmap-56fcbb7db4   1         1         1       6m43s

C:\Hans>oc scale --replicas=2 deployment/parksmap
deployment.apps/parksmap scaled

C:\Hans>oc get endpoints parksmap
NAME       ENDPOINTS                                AGE
parksmap   172.30.134.235:8080,172.30.218.69:8080   8m27s

C:\Hans>oc delete pod parksmap-56fcbb7db4-gqfdc
pod "parksmap-56fcbb7db4-gqfdc" deleted

C:\Hans>oc rollout restart deployment/parksmap
deployment.apps/parksmap restarted

C:\Hans>oc create -f https://raw.githubusercontent.com/openshift-labs/starter-guides/ocp-4.6/mongodb-template.yaml -n workshop
template.template.openshift.io/mongodb-ephemeral created

C:\Hans>oc rsh parksmap-78c58f896-mjqnw
sh-4.2$ ls /
anaconda-post.log  dev  home  lib64  mnt  parksmap.jar  root  sbin  sys  usr
bin                etc  lib   media  opt  proc          run   srv   tmp  var

C:\Hans>oc get route
NAME       HOST/PORT                                                                                                            PATH   SERVICES   PORT       TERMINATION   WILDCARD
parksmap   parksmap-workshop.rhd-wdc07-may19-3875203-4c50a18a6ae19b704aa10d04d75751f8-0000.us-east.containers.appdomain.cloud          parksmap   8080-tcp   edge          None
https://parksmap-workshop.rhd-wdc07-may19-3875203-4c50a18a6ae19b704aa10d04d75751f8-0000.us-east.containers.appdomain.cloud/
C:\Hans>oc create -f https://raw.githubusercontent.com/openshift-roadshow/mlbparks/master/ose3/application-template-eap.json -n workshop
template.template.openshift.io/mlbparks created

C:\Hans>oc get template
NAME                DESCRIPTION                                                                        PARAMETERS        OBJECTS
mlbparks            Application template MLBParks backend running on Wildfly and using mongodb         12 (2 blank)      8
mongodb-ephemeral   MongoDB database service, without persistent storage. For more information ab...   8 (3 generated)   3

C:\Hans>oc new-app mlbparks -p APPLICATION_NAME=mlbparks
--> Deploying template "workshop/mlbparks" to project workshop

     MLBparks
     ---------
     Application template MLBParks backend running on Wildfly and using mongodb

     * With parameters:
        * Application Name=mlbparks
        * Application route=
        * Mongodb App=mongodb-mlbparks
        * Git source repository=https://github.com/openshift-roadshow/mlbparks.git
        * Git branch/tag reference=master
        * Maven mirror url=
        * Database name=mongodb
        * Database user name=usergyY # generated
        * Database user password=PXKOdWS8 # generated
        * Database admin password=0BbQcb7j # generated
        * GitHub Trigger=2sfrBrUY # generated
        * Generic Trigger=whNYmASR # generated

--> Creating resources ...
    configmap "mlbparks" created
    service "mongodb-mlbparks" created
    deploymentconfig.apps.openshift.io "mongodb-mlbparks" created
    imagestream.image.openshift.io "mlbparks" created
    buildconfig.build.openshift.io "mlbparks" created
    deploymentconfig.apps.openshift.io "mlbparks" created
    service "mlbparks" created
    route.route.openshift.io "mlbparks" created
--> Success
    Build scheduled, use 'oc logs -f buildconfig/mlbparks' to track its progress.
    Access your application via route 'mlbparks-workshop.rhd-wdc07-may19-3875203-4c50a18a6ae19b704aa10d04d75751f8-0000.us-east.containers.appdomain.cloud'
    Run 'oc status' to view your app.

CLI commands to create route:
 $ oc create route reencrypt --service=docker-registry
 $ oc get route docker-registry

ref: https://redhat-scholars.github.io/openshift-starter-guides/rhs-openshift-starter-guides/4.6/index.html

One Reply to “Work on OpenShift with CLI”

  1. What’s up friends, how is everything, and what you want to say concerning this article, in my view its in fact awesome in support of
    me.

Leave a Reply

Your email address will not be published. Required fields are marked *