OC(1)
oc exec β bestie's guide to running commands inside containers π β¨
Okay so real talk, this is oc exec(1) from the oc manual. It's the OpenShift CLI user manual situation, and it's literally your golden ticket to getting inside a container. No cap. π
NAME πΈ
oc exec β Execute a command in a container. That's it, that's the whole vibe. You're basically teleporting a command into a pod. Iconic behavior only. π¦
SYNOPSIS β¨
oc exec [OPTIONS]
DESCRIPTION π«Ά
Execute a command in a container. Short and sweet, but the doors this opens? Infinite. You got this. π
OPTIONS π
-c,--container=""β the container name, bestie. If you omit it, it uses thekubectl.kubernetes.io/default-containerannotation for selecting the container to be attached, or the first container in the pod will be chosen. Either way, she's covered. π-f,--filename=[]β the filename to use to exec into the resource.--pod-running-timeout=0β how long to wait (like5s,2m, or3h, higher than zero) until at least one pod is running. Patience is a virtue but luckily you can tune it. β³-q,--quiet=falseβ Only print output from the remote session. Minimal noise, maximal focus. π§-i,--stdin=falseβ Pass stdin to the container. Feed her the input she deserves. π-t,--tty=falseβ Stdin is a TTY. Yes queen, give her a real terminal. π₯
OPTIONS INHERITED FROM PARENT COMMANDS π
Okay these are the borrowed-from-parent-command options, they show up everywhere and they're lowkey essential. Don't skip 'em. π
--as=""β Username to impersonate for the operation. User could be a regular user or a service account in a namespace. Main character energy, but make it someone else. π--as-group=[]β Group to impersonate for the operation. This flag can be repeated to specify multiple groups. Stack 'em. π«Ά--as-uid=""β UID to impersonate for the operation.--as-user-extra=[]β User extras to impersonate for the operation. This flag can be repeated to specify multiple values for the same key. π--cache-dir="/homeless-shelter/.kube/cache"β Default cache directory. That path is honestly a mood. π--certificate-authority=""β Path to a cert file for the certificate authority.--client-certificate=""β Path to a client certificate file for TLS.--client-key=""β Path to a client key file for TLS.--cluster=""β The name of the kubeconfig cluster to use.--context=""β The name of the kubeconfig context to use.--disable-compression=falseβ If true, opt-out of response compression for all requests to the server.--insecure-skip-tls-verify=falseβ If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure. β οΈ Like, actually read that again bestie,insecureis literally in the name.--kubeconfig=""β Path to the kubeconfig file to use for CLI requests.--kuberc=""β Path to the kuberc file to use for preferences. This can be disabled by exportingKUBECTL_KUBERC=falsefeature gate or turning off the featureKUBERC=off.--match-server-version=falseβ Require server version to match client version.-n,--namespace=""β If present, the namespace scope for this CLI request. Pick your kingdom, queen. π--profile="none"β Name of profile to capture. One of(none|cpu|heap|goroutine|threadcreate|block|mutex).--profile-output="profile.pprof"β Name of the file to write the profile to.--request-timeout="0"β The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g.1s,2m,3h). A value of zero means don't timeout requests. Zero = infinite patience. Spooky but valid. π-s,--server=""β The address and port of the Kubernetes API server.--tls-server-name=""β Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used.--token=""β Bearer token for authentication to the API server.--user=""β The name of the kubeconfig user to use.--warnings-as-errors=falseβ Treat warnings received from the server as errors and exit with a non-zero exit code. Strict mode: activated. π
EXAMPLE π
These are literally the easiest way to get it, copy-paste vibes fr fr:
# Get output from running the 'date' command from pod mypod, using the first container by default
oc exec mypod -- date
# Get output from running the 'date' command in ruby-container from pod mypod
oc exec mypod -c ruby-container -- date
# Switch to raw terminal mode; sends stdin to 'bash' in ruby-container from pod mypod
# and sends stdout/stderr from 'bash' back to the client
oc exec mypod -c ruby-container -i -t -- bash -il
# List contents of /usr from the first container of pod mypod and sort by modification time
# If the command you want to execute in the pod has any flags in common (e.g. -i),
# you must use two dashes (--) to separate your command's flags/arguments
# Also note, do not surround your command and its flags/arguments with quotes
# unless that is how you would execute it normally (i.e., do ls -t /usr, not "ls -t /usr")
oc exec mypod -i -t -- ls -t /usr
# Get output from running 'date' command from the first pod of the deployment mydeployment, using the first container by default
oc exec deploy/mydeployment -- date
# Get output from running 'date' command from the first pod of the service myservice, using the first container by default
oc exec svc/myservice -- date
β οΈ Okay this part is important: if your command has flags in common withoc exec(like-i), you must use two dashes (--) to separate your command's flags/arguments. And do not surround your command and its flags/arguments with quotes unless that's how you'd execute it normally (i.e., dols -t /usr, not"ls -t /usr"). The way that--saves you is genuinely iconic. π
SEE ALSO π
oc(1)β the parent, the OG. Go say hi. π«Ά
HISTORY πΈ
June 2016, Ported from the Kubernetes man-doc generator. Vintage, honestly. π
k that's the whole page bestie, you ate πβ¨
Openshift β Openshift CLI User Manuals, baby. Version dated June 2016. Go forth and exec slay, no cap. ππ
π¦
π¦ where this page comes from
- nixpkgs unstable: openshift 4.22.0-202605222050
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms