100% found this document useful (1 vote)
174 views10 pages

Openshift Cheatsheet

Uploaded by

Rpl Marseille
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
174 views10 pages

Openshift Cheatsheet

Uploaded by

Rpl Marseille
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

com/M

twork-
(/)

mastert
Tutorials for WildFly Application Server, Openshift, JBoss Projects and
Enterprise Applications
archion (/) (/GET-ME-STARTED)
HOME GET ME STARTED! WILDFLY  BPM  PROJECTS  JAVA EE - MICROPROFILE 

boss.c
=rss) IDE  SOA-CLOUD  WEB  MISC  OLD STUFF 

Search Mastertheboss Openshift cheatsheet


Search...
Here is a comprehensive Openshift CLI cheatsheet for Developers/Administrators.

Our eBooks Openshift Login and Con guration

/
1 #login with a user
2 oc login https://192.168.99.100:8443 -u developer -p developer
com/M 3
twork- 4 #login as system admin
5 oc login -u system:admin
6
7 #User Information
8 oc whoami
mastert
9
10 #View your configuration
11 oc config view
12
archion 13 #Update the current context to have users login to the desired
14 namespace:
oc config set-context `oc config current-context` --namespace=
<project_name>
boss.c
=rss) Basic Commands
1 #Use specific template
2 oc new-app https://github.com/name/project --template=<template>
3
4 #New app from a different branch
5 oc new-app --name=html-dev nginx:1.10~https://github.com/joe-
6 speedboat/openshift.html.devops.git#mybranch
7
(http://www.itbuzzpress.com) 8 #Create objects from a file:
9 oc create -f myobject.yaml -n <myproject>
10
11 #Create or merge objects from file
12 oc apply -f myobject.yaml -n <myproject>
13
14 #Update existing object
15 oc patch svc mysvc --type merge --patch '{"spec":{"ports":[{"port":
16 8080, "targetPort": 5000 }]}}'
17
18 #Monitor Pod status
19 watch oc get pods
20
21 #show labels
22 oc get pods --show-labels
23
24 #Gather information on a project's pod deployment with node information
/
25 $ oc get pods -o wide
26
com/M 27 #Hide inactive Pods
twork- 28 oc get pods --show-all=false
29
30 #Display all resources
31 oc get all,secret,configmap
32
mastert
33 #Get the Openshift Console Address
34 oc get -n openshift-console route console
35
36 #Get the Pod name from the Selector and rsh in it
archion 37 POD=$(oc get pods -l app=myapp -o name)
38 oc rsh -n $POD
39
40 #exec single command in pod
boss.c
41 oc exec $POD $COMMAND
=rss)
42
43 #Copy file from myrunning-pod-2 path in the current location
44 oc rsync myrunning-pod-2:/tmp/LogginData_20180717220510.json .
45
#Read resource schema doc
oc explain dc

Image Streams
1 #List available IS for openshift project
2 oc get is -n openshift
3
4 #Import an image from an external registry
5 oc import-image --from=registry.access.redhat.com/jboss-amq-6/amq62-
6 openshift -n openshift jboss-amq-62:1.3 --confirm
7
8 #List available IS and templates
oc new-app --list

WildFly application example


1 oc create -f https://raw.githubusercontent.com/wildfly/wildfly-s2i/wf-
2 18.0/imagestreams/wildfly-centos7.json
3 oc new-app wildfly~https://github.com/fmarchioni/ocpdemos --context-
dir=wildfly-basic --name=wildfly-basic
oc expose svc/wildfly-basic /
Create app from a Project with Docker le
com/M
1 oc new-build --binary --name=mywildfly -l app=mywildfly
twork-
2
3 oc patch bc/mywildfly -p '{"spec":{"strategy":{"dockerStrategy":
4 {"dockerfilePath":"Dockerfile"}}}}'
5
mastert 6 oc start-build mywildfly --from-dir=. --follow
7
8 oc new-app --image-stream=mywildfly
9
archion
oc expose svc/mywildfly

Nodes
boss.c 1 #Get Nodes lits
=rss) 2 oc get nodes
3
4 #Check on which Node your Pods are running
5 oc get pods -o wide
6
7 #Schedule an application to run on another Node
8 oc patch dc myapp -p '{"spec":{"template":{"spec":{"nodeSelector":
9 {"kubernetes.io/hostname": "ip-10-0-0-74.acme.compute.internal"}}}}}'
10
11 #List all pods which are running on a Node
12 oc adm manage-node node1.local --list-pods
13
14 #Add a label to a Node
15 oc label node node1.local mylabel=myvalue
16
17 #Remove a label from a Node
oc label node node1.local mylabel-

Storage

/
1 #create a PersistentVolumeClaim (+update the DeploymentConfig to include
2 a PV + update the DeploymentConfig to attach a volumemount into the
com/M 3 specified mount-path)
twork- 4
5 oc set volume dc/file-uploader --add --name=my-shared-storage \
6 -t pvc --claim-mode=ReadWriteMany --claim-size=1Gi \
7 --claim-name=my-shared-storage --claim-class=ocs-storagecluster-cephfs \
8 --mount-path=/opt/app-root/src/uploaded \
mastert
9 -n my-shared-storage
10
#List storage classes
oc -n openshift-storage get sc
archion

Build
1 #Manual build from source
boss.c 2 oc start-build ruby-ex
=rss) 3
4 #Stop a build that is in progress
5 oc cancel-build <build_name>
6
7 #Changing the log level of a build:
8 oc set env bc/my-build-name BUILD_LOGLEVEL=[1-5]

Deployment

/
1 #Manual deployment
2 $ oc rollout latest ruby-ex
com/M 3
twork- 4 #Pause automatic deployment rollout
5 oc rollout pause dc $DEPLOYMENT
6
7 # Resume automatic deployment rollout
8 oc rollout resume dc $DEPLOYMENT
mastert
9
10 #Define resource requests and limits in DeploymentConfig
11 oc set resources deployment nginx --limits=cpu=200m,memory=512Mi --
12 requests=cpu=100m,memory=256Mi
archion 13
14 #Define livenessProve and readinessProve in DeploymentConfig
15 oc set probe dc/nginx --readiness --get-url=http://:8080/healthz --
16 initial-delay-seconds=10
boss.c
17 oc set probe dc/nginx --liveness --get-url=http://:8080/healthz --
=rss)
18 initial-delay-seconds=10

#Define Horizontal Pod Autoscaler (hpa)


oc autoscale dc $DC_NAME --max=4 --cpu-percent=10

Routes
1 #Create route
2 $ oc expose service ruby-ex
3
4 #Read the Route Host attribute
5 oc get route my-route -o jsonpath --template="{.spec.host}"

Services
1 #Make a service idle. When the service is next accessed will automatically
2 boot up the pods again:
3 $ oc idle ruby-ex
4
5 #Read a Service IP
oc get services rook-ceph-mon-a --template='{{.spec.clusterIP}}'

Clean up resources
/
1 #Delete all resources
2 oc delete all --all
com/M 3
twork- 4 #Delete resources for one specific app
5 $ oc delete services -l app=ruby-ex
6 $ oc delete all -l app=ruby-ex
7
8 #CleanUp old docker images on nodes
mastert
9 #Keeping up to three tag revisions 1, and keeping resources (images,
10 image streams and pods) younger than sixty minutes:
11 oc adm prune images --keep-tag-revisions=3 --keep-younger-than=60m
12
archion 13 #Pruning every image that exceeds defined limits:
oc adm prune images --prune-over-size-limit

Troubleshooting
boss.c
=rss) 1 #Check status of current project
2 oc status
3
4 #Get events for a project
5 oc get events --sort-by='{.lastTimestamp}'
6
7 # get the logs of the myrunning-pod-2-fdthn pod
8 oc logs myrunning-pod-2-fdthn<br />
9 # follow the logs of the myrunning-pod-2-fdthn pod
10 oc logs -f myrunning-pod-2-fdthn<br />
11 # tail the logs of the myrunning-pod-2-fdthn pod
12 oc logs myrunning-pod-2-fdthn --tail=50
13
14 #Check the integrated Docker registry logs:
15 oc logs docker-registry-n-{xxxxx} -n default | less
16
17 #run cluster diagnostics
18 oc adm diagnostics

Security

/
1 #Create a secret from the CLI and mount it as a volume to a deployment
2 config:
com/M 3 oc create secret generic oia-secret --from-literal=username=myuser
twork- 4 --from-literal=password=mypassword
5 oc set volumes dc/myapp --add --name=secret-volume --mount-path=/opt/app-
root/
--secret-name=oia-secret

Manage user roles


mastert

1 oc adm policy add-role-to-user admin oia -n python


2 oc adm policy add-cluster-role-to-user cluster-reader
archion
3 system:serviceaccount:monitoring:default
oc adm policy add-scc-to-user anyuid -z default

boss.c Misc commands


=rss)
1 #Manage node state
2 oc adm manage node <node> --schedulable=false
3
4 #List installed operators
5 oc get csv
6
7 #Export in a template the IS, BC, DC and SVC
8 oc export is,bc,dc,svc --as-template=app.yaml
9
10 #Show user in prompt
11 function ps1(){
12 export PS1='[\u@\h($(oc whoami -c 2>/dev/null|cut -d/ -f3,1)) \W]\$ '
13 }
14
15 #backup openshift objects
16
17 oc get all --all-namespaces --no-headers=true | awk '{print $1","$2}' |
18 while read obj
19 do
20 NS=$(echo $obj | cut -d, -f1)
21 OBJ=$(echo $obj | cut -d, -f2)
22 FILE=$(echo $obj | sed 's/\//-/g;s/,/-/g')
23 echo $NS $OBJ $FILE; oc export -n $NS $OBJ -o yaml > $FILE.yml
done

/
C Last Updated: 06 December 2019
com/M
twork-     

Related articles available on mastertheboss.com


mastert
(/soa-cloud/openshift/openshift-installation-quick-
Openshift installation quick tutorial
tutorial) (/soa-cloud/openshift/java-ee-example-
IMPORTANT: This tutorial is now outdated. Openishift
origin has b Java EE example application on Openshift
archion
In this tutorial we will learn how to deploy a Java EE
applicatio

boss.c
=rss)

application-on-openshift) (/soa-
Running tomcat Docker image on Openshift
cloud/openshift/running-tomcat-docker-image-on-
A common issue when porting Docker images on
openshift) (/soa-cloud/openshift/deploy-docker-
Openshift is that th
Deploy Docker images on Openshift
This tutorial will teach you how you can build and deploy
a custo

Using Property les in your Openshift


images-on-openshift) (/soa-cloud/openshift/using-
applications property-files-in-your-openshift-applications)
A common need for most application is to store its Accessing Openshift services remotely
configuration
In this article we will learn how to connect to services
running

/
com/M (/soa-cloud/openshift/accessing-openshift-services-remotely) (/soa-cloud/openshift/helloworld-
twork-
nodejs-on-openshift) (/soa-cloud/openshift/using-wildfly-on-openshift) (/soa-
cloud/openshift/manage-blue-green-deployment-with-openshift-paas) (/soa-cloud/openshift/how-to-
configure-ab-deployments-on-openshift) (/soa-cloud/openshift/checking-intra-pod-connectivity)
mastert (/soa-cloud/openshift/configuring-metrics-on-openshift) (/soa-cloud/openshift/how-to-autoscale-
your-applications-with-openshift) (/soa-cloud/openshift/configuring-wildfly-jvm-on-openshift) (/soa-
cloud/openshift/configuring-persistent-storage-on-openshift) (/soa-cloud/openshift/how-to-
customize-wildfly-applications-on-openshift) (/soa-cloud/openshift/running-microprofile-applications-
archion
on-openshift) (/soa-cloud/openshift/running-any-docker-image-on-openshift) (/soa-
cloud/openshift/managing-microprofile-health-checks)

Load More...
boss.c
=rss)

© 2020 WildFly | JBoss Application Server | Openshift tutorials Back to Top

You might also like