OC(1)
OC(1) π β¨ β Extract Secrets or Config Maps to Disk (bestie edition)
okay so you want to pull secrets and config maps out of your cluster and onto your disk? say less, bestie. this is literally the command for that. oc extract is the main character here, and it's about to make your life so much easier. periodt.
NAME π
oc extract β extract secrets or config maps to disk. that's it. that's the vibe. π
SYNOPSIS β¨
oc extract [OPTIONS]
DESCRIPTION πΈ
okay so picture this: you've got a config map or a secret sitting in your cluster, and you're like "bestie, i need those files locally." that's literally what oc extract does. it downloads the contents of a config map or secret into a directory, and each key in that config map or secret becomes its own separate file β with the name of the key as the filename. it's exactly the same way it works when you mount a secret or config map into a container. no cap. π«Ά
you can also extract the contents to standard out by passing - to the --to option. and when you do that? the names of each key get written to standard error, so you can still see what's what. it's giving "best of both worlds." π
want to be picky about which keys you pull? easy. limit which keys are extracted with the --keys=NAME flag. and if you want to choose where everything lands, just set the directory with --to=DIRECTORY. slay. π
OPTIONS π₯
--confirm=falseβ if you set this totrue, it'll overwrite files that already exist. lowkey important if you don't want to be surprised. π-f,--filename=[]β filename, directory, or URL to a file that identifies the resource you want to extract. it's like a little pointer saying "hey, this one!" π--keys=[]β an optional list of keys to extract. default is all keys. so if you're like "just the nginx.conf please," this is your flag. β¨--to="."β directory to extract files to. the default is.which means "right here, bestie." πΈ
OPTIONS INHERITED FROM PARENT COMMANDS π
these are the flags you get from the parent command, and honestly? there are a lot of them. but we're not skipping any. we would never. π
--as=""β username to impersonate for the operation. user could be a regular user or a service account in a namespace. it's giving "identity crisis but make it kubernetes." π--as-group=[]β group to impersonate for the operation. this flag can be repeated to specify multiple groups. so you can be in multiple groups at once. iconic. π--as-uid=""β UID to impersonate for the operation. yes, you can be a whole different UID. main character energy. π--as-user-extra=[]β user extras to impersonate for the operation. this flag can be repeated to specify multiple values for the same key. fancy. π--cache-dir="/homeless-shelter/.kube/cache"β default cache directory. that's the path. no cap. ποΈ--certificate-authority=""β path to a cert file for the certificate authority. you know, for trust. π--client-certificate=""β path to a client certificate file for TLS. secure vibes only. π--client-key=""β path to a client key file for TLS. the key to the kingdom. π--cluster=""β the name of the kubeconfig cluster to use. pick your fighter. βοΈ--context=""β the name of the kubeconfig context to use. like choosing which universe you're in. π--disable-compression=falseβ iftrue, opt-out of response compression for all requests to the server. sometimes you just want it raw. π--insecure-skip-tls-verify=falseβ iftrue, the server's certificate will not be checked for validity. bestie, this will make your HTTPS connections insecure. so maybe don't unless you know what you're doing. β οΈ
seriously, that one's a little risky. proceed with caution, okay? π«Ά
--kubeconfig=""β path to the kubeconfig file to use for CLI requests. where your cluster config lives. π--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. iykyk. π§--match-server-version=falseβ require server version to match client version. if you're picky about versions, this is your flag. π―-n,--namespace=""β if present, the namespace scope for this CLI request. where the magic happens. π--profile="none"β name of profile to capture. one of(none|cpu|heap|goroutine|threadcreate|block|mutex). yes, those are the exact options. pick your poison. π¬--profile-output="profile.pprof"β name of the file to write the profile to. default isprofile.pprof. cute. π--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. so0is literally "wait forever." π΄-s,--server=""β the address and port of the Kubernetes API server. where you're connecting to. π--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. default behavior is fine, but you can override. β¨--token=""β bearer token for authentication to the API server. like a VIP pass. ποΈ--user=""β the name of the kubeconfig user to use. who are you today? πββοΈ--warnings-as-errors=falseβ treat warnings received from the server as errors and exit with a non-zero exit code. if you're dramatic and want warnings to be full-on errors, this is it. π
EXAMPLE π
here's how you'd actually use it, bestie. these are the exact examples from the original, so you know they're legit:
# Extract the secret "test" to the current directory
oc extract secret/test
# Extract the config map "nginx" to the /tmp directory
oc extract configmap/nginx --to=/tmp
# Extract the config map "nginx" to STDOUT
oc extract configmap/nginx --to=-
# Extract only the key "nginx.conf" from config map "nginx" to the /tmp directory
oc extract configmap/nginx --to=/tmp --keys=nginx.conf
see? literally that easy. you got this. π
SEE ALSO π
check out oc(1) for more. that's the parent command, and it's also iconic. π
HISTORY π
june 2016, ported from the Kubernetes man-doc generator. so it's been around for a minute, but it's still relevant. periodt. π
this page is from Openshift, part of the Openshift CLI User Manuals, and it was last updated in June 2016. slay. πβ¨
π¦ 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