{"id":89467,"date":"2025-09-27T20:01:08","date_gmt":"2025-09-27T20:01:08","guid":{"rendered":"https:\/\/www.europesays.com\/ie\/89467\/"},"modified":"2025-09-27T20:01:08","modified_gmt":"2025-09-27T20:01:08","slug":"kubectl-cp-copying-files-to-and-from-kubernetes-pods","status":"publish","type":"post","link":"https:\/\/www.europesays.com\/ie\/89467\/","title":{"rendered":"kubectl cp: Copying Files to and From Kubernetes Pods"},"content":{"rendered":"<p>Deploying apps on <a href=\"https:\/\/thenewstack.io\/kubernetes\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">Kubernetes (K8)<\/a> can feel like walking a tightrope. One wrong step and boom. Your app doesn\u2019t work, your pod crashes, or your team\u2019s stuck debugging for hours.<\/p>\n<p>If this sounds familiar, you\u2019re not alone. A <a href=\"https:\/\/www.cncf.io\/reports\/cncf-annual-survey-2023\/\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">2023 CNCF report<\/a> found that 66% of consumers were using Kubernetes for production, and a majority of them were dealing with <a href=\"https:\/\/thenewstack.io\/kubernetes-complexity-realigns-platform-engineering-strategy\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">K8s\u2019 complexities<\/a>. But many errors are preventable if you know what to look for.<\/p>\n<p>Discover the most common deployment mistakes, what causes them, and how to fix or avoid them.<\/p>\n<p><strong>Coming Up Next<\/strong><\/p>\n<ul>\n<li>Prerequisites and Context<\/li>\n<li>Basic Syntax of kubectl cp<\/li>\n<li>Common Use Cases<\/li>\n<li>Copying Directories and Recursive Transfers<\/li>\n<li>Working With Multicontainer Pods<\/li>\n<li>Copying Across Namespaces and Contexts<\/li>\n<li>Dealing With Symlinks, Permissions, and Preserved Metadata<\/li>\n<li>Troubleshooting kubectl cp Errors<\/li>\n<li>Performance Tips and Alternatives<\/li>\n<li>Security Considerations<\/li>\n<li>Automating File Copy in CI\/CD Pipelines<\/li>\n<li>Wrap-Up: Keep It Simple, Ship It Smooth<\/li>\n<\/ul>\n<p><strong>Prerequisites and Context<\/strong><\/p>\n<p>Before we dive in, let\u2019s make sure you\u2019re set up. You don\u2019t need to be a <a href=\"https:\/\/thenewstack.io\/kubernetes\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">Kubernetes expert<\/a>, but a few basics will help you follow along. Here\u2019s what you should have ready:<\/p>\n<ul>\n<li><strong>A Kubernetes cluster<\/strong> (local or cloud-based)<\/li>\n<li><strong>kubectl installed<\/strong> on your machine<\/li>\n<li><strong>Basic understanding of YAML files<\/strong> (just the idea that they describe how things work in Kubernetes)<\/li>\n<li><strong>An app to deploy<\/strong> \u2014 even a simple \u201cHello World\u201d one works<\/li>\n<li><strong>A bit of command-line comfort<\/strong><\/li>\n<\/ul>\n<p>That\u2019s it, and you\u2019re good to go.<\/p>\n<p><strong>Basic Syntax of <\/strong><strong>kubectl cp<\/strong><\/p>\n<p>The kubectl cp command lets you copy files and folders between your local machine and your <a href=\"https:\/\/thenewstack.io\/kubernetes-building-blocks-nodes-pods-clusters\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">Kubernetes pods<\/a>. It\u2019s like using a USB stick, but for containers.<\/p>\n<p>Under the hood, it uses the tar command to package and transfer files between your system and the container. This means both your machine and the container need to support basic tar operations for it to work smoothly.<\/p>\n<p><strong>Source and Destination Patterns<\/strong><\/p>\n<p>The basic pattern looks like this: kubectl cp  <\/p>\n<p>But here\u2019s the catch: When you\u2019re copying to or from a pod, you need to include: \/:<\/p>\n<p><strong>Examples:<\/strong><\/p>\n<ul>\n<li>Copy a file <strong>from your local machine to a pod: <\/strong>kubectl cp .\/myfile.txt default\/mypod:\/app\/myfile.txt<\/li>\n<li>Copy a file <strong>from a pod to your machine:<\/strong> kubectl cp default\/mypod:\/app\/log.txt .\/log.txt<\/li>\n<\/ul>\n<p><strong>Important Flags (<\/strong><strong>-c, <\/strong><strong>-n, <\/strong><strong>\u2013retries, <\/strong><strong>\u2013no-preserve)<\/strong><\/p>\n<p>Here are the most useful flags for kubectl cp:<\/p>\n<p><strong>Common Use Cases<\/strong><\/p>\n<p>Let\u2019s look at some everyday ways developers use kubectl cp. Whether you\u2019re moving a config file into a pod, grabbing logs from one, or copying data between pods, this command can save time and headaches.<\/p>\n<p><strong>Copying Local Files to a Pod<\/strong><\/p>\n<p>Use this command if you want to send a file from your laptop into a pod: kubectl cp .\/myfile.txt default\/mypod:\/app\/myfile.txt<\/p>\n<p>With this command, we\u2019re telling Kubernetes: \u201cHey, take this file on my computer and put it inside the pod at this path.\u201d<\/p>\n<p><strong>This is helpful when:<\/strong><\/p>\n<ul>\n<li>You\u2019re updating config files<\/li>\n<li>You need to drop in a script or binary<\/li>\n<li>You want to test something quickly<\/li>\n<\/ul>\n<p><strong>Copying Files From a Pod to Local<\/strong><\/p>\n<p>If you need to download something from a pod, just flip the order: kubectl cp default\/mypod:\/app\/log.txt .\/log.txt<\/p>\n<p><strong>This is great for:<\/strong><\/p>\n<ul>\n<li>Saving logs for debugging<\/li>\n<li>Grabbing output files<\/li>\n<li>Backing up config files<\/li>\n<\/ul>\n<p><strong>Pod-to-Pod Copy via Local Hop<\/strong><\/p>\n<p>Kubernetes doesn\u2019t support direct pod-to-pod copy. But here\u2019s a trick:<\/p>\n<ol>\n<li><strong>Copy the file from Pod A to your local machine:<\/strong> kubectl cp default\/pod-a:\/data\/file.txt .\/file.txt<\/li>\n<li><strong>Then copy it from your local machine to Pod B:<\/strong> kubectl cp .\/file.txt default\/pod-b:\/data\/file.txt<\/li>\n<\/ol>\n<p>It\u2019s a two-step process, but it works like a charm when:<\/p>\n<ul>\n<li>You\u2019re <a href=\"https:\/\/thenewstack.io\/cloud-data-migration-or-cloud-data-tiering\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">migrating data<\/a> between services<\/li>\n<li>You need to sync the setup files or logs<\/li>\n<\/ul>\n<p><strong>Copying Directories and Recursive Transfers<\/strong><\/p>\n<p>Sometimes, you need to move a bunch of files, not just one. And luckily, kubectl cp can handle directories, too. Here\u2019s what you need to do:<\/p>\n<ul>\n<li><strong>Point it to the folder you want to copy:<\/strong> kubectl cp .\/myfolder default\/mypod:\/app\/myfolder<\/li>\n<li><strong>Or copy from the pod back to your machine:<\/strong> kubectl cp default\/mypod:\/app\/myfolder .\/myfolder<\/li>\n<\/ul>\n<p><strong>Handling Large Directories Efficiently<\/strong><\/p>\n<p>Big directories can slow things down or cause timeouts. Here are a few tips to keep things smooth:<\/p>\n<p>This method reduces the number of file transfers and speeds up the whole process and works especially well when:<\/p>\n<ul>\n<li>You\u2019re moving lots of small files.<\/li>\n<li>You need to upload full project folders.<\/li>\n<li>You want to avoid transfer timeouts.<\/li>\n<\/ul>\n<p><strong>Working With Multicontainer Pods<\/strong><\/p>\n<p>Some pods have more than one <a href=\"https:\/\/thenewstack.io\/introduction-to-containers\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">container<\/a> inside \u2014 kind of like a lunchbox with multiple compartments. By default, kubectl cp doesn\u2019t know which one you want to copy to or from. So, you need to tell it.<\/p>\n<p><strong>Selecting the Right Container<\/strong><\/p>\n<p>Use the -c flag to name the container you want to work with.<\/p>\n<p><strong>Example:<\/strong> kubectl cp -c my-container .\/file.txt default\/mypod:\/app\/<\/p>\n<p>This tells Kubernetes: \u201cHey, copy this file into the my-container inside mypod.\u201d<\/p>\n<p>You\u2019ll usually need this when:<\/p>\n<ul>\n<li>You\u2019re working with sidecar containers, like one for logs and one for the app.<\/li>\n<li>You only want to target one specific container in the pod.<\/li>\n<li>Your kubectl cp command is failing without it.<\/li>\n<\/ul>\n<p><strong>Copying Across Namespaces and Contexts<\/strong><\/p>\n<p>Kubernetes clusters often have multiple namespaces (like folders) and multiple contexts (like environments). If you don\u2019t specify the right one, your command won\u2019t find the pod.<\/p>\n<p>Here are a few ways to deal with it:<\/p>\n<ul>\n<li><strong>Use <\/strong><strong>-n<\/strong><strong> to pick the right namespace: <\/strong>kubectl cp -n custom-namespace .\/file.txt mypod:\/app\/<\/li>\n<li><strong>Use <\/strong><strong>\u2013context<\/strong><strong> if you\u2019re working in a different cluster: <\/strong>kubectl \u2013context=my-cluster cp .\/file.txt default\/mypod:\/app\/<\/li>\n<li><strong>Check your current context and namespace: <\/strong>\n<ul>\n<li>kubectl config get-contexts<\/li>\n<li>kubectl config view \u2013minify | grep namespace<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>These small <a href=\"https:\/\/thenewstack.io\/what-are-the-next-steps-for-feature-flags\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">flags<\/a> make a big difference when you\u2019re juggling dev, staging, and production setups.<\/p>\n<p><strong>Dealing With Symlinks, Permissions, and Preserved Metadata<\/strong><\/p>\n<p>The kubectl cp command tries to copy things as-is, but there are a few things that can cause problems if you\u2019re not careful.<\/p>\n<p>Here\u2019s what to look out for:<\/p>\n<ul>\n<li><strong>Symlinks may break: <\/strong>Symlinks (shortcut files) might not work as expected after copying. If you\u2019re relying on them, double-check their paths inside the pod.<\/li>\n<li><strong>Permissions might not match: <\/strong>File permissions, such as who can read\/write, may change after copying. Use kubectl exec and chmod inside the pod if needed.<\/li>\n<li><strong>Timestamps are preserved by default: <\/strong>The file keeps its original \u201ccreated\u201d and \u201cmodified\u201d times. To turn this off, use the \u2013no-preserve flag:\n<ul>\n<li>kubectl cp \u2013no-preserve .\/file.txt default\/mypod:\/app\/<\/li>\n<\/ul>\n<\/li>\n<li><strong>Executable files might lose permissions:<\/strong> If your script or binary isn\u2019t working inside the pod, check if it\u2019s still marked as executable:\n<ul>\n<li>kubectl exec -it mypod \u2014 chmod +x \/app\/myscript.sh<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Copying files sounds simple, but the details matter, especially when you\u2019re troubleshooting strange behavior.<\/p>\n<p><strong>Troubleshooting <\/strong><strong>kubectl cp Errors<\/strong><\/p>\n<p>Sometimes, kubectl cp doesn\u2019t work the way you expect. Let\u2019s break down some of the most common errors and exactly how to fix them.<\/p>\n<p><strong>Permission Denied and Read-Only File System<\/strong><\/p>\n<p><strong>The error:<\/strong><\/p>\n<ul>\n<li>tar: .\/file.txt: Cannot open: Permission denied<\/li>\n<li>tar: Exiting with failure status due to previous errors<\/li>\n<\/ul>\n<p><strong>What it means:<\/strong><\/p>\n<ul>\n<li>You\u2019re trying to copy a file into a folder where the <a href=\"https:\/\/thenewstack.io\/containers\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\"><strong>container<\/strong><\/a><strong> doesn\u2019t have write access<\/strong>.<\/li>\n<li>The container\u2019s file system might be <strong>read-only<\/strong>, or your user inside the pod lacks permission.<\/li>\n<\/ul>\n<p><strong>To fix it:<\/strong><\/p>\n<ul>\n<li><strong>Try copying to a different folder, like <\/strong><strong>\/tmp<\/strong><strong>, which is usually writable:<\/strong> kubectl cp .\/file.txt default\/mypod:\/tmp\/<\/li>\n<li><strong>Or, exec into the pod and change permissions (if allowed): <\/strong>kubectl exec -it mypod \u2014 chmod 777 \/target\/folder<\/li>\n<\/ul>\n<p><strong>Heads-up:<\/strong> In production pods, changing permissions may not be allowed, and that\u2019s by design for security.<\/p>\n<p><strong>No Such File or Directory<\/strong><\/p>\n<p><strong>The error:<\/strong><\/p>\n<ul>\n<li>error: one of src or dest must be a local file specification<\/li>\n<li><strong>Or: <\/strong>tar: \/app\/file.txt: No such file or directory<\/li>\n<\/ul>\n<p><strong>What it means:<\/strong><\/p>\n<ul>\n<li>The file or folder path doesn\u2019t exist \u2014 either on your machine or inside the pod.<\/li>\n<li>Or, you misspelled the pod name, container name, or namespace.<\/li>\n<\/ul>\n<p><strong>To fix it:<\/strong><\/p>\n<ul>\n<li><strong>Double-check your source and destination paths.<\/strong> Use kubectl exec to inspect the pod: kubectl exec -it mypod \u2014 ls \/app\/<\/li>\n<li><strong>Make sure you\u2019re targeting the right namespace:<\/strong> kubectl cp -n my-namespace .\/file.txt mypod:\/app\/<\/li>\n<li>Use kubectl get pods to confirm the pod name.<\/li>\n<\/ul>\n<p><strong>Unexpected Tar Format Errors<\/strong><\/p>\n<p><strong>The error: <\/strong>unexpected tar header error<\/p>\n<p><strong>What it means: <\/strong>The kubectl cp command relies on tar under the hood. If tar isn\u2019t installed in the container \u2014 or if the version is too different \u2014 things break.<\/p>\n<p><strong>To fix it:<\/strong><\/p>\n<ol>\n<li><strong>Check if <\/strong><strong>tar<\/strong><strong> exists inside the pod: <\/strong>kubectl exec -it mypod \u2014 which<\/li>\n<li>If tar is missing, you won\u2019t be able to use kubectl cp. You have two options:\n<ol>\n<li><strong>Install <\/strong><strong>tar<\/strong>, if possible and safe to do so.<\/li>\n<li><strong>Use an alternative<\/strong> like the tar + exec combo (explained below!)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><strong>Performance Tips and Alternatives<\/strong><\/p>\n<p>If you\u2019re moving large files or lots of files, kubectl cp can be slow. Or flaky. Here are a couple of tips that offer faster, more reliable alternatives.<\/p>\n<p><strong>Using Tar Over <\/strong><strong>kubectl exec for Big Files<\/strong><\/p>\n<p>Instead of kubectl cp, try creating a tar archive yourself and pushing it using kubectl exec. This avoids many of the bugs tied to kubectl cp.<\/p>\n<p><strong>Example: Copying to a pod<\/strong><\/p>\n<ol>\n<li><strong>Compress your files: <\/strong>tar -czf files.tar.gz myfolder\/<\/li>\n<li><strong>Copy the archive:<\/strong> kubectl cp .\/files.tar.gz default\/mypod:\/tmp\/<\/li>\n<li><strong>Unpack it inside the pod: <\/strong>kubectl exec -it mypod \u2014 tar -xzf \/tmp\/files.tar.gz -C \/app\/<\/li>\n<\/ol>\n<p><strong>This method works better because it: <\/strong><\/p>\n<ul>\n<li>Has fewer files, which means faster transfers<\/li>\n<li>Offers more control over how things are unpacked<\/li>\n<li>Works even if kubectl cp is flaky<\/li>\n<\/ul>\n<p><strong>Leveraging <\/strong><strong>rsync via <\/strong><strong>kubectl port-forward<\/strong><\/p>\n<p>If you want blazing-fast file sync, try <a href=\"https:\/\/thenewstack.io\/linux-synchronize-local-and-remote-directories-with-rsync\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">rsync<\/a> \u2014 a powerful file transfer tool. It\u2019s not built into Kubernetes, but you can port-forward to a container running rsync, and then push files directly.<\/p>\n<p><strong>Here\u2019s how you can do it:<\/strong><\/p>\n<ol>\n<li><strong>Run rsync inside a container<\/strong>, either install it or use a custom image that has it.<\/li>\n<li><strong>Port-forward to expose rsync: <\/strong>kubectl port-forward pod\/mypod 8730:873<\/li>\n<li><strong>Use rsync from your machine to push files: <\/strong>rsync -av .\/myfolder rsync:\/\/localhost:8730\/app\/<\/li>\n<\/ol>\n<p><strong>This method works well because it:<\/strong><\/p>\n<ul>\n<li>Is fast and efficient for lots of files<\/li>\n<li>Only transfers what\u2019s changed, which saves time<\/li>\n<li>Is great for syncing folders during dev<\/li>\n<\/ul>\n<p>That said, you\u2019ll need a container with rsync installed, and security rules that allow port-forwarding.<\/p>\n<p><strong>Security Considerations<\/strong><\/p>\n<p>Copying files in and out of pods might seem harmless, but it can open doors to risks if you\u2019re not careful. Let\u2019s look at two key areas: Permissions and data safety.<\/p>\n<p><strong>RBAC Rules for Copy Operations<\/strong><\/p>\n<p>Kubernetes uses <a href=\"https:\/\/thenewstack.io\/kubernetes-rbac-permissions-you-might-not-know-about-but-should\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">role-based access control (RBAC)<\/a> to decide who can do what. Copying files with kubectl cp involves actions like:<\/p>\n<ul>\n<li>Reading from a pod<\/li>\n<li>Writing to a pod<\/li>\n<li>Executing commands inside the container (via tar)<\/li>\n<\/ul>\n<p>So, to use kubectl cp, you must have permission to get, list, and exec pods in the right namespace.<\/p>\n<p>If you see access denied errors, it\u2019s likely your user or service account doesn\u2019t have these rights. An admin can fix this by updating the <strong>Role<\/strong> or <strong>ClusterRole<\/strong> bindings.<\/p>\n<p><strong>Example Role:<\/strong><\/p>\n<p>\nrules:&#13;<br \/>\n&#13;<br \/>\n&#8211; apiGroups: [&#8220;&#8221;]&#13;<br \/>\n&#13;<br \/>\nresources: [&#8220;pods&#8221;, &#8220;pods\/exec&#8221;]&#13;<br \/>\n&#13;<br \/>\nverbs: [&#8220;get&#8221;, &#8220;list&#8221;, &#8220;create&#8221;, &#8220;delete&#8221;, &#8220;exec&#8221;]<\/p>\n<p>\t\t\t\t&#13;<\/p>\n<tr class=\"crayon-row\">&#13;<\/p>\n<td class=\"crayon-nums \" data-settings=\"show\">&#13;<br \/>\n\t\t\t\t\t&#13;\n\t\t\t\t<\/td>\n<p>&#13;<\/p>\n<td class=\"crayon-code\">\n<p>rules:<\/p>\n<p>\u00a0<\/p>\n<p>&#8211; apiGroups: [&#8220;&#8221;]<\/p>\n<p>\u00a0<\/p>\n<p>resources: [&#8220;pods&#8221;, &#8220;pods\/exec&#8221;]<\/p>\n<p>\u00a0<\/p>\n<p>verbs: [&#8220;get&#8221;, &#8220;list&#8221;, &#8220;create&#8221;, &#8220;delete&#8221;, &#8220;exec&#8221;]<\/p>\n<\/td>\n<p>&#13;<br \/>\n\t\t\t\t\t<\/tr>\n<p>&#13;<\/p>\n<p><strong>Pro tip:<\/strong> Always follow least privilege, i.e., give only the access that\u2019s needed and nothing more.<\/p>\n<p><strong>Avoiding Sensitive Data Leakage<\/strong><\/p>\n<p>Copying files can accidentally expose secrets if you\u2019re not paying attention. Here\u2019s how to stay safe:<\/p>\n<ul>\n<li><strong>Never copy files into a pod\u2019s <\/strong><strong>\/etc<\/strong><strong>, <\/strong><strong>\/secrets<\/strong><strong>, or system directories<\/strong> unless you know what you\u2019re doing.<\/li>\n<li><strong>Don\u2019t copy secrets out of pods<\/strong>, like TLS certificates, config files, or .env<\/li>\n<li><strong>Review file contents before copying<\/strong>, especially when using wildcard commands or whole directories.<\/li>\n<li><strong>Audit who has access<\/strong> to kubectl cp, and make sure devs aren\u2019t copying sensitive files into shared or production pods.<\/li>\n<\/ul>\n<p><strong>Pro tip: <\/strong>If you\u2019re working with sensitive files (like keys, certs, or passwords), use <a href=\"https:\/\/thenewstack.io\/how-to-centralize-kubernetes-secrets-management-with-vault\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">Kubernetes Secrets<\/a> instead. They\u2019re made for that.<\/p>\n<p><strong>Automating File Copy in CI\/CD Pipelines<\/strong><\/p>\n<p>In a <a href=\"https:\/\/thenewstack.io\/ci-cd\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">CI\/CD pipeline<\/a>, manual steps are the enemy. You want everything, including file transfers, to run automatically and reliably.<\/p>\n<p>Using kubectl cp in your pipeline works for basic tasks, but there are a few things to keep in mind to make it safe and stable.<\/p>\n<p>For instance, you need to know when to automate file copy. You might want to copy files during:<\/p>\n<ul>\n<li><strong>Pre-deployment steps<\/strong>, such as injecting config files into a pod.<\/li>\n<li><strong>Post-deployment tests<\/strong>, like pulling logs or results from a test container.<\/li>\n<li><strong>Data migration<\/strong> between app versions.<\/li>\n<\/ul>\n<p><strong>Sample command in a pipeline script:<\/strong><\/p>\n<p>\nkubectl cp .\/build\/output.zip default\/my-app-pod:\/app\/output.zip<\/p>\n<p>\t\t\t\t&#13;<\/p>\n<tr class=\"crayon-row\">&#13;<\/p>\n<td class=\"crayon-nums \" data-settings=\"show\">&#13;<br \/>\n\t\t\t\t\t&#13;\n\t\t\t\t<\/td>\n<p>&#13;<\/p>\n<td class=\"crayon-code\">\n<p>kubectl cp .\/build\/output.zip default\/my-app-pod:\/app\/output.zip<\/p>\n<\/td>\n<p>&#13;<br \/>\n\t\t\t\t\t<\/tr>\n<p>&#13;<\/p>\n<p>You can drop this into a CI\/CD job step \u2014 in GitHub Actions, GitLab CI, or Jenkins.<\/p>\n<p>And here are a few things to keep in mind when automating file copy:<\/p>\n<ul>\n<li><strong>Always set the namespace<\/strong> with -n so the command doesn\u2019t rely on local configs: kubectl cp -n staging .\/file.txt mypod:\/app\/<\/li>\n<li><strong>Set <\/strong><strong>KUBECONFIG<\/strong> in your CI environment to point to the right cluster.<\/li>\n<li><strong>Add retries or checks<\/strong> in case the pod isn\u2019t ready yet: kubectl wait \u2013for=condition=Ready pod\/mypod<\/li>\n<li><strong>Use <\/strong><strong>tar + exec<\/strong> instead of kubectl cp if your container doesn\u2019t have tar, or if kubectl cp is flaky in your setup.<\/li>\n<\/ul>\n<p>Remember to ensure that your CI runner only has access to what it needs. Don\u2019t give it full admin rights just to copy files. Use a service account with the bare minimum permissions instead.<\/p>\n<p><strong>Wrapping Up: Keep It Simple, Ship It Smooth<\/strong><\/p>\n<p>Copying files in Kubernetes can be tricky, but with the right approach \u2014 using the correct flags, understanding pod\/container setups, avoiding common errors, and optimizing for performance \u2014 it becomes a smooth part of your workflow. Whether you\u2019re working in dev, CI\/CD, or production, knowing how to handle file transfers gives you more control and fewer headaches.<\/p>\n<p>If you\u2019re ready to automate even more of your Kubernetes tasks, <a href=\"https:\/\/thenewstack.io\/how-to-run-kubernetes-commands-in-go-steps-and-best-practices\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">check out our guide on how to run Kubernetes commands in Go<\/a>. We talk about how to programmatically handle file operations, deployments, and more using Go.<\/p>\n<p><strong>Primary sources: <\/strong><\/p>\n<p>\t<a class=\"row youtube-subscribe-block\" href=\"https:\/\/youtube.com\/thenewstack?sub_confirmation=1\" target=\"_blank\" rel=\"nofollow noopener\"><\/p>\n<p>\n\t\t\t\tYOUTUBE.COM\/THENEWSTACK\n\t\t\t<\/p>\n<p>\n\t\t\t\tTech moves fast, don&#8217;t miss an episode. Subscribe to our YouTube<br \/>\n\t\t\t\tchannel to stream all our podcasts, interviews, demos, and more.\n\t\t\t<\/p>\n<p>\t\t\t\tSUBSCRIBE<\/p>\n<p>\t<\/a><\/p>\n<p>    Group<br \/>\n    Created with Sketch.<\/p>\n<p>\t\t<a href=\"https:\/\/thenewstack.io\/author\/joab\/\" class=\"author-more-link\" rel=\"nofollow noopener\" target=\"_blank\"><\/p>\n<p>\t\t\t\t\t<img decoding=\"async\" class=\"post-author-avatar\" src=\"https:\/\/www.europesays.com\/ie\/wp-content\/uploads\/2025\/09\/1759003268_423_327440bd-joab-jackson_avatar_1495152980.-600x600.jpeg\"\/><\/p>\n<p>\n\t\t\t\t\t\t\tJoab Jackson is a senior editor for The New Stack, covering cloud native computing and system operations. He has reported on IT infrastructure and development for over 30 years, including stints at IDG and Government Computer News. Before that, he&#8230;\t\t\t\t\t\t<\/p>\n<p>\t\t\t\t\t\tRead more from Joab Jackson\t\t\t\t\t\t<\/p>\n<p>\t\t<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"Deploying apps on Kubernetes (K8) can feel like walking a tightrope. One wrong step and boom. Your app&hellip;\n","protected":false},"author":2,"featured_media":89468,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[18,19,17,82,58442],"class_list":{"0":"post-89467","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-technology","8":"tag-eire","9":"tag-ie","10":"tag-ireland","11":"tag-technology","12":"tag-tutorial"},"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"https:\/\/www.europesays.com\/ie\/wp-json\/wp\/v2\/posts\/89467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.europesays.com\/ie\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.europesays.com\/ie\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.europesays.com\/ie\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.europesays.com\/ie\/wp-json\/wp\/v2\/comments?post=89467"}],"version-history":[{"count":0,"href":"https:\/\/www.europesays.com\/ie\/wp-json\/wp\/v2\/posts\/89467\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.europesays.com\/ie\/wp-json\/wp\/v2\/media\/89468"}],"wp:attachment":[{"href":"https:\/\/www.europesays.com\/ie\/wp-json\/wp\/v2\/media?parent=89467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.europesays.com\/ie\/wp-json\/wp\/v2\/categories?post=89467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.europesays.com\/ie\/wp-json\/wp\/v2\/tags?post=89467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}