0% found this document useful (0 votes)
27 views10 pages

Openshift Cheatsheet - Mastertheboss

The document is a comprehensive cheatsheet for the Openshift Container Platform, detailing commands for login, configuration, application deployment, image streams, templates, environment variables, and more. It includes instructions for managing nodes, storage, builds, deployments, routes, services, and troubleshooting. Additionally, it provides guidance on security, user roles, and miscellaneous commands for effective management of Openshift environments.

Uploaded by

jorgeluis81669
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
0% found this document useful (0 votes)
27 views10 pages

Openshift Cheatsheet - Mastertheboss

The document is a comprehensive cheatsheet for the Openshift Container Platform, detailing commands for login, configuration, application deployment, image streams, templates, environment variables, and more. It includes instructions for managing nodes, storage, builds, deployments, routes, services, and troubleshooting. Additionally, it provides guidance on security, user roles, and miscellaneous commands for effective management of Openshift environments.

Uploaded by

jorgeluis81669
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

Openshift cheatsheet - Mastertheboss http://www.mastertheboss.com/soa-cloud/openshift/op...

Mastertheboss

Openshift cheatsheet
8 November 2019 by F.Marchioni

Here is a comprehensive Openshift Container Platform cheatsheet for


Developers/Administrators.

Openshift Container Platform Login and


Con�guration
1. #login with a user
2. oc login https://192.168.99.100:8443 -u developer -p
developer
3.
4. #login as system admin
5. oc login -u system:admin
6.
7. #User Information
8. oc whoami
9.
10. #View your configuration
11. oc config view
12.
13. #Update the current context to have users login to the
desired namespace:
14. oc config set-context `oc config current-context`
--namespace=<project_name>

Openshift Container Platform 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-
speedboat/openshift.html.devops.git#mybranch
6.
7. #Create objects from a file:

1 de 10 21/1/22, 16:55
Openshift cheatsheet - Mastertheboss http://www.mastertheboss.com/soa-cloud/openshift/op...

8. oc create -f myobject.yaml -n myproject

1. #Delete objects contained in a file:


2. oc delete -f myobject.yaml -n myproject

1. #Create or merge objects from file


2. oc apply -f myobject.yaml -n myproject
3.
4. #Update existing object
5. oc patch svc mysvc --type merge --patch '{"spec":{"ports":
[{"port": 8080, "targetPort": 5000 }]}}'
6.
7. #Monitor Pod status
8. watch oc get pods
9.
10. #Show labels
11. oc get pods --show-labels
12.
13. #Gather information on a project's pod deployment with node
information
14. oc get pods -o wide
15.
16. #Hide inactive Pods
17. oc get pods --show-all=false
18.
19. #Display all resources
20. oc get all,secret,configmap
21.
22. #Get the Openshift Console Address
23. oc get -n openshift-console route console
24.
25. #Get the Pod name from the Selector and rsh in it
26. POD=$(oc get pods -l app=myapp -o name) oc rsh -n $POD
27.
28. #Exec single command in pod
29. oc exec $POD $COMMAND
30.
31. #Copy file from myrunning-pod-2 path in the current location
32. oc rsync myrunning-pod-2:/tmp/LogginData_20180717220510.json
.
33.
34. #Read resource schema doc oc explain dc

Openshift Container Platform Image Streams


1. #List available IS for openshift project
2. oc get is -n openshift

2 de 10 21/1/22, 16:55
Openshift cheatsheet - Mastertheboss http://www.mastertheboss.com/soa-cloud/openshift/op...

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

Openshift Container Platform Templates


1. # Deploy resources contained in a template
2. oc process -f template.yaml | oc create -f -
3.
4. #List parameters available in a template
5. oc process --parameters -f .template.yaml

Setting environment variables


1. # Update deployment 'registry' with a new environment
variable
2. oc set env dc/registry STORAGE_DIR=/local
3.
4. # List the environment variables defined on a build config
'sample-build'
5. oc set env bc/sample-build --list
6.
7. # List the environment variables defined on all pods
8. oc set env pods --all --list
9.
10. # Import environment from a secret
11. oc set env --from=secret/mysecret dc/myapp

WildFly application example on Openshift


Container Platform
1. oc create -f https://raw.githubusercontent.com/wildfly
/wildfly-s2i/wf-18.0/imagestreams/wildfly-centos7.json
2. oc new-app wildfly~https://github.com/fmarchioni/ocpdemos
--context-dir=wildfly-basic --name=wildfly-basic
3. oc expose svc/wildfly-basic

Create app from a Project with Docker�le


1. oc new-build --binary --name=mywildfly -l app=mywildfly
2.

3 de 10 21/1/22, 16:55
Openshift cheatsheet - Mastertheboss http://www.mastertheboss.com/soa-cloud/openshift/op...

3. oc patch bc/mywildfly -p '{"spec":{"strategy":


{"dockerStrategy":{"dockerfilePath":"Dockerfile"}}}}'
4.
5. oc start-build mywildfly --from-dir=. --follow
6.
7. oc new-app --image-stream=mywildfly
8.
9. oc expose svc/mywildfly

Openshift Container Platform Nodes


1. #Get Nodes list
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":{"kubernetes.io/hostname":
"ip-10-0-0-74.acme.compute.internal"}}}}}'
9.
10. #List all pods which are running on a Node
11. oc adm manage-node node1.local --list-pods
12.
13. #Add a label to a Node
14. oc label node node1.local mylabel=myvalue
15.
16. #Remove a label from a Node
17. oc label node node1.local mylabel-

Openshift Container Platform Storage


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

4 de 10 21/1/22, 16:55
Openshift cheatsheet - Mastertheboss http://www.mastertheboss.com/soa-cloud/openshift/op...

Openshift Container Platform Build


1. #Manual build from source
2. oc start-build ruby-ex
3.
4. #Manual build from source and follow logs
5. oc start-build ruby-ex -F
6.
7. #Stop a build that is in progress
8. oc cancel-build <build_name>
9.
10. #Changing the log level of a build:
11. oc set env bc/my-build-name BUILD_LOGLEVEL=[1-5]

Openshift Container Platform Deployment


1. #Manual deployment
2. $ oc rollout latest ruby-ex
3.
4. #Pause automatic deployment rollout
5. oc rollout pause dc $DEPLOYMENT
6.
7. # Resume automatic deployment rollout
8. oc rollout resume dc $DEPLOYMENT
9.
10. #Define resource requests and limits in DeploymentConfig
11. oc set resources deployment nginx
--limits=cpu=200m,memory=512Mi
--requests=cpu=100m,memory=256Mi
12.
13. #Define livenessProve and readinessProve in DeploymentConfig
14. oc set probe dc/nginx --readiness --get-url=http://:8080
/healthz --initial-delay-seconds=10
15. oc set probe dc/nginx --liveness --get-url=http://:8080
/healthz --initial-delay-seconds=10
16.
17. #Scale the number of Pods to 2
18. oc scale dc/nginx --replicas=2
19.
20. #Define Horizontal Pod Autoscaler (hpa)
21. oc autoscale dc $DC_NAME --max=4 --cpu-percent=10

Openshift Container Platform Routes


1. #Create route
2. $ oc expose service ruby-ex
3.

5 de 10 21/1/22, 16:55
Openshift cheatsheet - Mastertheboss http://www.mastertheboss.com/soa-cloud/openshift/op...

4. #Read the Route Host attribute


5. oc get route my-route -o jsonpath --template="{.spec.host}"

Openshift Container Platform Services


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

Clean up resources
1. #Delete all resources
2. oc delete all --all
3.
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
9. #Keeping up to three tag revisions 1, and keeping resources
(images, image streams and pods) younger than sixty minutes:
10. oc adm prune images --keep-tag-revisions=3 --keep-younger-
than=60m
11.
12. #Pruning every image that exceeds defined limits:
13. oc adm prune images --prune-over-size-limit

Openshift Container Platform Troubleshooting


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.

6 de 10 21/1/22, 16:55
Openshift cheatsheet - Mastertheboss http://www.mastertheboss.com/soa-cloud/openshift/op...

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

Openshift Container Platform Security


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

Openshift Container Platform Manage user roles


1. oc adm policy add-role-to-user admin oia -n python
2. oc adm policy add-cluster-role-to-user cluster-reader
system:serviceaccount:monitoring:default
3. oc adm policy add-scc-to-user anyuid -z default

Misc commands
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}' | while read obj
18. do
19. NS=$(echo $obj | cut -d, -f1)

7 de 10 21/1/22, 16:55
Openshift cheatsheet - Mastertheboss http://www.mastertheboss.com/soa-cloud/openshift/op...

20. OBJ=$(echo $obj | cut -d, -f2)


21. FILE=$(echo $obj | sed 's/\//-/g;s/,/-/g')
22. echo $NS $OBJ $FILE; oc export -n $NS $OBJ -o yaml >
$FILE.yml
23. done

Openshift
Con�guring MS SQLServer Datasource in WildFly
Securing Quarkus with Elytron Database Realm

Search …

Recent Posts

How to code a Quarkus REST Client

How to con�gure Web applications request limits in WildFly

What you need to know about CVE-2021-42392

How to run Quarkus applications on Kubernetes


Getting started with Netty

WildFly books

8 de 10 21/1/22, 16:55
Openshift cheatsheet - Mastertheboss http://www.mastertheboss.com/soa-cloud/openshift/op...

Top 10 Tutorials

Con�guring SSL/TLS with WildFly

Using WildFly on OpenShift

How to run CLI commands in WildFly Docker�le

Monitoring Quarkus with Prometheus

Spring Boot on WildFly

9 de 10 21/1/22, 16:55
Openshift cheatsheet - Mastertheboss http://www.mastertheboss.com/soa-cloud/openshift/op...

Active MQ Performance Tuning


© 2022 Mastertheboss • Built with GeneratePress
WildFly Interview Questions

DataSource pool con�guration

Solving java.lang.OutOfMemoryError: Metaspace error

How to redirect HTTP to HTTPS in WildFly

10 de 10 21/1/22, 16:55

You might also like