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
Aspect | oc (OpenShift CLI) | kubectl (Kubernetes CLI) |
---|---|---|
Definition | CLI tool for managing OpenShift resources and clusters | CLI tool for managing Kubernetes resources and clusters |
Default Cluster | Targets OpenShift (Red Hat Kubernetes platform) | Targets any CNCF-compliant Kubernetes cluster |
Installation | Installed with OpenShift tools or CRC | Comes bundled with most Kubernetes distributions |
Resource Access | Supports all Kubernetes APIs + OpenShift APIs (e.g., Build , Route , ImageStream ) | Supports only Kubernetes-native APIs |
Customization | Includes extended functionality and OpenShift-specific templates | No built-in support for OpenShift-only resources |
Login | Uses oc login with OpenShift OAuth | Uses kubectl config or kubeconfig files |
Compatibility | Fully supports kubectl commands as aliases | Cannot access OpenShift-only resources |
✅ Similarities Between oc
and kubectl
Feature | Example Command (same for both) | Description |
---|---|---|
Get Pods | oc get pods / kubectl get pods | Lists pods in current namespace |
Describe Resource | oc describe pod <name> / kubectl describe pod <name> | Detailed pod description |
Apply YAML | oc apply -f app.yaml / kubectl apply -f app.yaml | Apply resource configuration |
Delete Resources | oc delete pod <name> / kubectl delete pod <name> | Delete a resource |
Logs | oc logs <pod> / kubectl logs <pod> | Stream logs from a container |
Port-forward | oc port-forward svc/myapp 8080:80 | Forward local port to a service |
Exec | oc exec -it <pod> -- /bin/bash | Get shell access to a pod |
✅ Fact: Every valid
kubectl
command is also valid inoc
.
🔴 Differences: oc
Adds OpenShift-Specific Features
Command | Only in oc | Purpose |
---|---|---|
oc new-app | Yes | Rapid app deployment from source/image |
oc new-project | Yes | Create a new OpenShift project (namespace) |
oc adm | Yes | OpenShift admin utility commands |
oc rollout | Extended | Manage OpenShift-specific rollouts |
oc status | Yes | Visual overview of current project |
oc whoami | Yes | Check current OpenShift user |
oc get route | Yes | View OpenShift routes (external access) |
oc import-image | Yes | Import images into OpenShift image streams |
oc policy | Yes | RBAC management for OpenShift |
oc start-build | Yes | Trigger OpenShift BuildConfig |
oc logs -f bc/<buildConfig> | Yes | Stream logs from OpenShift build |
⚠️
kubectl
does not support OpenShift-specific resources likeRoute
,BuildConfig
,DeploymentConfig
,ImageStream
.
🧪 Example: Deploying a Sample App
Using kubectl
(Kubernetes way):
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
Code language: CSS (css)
Using oc
(OpenShift way):
oc new-app nodejs~https://github.com/sclorg/nodejs-ex.git
oc expose svc/nodejs-ex
Code language: JavaScript (javascript)
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
Code language: PHP (php)
⚙️ oc adm
(Admin Commands Exclusive to OpenShift)
Command | Purpose |
---|---|
oc adm diagnostics | Run cluster diagnostics |
oc adm top | View resource usage like kubectl top |
oc adm policy add-role-to-user | Manage RBAC easily |
oc adm groups | Manage OpenShift user groups |
oc adm node-logs | View node logs in OpenShift |
oc adm drain | Drain node (similar to kubectl drain ) |
🧠 When to Use What?
Use Case | Recommended CLI |
---|---|
Basic Kubernetes operations | kubectl or oc |
OpenShift templates, routes, and builds | oc only |
Admin tasks on OpenShift (RBAC, node mgmt) | oc adm |
Scripting across clusters (K8s generic) | kubectl |
Using CRC or OpenShift Online | oc preferred |
📌 Summary Table
Command Type | kubectl Support | oc 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'
Code language: JavaScript (javascript)
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at WIZBRAND