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:
- Login to OpenShift Cluster:
oc login https://<OpenShift Master URL>You will be prompted to provide your credentials. - Project and Namespace Operations:
- List all projects (namespaces):code
oc get projects - Create a new project (namespace):arduinoCopy code
oc new-project <project-name>
- List all projects (namespaces):code
- Deploy Applications:
- Deploy an application from a YAML file:
create -f <yaml-file> - Deploy an application from a Git repository:arduinoCopy code
oc new-app <Git-repo-URL>
- Deploy an application from a YAML file:
- Managing Deployments:
- View deployments:
oc get deployments - Scale a deployment:
oc scale --replicas=<replica-count> deployment/<deployment-name>
- View deployments:
- Expose Services:
- Expose a service to the internet:
oc expose service <service-name> - List routes (public URLs) for your services:arduinoCopy code
oc get routes
- Expose a service to the internet:
- 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>
- View cluster-wide metrics (requires the OpenShift Monitoring stack):
- Security and User Management:
- Create new users or manage user roles (requires appropriate permissions):sqlCopy code
oc create user <username> - Add a user to a project (namespace):
oc adm policy add-role-to-user <role> <username> -n <project-name>
- Create new users or manage user roles (requires appropriate permissions):sqlCopy code
- Viewing Resources:
- List pods in a project (namespace):
oc get pods -n <project-name> - Describe a resource:phpCopy code
oc describe <resource-type> <resource-name>
- List pods in a project (namespace):
- Accessing the Web Console:Open the OpenShift web console in a web browser by running:
oc whoami --show-console - 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.