$ oc exec <pod> [-c <container>] -- <command> [<arg_1> ... <arg_n>]
You can use the oc exec command to execute remote commands in OKD containers from your local machine.
You can use the OpenShift CLI (oc) to execute remote commands in OKD containers. By running commands in a container, you can perform troubleshooting, inspect logs, run scripts, and other tasks.
Use a command similar to the following to run a command in a container:
$ oc exec <pod> [-c <container>] -- <command> [<arg_1> ... <arg_n>]
For example:
$ oc exec mypod date
Thu Apr 9 02:21:53 UTC 2015
|
For security purposes, the
|
A client resource in your cluster can initiate the execution of a remote command in a container by issuing a request to the Kubernetes API server.
The following example is the format for a typical request to a Kubernetes API server:
/proxy/nodes/<node_name>/exec/<namespace>/<pod>/<container>?command=<command>
where:
<node_name>Specifies the FQDN of the node.
<namespace>Specifies the project of the target pod.
<pod>Specifies the name of the target pod.
<container>Specifies the name of the target container.
<command>Specifies the desired command to be executed.
/proxy/nodes/node123.openshift.com/exec/myns/mypod/mycontainer?command=date
Additionally, the client can add parameters to the request to indicate any of the following conditions:
The client should send input to the remote container’s command (stdin).
The client’s terminal is a TTY.
The remote container’s command should send output from stdout to the client.
The remote container’s command should send output from stderr to the client.
After sending an exec request to the API server, the client upgrades the
connection to one that supports multiplexed streams; the current implementation
uses HTTP/2.
The client creates one stream each for stdin, stdout, and stderr. To distinguish
among the streams, the client sets the streamType header on the stream to one
of stdin, stdout, or stderr.
The client closes all streams, the upgraded connection, and the underlying connection when it is finished with the remote command execution request.