Skip to content

Instantly share code, notes, and snippets.

@lrpinto
Last active August 28, 2024 16:30
Show Gist options
  • Save lrpinto/e2c088124937c7ffd8c297abf22a3a85 to your computer and use it in GitHub Desktop.
Save lrpinto/e2c088124937c7ffd8c297abf22a3a85 to your computer and use it in GitHub Desktop.
OpenShift CLI (oc) Cheat Sheet

OpenShift CLI (oc) Cheat Sheet

Basic Commands

  • Login to OpenShift

    oc login <server_url> --token=<your_token>
  • Get Cluster Information

    oc status
  • Get Projects

    oc projects
  • Switch to a Project

    oc project <project_name>

Working with Pods

  • List All Pods

    oc get pods
  • Describe a Pod

    oc describe pod <pod_name>
  • Get Pod Logs

    oc logs <pod_name>
  • Execute a Command Inside a Pod

    oc exec <pod_name> -- <command>

Deployments and DeploymentConfigs

  • List All Deployments

    oc get deployments
  • View Deployment Details

    oc describe deployment <deployment_name>
  • List All DeploymentConfigs

    oc get deploymentconfigs
  • View DeploymentConfig Details

    oc describe deploymentconfig <deployment_config_name>

Rollouts

  • Trigger a New Deployment Rollout (Kubernetes Deployment)

    • Restarts a Kubernetes Deployment to trigger a new rollout.
    oc rollout restart deployment/<deployment_name>
  • Trigger a New Deployment Rollout (OpenShift DeploymentConfig)

    • For triggering a new rollout using an OpenShift DeploymentConfig.
    oc rollout latest <deployment_config_name>
  • Scale Down and Up to Rollout (Kubernetes Deployment)

    • Another method to trigger a new rollout by scaling down and then back up.
    oc scale deployment <deployment_name> --replicas=0
    oc scale deployment <deployment_name> --replicas=1

Services and Routes

  • List Services

    oc get svc
  • Describe a Service

    oc describe svc <service_name>
  • List Routes

    oc get routes
  • Describe a Route

    oc describe route <route_name>

Builds and Image Streams

  • List Builds

    oc get builds
  • Start a New Build

    oc start-build <build_name>
  • List Image Streams

    oc get is
  • Describe an Image Stream

    oc describe is <image_stream_name>

Scaling Applications

  • Scale a Deployment

    oc scale --replicas=<number_of_replicas> deployment/<deployment_name>
  • Scale a DeploymentConfig

    oc scale --replicas=<number_of_replicas> deploymentconfig/<deployment_config_name>

Application Management

  • Delete an Application
    oc delete all -l app=<application_name>

Exposing Services

  • Expose a Service as a Route
    oc expose svc/<service_name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment