🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Openshift: Comprehensive Guide: oc vs kubectl CLI

Here’s a comprehensive guide comparing the oc (OpenShift CLI) and kubectl (Kubernetes CLI) commands, focusing on their differences, similarities, and real-world usage. This is especially useful for OpenShift developers or admins coming from Kubernetes backgrounds.


📘 Comprehensive Guide: oc vs kubectl CLI

Aspectoc (OpenShift CLI)kubectl (Kubernetes CLI)
DefinitionCLI tool for managing OpenShift resources and clustersCLI tool for managing Kubernetes resources and clusters
Default ClusterTargets OpenShift (Red Hat Kubernetes platform)Targets any CNCF-compliant Kubernetes cluster
InstallationInstalled with OpenShift tools or CRCComes bundled with most Kubernetes distributions
Resource AccessSupports all Kubernetes APIs + OpenShift APIs (e.g., Build, Route, ImageStream)Supports only Kubernetes-native APIs
CustomizationIncludes extended functionality and OpenShift-specific templatesNo built-in support for OpenShift-only resources
LoginUses oc login with OpenShift OAuthUses kubectl config or kubeconfig files
CompatibilityFully supports kubectl commands as aliasesCannot access OpenShift-only resources

✅ Similarities Between oc and kubectl

FeatureExample Command (same for both)Description
Get Podsoc get pods / kubectl get podsLists pods in current namespace
Describe Resourceoc describe pod <name> / kubectl describe pod <name>Detailed pod description
Apply YAMLoc apply -f app.yaml / kubectl apply -f app.yamlApply resource configuration
Delete Resourcesoc delete pod <name> / kubectl delete pod <name>Delete a resource
Logsoc logs <pod> / kubectl logs <pod>Stream logs from a container
Port-forwardoc port-forward svc/myapp 8080:80Forward local port to a service
Execoc exec -it <pod> -- /bin/bashGet shell access to a pod

✅ Fact: Every valid kubectl command is also valid in oc.


🔴 Differences: oc Adds OpenShift-Specific Features

CommandOnly in ocPurpose
oc new-appYesRapid app deployment from source/image
oc new-projectYesCreate a new OpenShift project (namespace)
oc admYesOpenShift admin utility commands
oc rolloutExtendedManage OpenShift-specific rollouts
oc statusYesVisual overview of current project
oc whoamiYesCheck current OpenShift user
oc get routeYesView OpenShift routes (external access)
oc import-imageYesImport images into OpenShift image streams
oc policyYesRBAC management for OpenShift
oc start-buildYesTrigger OpenShift BuildConfig
oc logs -f bc/<buildConfig>YesStream logs from OpenShift build

⚠️ kubectl does not support OpenShift-specific resources like Route, BuildConfig, DeploymentConfig, ImageStream.


🧪 Example: Deploying a Sample App

Using kubectl (Kubernetes way):

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

Using oc (OpenShift way):

oc new-app nodejs~https://github.com/sclorg/nodejs-ex.git
oc expose svc/nodejs-ex

OpenShift simplifies workflows with oc new-app and oc expose.


👩‍💻 Example: Working with Projects/Namespaces

# Create and switch in OpenShift
oc new-project myapp

# Create namespace in Kubernetes
kubectl create namespace myapp
kubectl config set-context --current --namespace=myapp

⚙️ oc adm (Admin Commands Exclusive to OpenShift)

CommandPurpose
oc adm diagnosticsRun cluster diagnostics
oc adm topView resource usage like kubectl top
oc adm policy add-role-to-userManage RBAC easily
oc adm groupsManage OpenShift user groups
oc adm node-logsView node logs in OpenShift
oc adm drainDrain node (similar to kubectl drain)

🧠 When to Use What?

Use CaseRecommended CLI
Basic Kubernetes operationskubectl or oc
OpenShift templates, routes, and buildsoc only
Admin tasks on OpenShift (RBAC, node mgmt)oc adm
Scripting across clusters (K8s generic)kubectl
Using CRC or OpenShift Onlineoc preferred

📌 Summary Table

Command Typekubectl Supportoc Support
Kubernetes Resources✅ Yes✅ Yes
OpenShift Resources❌ No✅ Yes
CLI Alias of Each Other✅ oc supports all kubectl✅ Yes
Admin Commands❌ Limited✅ Full (oc adm)
Developer Productivity❌ No templating✅ Powerful templates, routes, builds

💡 Tip: You can always alias kubectl to oc if you’re using OpenShift full-time:

alias kubectl='oc'

Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x