Command Line Interface
Overview
Here is an overview of common oc
commands:
Command | Description |
---|---|
oc login --token=<token> | Login to the DSRI OpenShift cluster in your terminal |
oc get projects | List all available projects |
oc project <project> | Switch to project |
oc get pods | Get running pods (a pod can run one or multiple containers for your application) |
oc rsh <pod_name> <command> | Remote terminal connexion to a pod (Shell/Bash) |
oc cp <from> <to> | Copy files from host to container or vice versa, e.g. from host: oc cp <local dir> <pod>:<pod_dir> or from to host: oc cp <pod>:<pod_dir> <local dir> |
oc rsync <from> <to> | Similar to rsync command on Linux to synchronize directories between container and host or the other way around |
oc exec <pod_id> <folder_path> | Execute command in pods |
oc delete pod <pod_id> | Delete pod |
Projects
List projects
oc projects
Connect to project
oc project my-project
ImageStreams
To update an ImageStream in your project to pull the latest update from the external repository (e.g. from ghcr.io or DockerHub):
oc import-image <imagestream-id>
Pods
Create pod from YAML
oc create -f my-pod.yaml
E.g. d2s-pod-virtuoso.yaml.
List pods
oc get pod
List running pods:
oc get pods --field-selector=status.phase=Running
Get specific pod
oc get pod | grep <pod_id>
Using selector with Apache Flink as example, and showing only the pod id without header:
oc get pod --selector app=flink --selector component=jobmanager --no-headers -o=custom-columns=NAME:.metadata.name
Remote Shell connection
Connect to a pod with Bash.
oc rsh <pod_id>
Execute command in pod
Example creating a folder:
oc exec <pod_id> -- mkdir -p /mnt/workspace/resources
Delete pod
oc delete pod <pod_id>
Force pod deletion
If the pod is not properly deleted, you can force its deletion:
oc delete pod --force --grace-period=0 <pod_id>
Get pod logs
oc logs -f <pod_id>
Debug a pod
Get more details on how to debug a pod.
Create app from template
Create app from template using the CLI and providing parameters as arguments:
oc new-app my-template -p APPLICATION_NAME=my-app -p ADMIN_PASSWORD=mypassword
Example for the Semantic Web course notebooks:
oc new-app template-jupyterstack-notebook -p APPLICATION_NAME=swcourseName -p NOTEBOOK_PASSWORD=PASSWORD
oc delete all --selector template=template-jupyterstack-notebook
Copy files
See the Load data page.