RedHat Openshift command line

Red Hat OpenShift is a Kubernetes-based container platform for managing and orchestrating containerized applications. To interact with OpenShift from the command line, you can use the OpenShift Command-Line Interface (CLI), commonly known as oc. This tool allows you to perform various operations on your OpenShift cluster. Here are some common oc commands and their usage:

  1. Login to OpenShift Cluster:oc login https://<OpenShift Master URL> You will be prompted to provide your credentials.
  2. Project and Namespace Operations:
    • List all projects (namespaces):codeoc get projects
    • Create a new project (namespace):arduinoCopy codeoc new-project <project-name>
  3. Deploy Applications:
    • Deploy an application from a YAML file:create -f <yaml-file>
    • Deploy an application from a Git repository:arduinoCopy codeoc new-app <Git-repo-URL>
  4. Managing Deployments:
    • View deployments:oc get deployments
    • Scale a deployment:oc scale --replicas=<replica-count> deployment/<deployment-name>
  5. Expose Services:
    • Expose a service to the internet:oc expose service <service-name>
    • List routes (public URLs) for your services:arduinoCopy codeoc get routes
  6. Monitoring and Logging:
    • View cluster-wide metrics (requires the OpenShift Monitoring stack):oc get --raw /apis/custom.metrics.k8s.io/v1beta1
    • Access container logs:oc logs <pod-name>
  7. Security and User Management:
    • Create new users or manage user roles (requires appropriate permissions):sqlCopy codeoc create user <username>
    • Add a user to a project (namespace):oc adm policy add-role-to-user <role> <username> -n <project-name>
  8. Viewing Resources:
    • List pods in a project (namespace):oc get pods -n <project-name>
    • Describe a resource:phpCopy codeoc describe <resource-type> <resource-name>
  9. Accessing the Web Console:Open the OpenShift web console in a web browser by running:oc whoami --show-console
  10. Other Useful Commands:
  • Restart a pod:oc delete pod <pod-name>
  • Delete a resource (e.g., a service or deployment):oc delete <resource-type> <resource-name>

These are just some common oc commands for managing and interacting with an OpenShift cluster. The oc CLI is feature-rich and can perform a wide range of operations for application deployment, scaling, monitoring, and more. You can access the full documentation for oc by running oc --help or oc <command> --help for specific command usage information.

Leave a comment