OpenShift CLI Essential Commands and Examples
OpenShift CLI Essential Commands and Examples
YZ
by Yossi Z
Introduction to OpenShift
CLI (oc)
Command Line Versatile
Interface Functionality
OpenShift CLI (oc) is a It enables developers
powerful tool for and administrators to
managing OpenShift interact with OpenShift
resources from the clusters efficiently.
terminal.
Cross-Platform Support
Available for Windows, macOS, and Linux, ensuring broad
accessibility.
Exploring the oc Command Structure
Basic Syntax
oc [command] [type] [options]
Common Commands
get, create, delete, describe, edit
Resource Types
pods, services, deployments, routes
Options
-n (namespace), -o (output format), --all-namespaces
Interacting with OpenShift Projects and
Resources
Project Management Resource Retrieval
2 Specify Image
oc new-app
centos/ruby-25-centos7~https://github.com/sclorg/ru
by-ex
3 Use Template
oc new-app --template=mysql-persistent
Managing Application Builds with oc start-
build
Start New Build Build from Dockerfile Follow Build Logs
oc start-build myapp oc start-build myapp --from- oc start-build myapp --follow
dockerfile=./Dockerfile
Scaling and Managing Application
Pods with oc scale
Scale Up
oc scale deployment myapp --replicas=5
Scale Down
oc scale deployment myapp --replicas=2
Autoscale
oc autoscale deployment myapp --min=2 --max=10 --cpu-percent=80
Monitoring and Troubleshooting with oc logs
and oc describe
View Logs Describe Resources
Define Template
1
2 Process Template
3 Apply Configuration