How do I directly access my pods running in OpenShift?

You need to have the appropriate RBAC setup to access the project that the pod(s) is deployed into.

Pods are by their very nature ephemeral. Unless you are making a change to something that is mounted to a persistent volume, any change you make will be lost when the pod is destroyed.

Do you need to access the console for a container running in a pod?

If so, then oc rsh is what you want.

Official Documentation

Log into the OpenShift Cluster

oc login [cluster]

Switch to the project where the pod is deployed into:

oc project [project name]

Remote shell into the default container:

oc rsh [pod name]

Remote shell into a specific container in the pod:

oc rsh [pod name] -c [container name]

Do you need to transfer files in/out of a container running in a pod?

If so, then oc rsync is what you want.

Official Documentation

Log into the OpenShift Cluster

oc login [cluster]

Switch to the project where the pod is deployed into:

oc project [project name]

Copy a file up to the default container in a pod:

oc rsync [local path] [pod name]:[pod path]

Copy a file down from the default container running in the pod:

oc rsync [pod name]:[pod path] [local path]

As with the oc rsh command, append -c "container name" to use a specific container in the pod

Do you need to directly access an application over a specific port running in a container in a pod?

If so, then oc port-forward is what you want.

Official Documentation

Log into the OpenShift Cluster

oc login [cluster]

Switch to the project where the pod is deployed into:

oc project [project name]

Start a port-forward session to the default container in a pod:

oc port-forward [pod name] [local port]:[remote port]

As with the oc rsh command, append -c "container name" to use a specific container in the pod

For example, let's say you have deployed an api into OpenShift and it uses MongoDB as its persistent data store. The MongoDB instance is also running in OpenShift. Maybe your front end that consumes the api exposed a route to itself to respond to http requests. But how else can you get to your application?

Let's say you need to query the data in your MongoDB database. Perhaps troubleshoot an issue or initialize some data and you want to use your favorite GUI for interacting with MongoDB, not the command line. To do that, assuming 3306 is the port you are using:

oc port-forward [mongodb pod name] 3306:3306

Leave the terminal running as it will actively proxy requests to localhost:3306 to your running pod.

Use localhost:3306 as the host:port combo for the connection string definition in your favorite GUI and you will be able to interact with your MongoDB database.

Next Post Previous Post