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
kubectlcommand 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 |
โ ๏ธ
kubectldoes 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 Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals