OC(1)

πŸ“¦
version 4.22.0 Β· 2 versions
, in nixpkgs unstable

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 the kubectl.kubernetes.io/default-container annotation 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 (like 5s, 2m, or 3h, 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, insecure is 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 exporting KUBECTL_KUBERC=false feature gate or turning off the feature KUBERC=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 with oc 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., do ls -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