OpenShift Cheatsheet
#
OpenShift is a Kubernetes-based platform that provides a range of tools and services to help developers and IT organizations build, deploy, and manage applications. It offers advanced features like automated updates, integrated CI/CD, and robust security.
Basic Commands
#
Command/Option | Example | Description |
---|
oc login | oc login <server> | Log in to an OpenShift server |
oc new-project | oc new-project <project_name> | Create a new project |
oc project | oc project <project_name> | Switch to a different project |
oc get | oc get pods | List resources (e.g., pods, services, deployments) |
oc describe | oc describe pod <pod_name> | Show detailed information about a resource |
oc delete | oc delete pod <pod_name> | Delete a resource |
Creating and Managing Applications
#
Command/Option | Example | Description |
---|
oc new-app | oc new-app <source_url> | Create a new application from source code, template, or image |
oc start-build | oc start-build <build_name> | Start a new build for an application |
oc get builds | oc get builds | List all builds |
oc get buildconfig | oc get buildconfig | List all build configurations |
oc logs -f build/<build_name> | oc logs -f build/<build_name> | Follow logs for a build |
Deployment Management
#
Command/Option | Example | Description |
---|
oc rollout status | oc rollout status deployment/<deployment_name> | Show the rollout status of a deployment |
oc rollout undo | oc rollout undo deployment/<deployment_name> | Undo a deployment |
oc scale | oc scale --replicas=3 deployment/<deployment_name> | Scale a deployment |
oc set image | oc set image deployment/<deployment_name> <container_name>=<image> | Update the image for a deployment |
Services and Networking
#
Command/Option | Example | Description |
---|
oc expose | oc expose deployment/<deployment_name> --port=<port> | Expose a deployment as a service |
oc get services | oc get services | List all services |
oc describe service <service_name> | oc describe service <service_name> | Show detailed information about a service |
oc get routes | oc get routes | List all routes |
oc create route | oc create route edge --service=<service_name> | Create a new route to a service |
Storage Management
#
Command/Option | Example | Description |
---|
oc get pvc | oc get pvc | List all persistent volume claims (PVCs) |
oc describe pvc <pvc_name> | oc describe pvc <pvc_name> | Show detailed information about a PVC |
oc create pvc | oc create -f <pvc.yaml> | Create a PVC from a YAML file |
oc delete pvc <pvc_name> | oc delete pvc <pvc_name> | Delete a PVC |
Security and Access Control
#
Command/Option | Example | Description |
---|
oc get sa | oc get sa | List all service accounts |
oc describe sa <sa_name> | oc describe sa <sa_name> | Show detailed information about a service account |
oc create sa <sa_name> | oc create sa <sa_name> | Create a new service account |
oc policy add-role-to-user | oc policy add-role-to-user <role> <user> | Add a role to a user |
oc policy remove-role-from-user | oc policy remove-role-from-user <role> <user> | Remove a role from a user |
Monitoring and Logging
#
Command/Option | Example | Description |
---|
oc logs | oc logs <pod_name> | View logs for a pod |
oc logs -f <pod_name> | oc logs -f <pod_name> | Follow logs for a pod |
oc get events | oc get events | List all events in the cluster |
oc top pod | oc top pod | Show resource usage for pods |
This cheatsheet covers essential OpenShift commands for managing applications, deployments, services, storage, security, and monitoring. OpenShift extends Kubernetes with additional features and tools, making it a powerful platform for container orchestration and application lifecycle management.