DEV Community

Cover image for 12 Useful OpenShift Commands You Should Know
Sagar Jadhav
Sagar Jadhav

Posted on • Originally published at developersthought.in

12 Useful OpenShift Commands You Should Know

Introduction

Redhat OpenShift is a Container Management and a Hybrid Cloud Platform. It gives you the ability to develop and run containerized applications along with OOTB integration with existing DevOps tools. Checkout OpenShift documentation for more details.

Containers

OC CLI is used to perform various operations on OpenShift. It is similar to kubectl CLI and offers all the operations that you can perform with kubectl CLI plus additional support for native OpenShift features. Checkout OC CLI documentation for more details.

12 Useful OpenShift Commands

I. Create Service Account testsa

oc create sa testsa
Enter fullscreen mode Exit fullscreen mode

II. Add anyuid SCC to Service Account testsa

oc adm policy add-scc-to-user anyuid -z testa
Enter fullscreen mode Exit fullscreen mode

III. Deploy nginx application using nginx Docker Image from Docker Hub with label app=test

oc new-app --docker-image nginx --name nginx -l app=test
Enter fullscreen mode Exit fullscreen mode

IV. Scale up nginx application to 5 replicas

oc scale --replicas=5 dc nginx
Enter fullscreen mode Exit fullscreen mode

V. Delete nginx application using label app=test

oc delete all -l app=test
Enter fullscreen mode Exit fullscreen mode

VI. Export nginx application definition to nginx.yaml

oc new-app --docker-image nginx --name nginx -l app=test -o yaml > nginx.yaml
Enter fullscreen mode Exit fullscreen mode

VII. Deploy nginx application using nginx.yaml

oc apply -f nginx.yaml
Enter fullscreen mode Exit fullscreen mode

VIII. Deploy Node.js Hello World application using GitHub URL with label app=test and name helloworld

oc new-app https://github.com/sagar-jadhav/node-hello --name helloworld -l app=test
Enter fullscreen mode Exit fullscreen mode

IX. Export nginx application to nginx-template template

oc export dc nginx --as-template=nginx-template
Enter fullscreen mode Exit fullscreen mode

X. Set requests & limits of nginx application

oc set resources dc nginx --requests=cpu=250m --limits=cpu=250m
Enter fullscreen mode Exit fullscreen mode

XI. Create Edge Terminated Route nginx-route for nginx service using nginx.key & nginx.crt files

oc create route edge nginx-route --service=nginx --key=nginx.key --cert=nginx.crt
Enter fullscreen mode Exit fullscreen mode

XII. Create secret user-creds with values user=admin and password=admin

oc create secret generic user-creds --from-literal='user'='admin' --from-literal='password'='admin'
Enter fullscreen mode Exit fullscreen mode

Top comments (0)