<p>I'm aware of how to copy files between a local machine and a Kubernetes container:</p>
<pre><code>kubectl cp /local_dir/some_file container:/remote_dir/some_file
</code></pre>
<p>And from an s3 bucket to EC2 using AWS CLI:</p>
<pre><code>aws s3 cp remote local
</code></pre>
<p>But unsure of how to copy between s3 and Kubernetes. In Googling the issue I've come across the skbn library, but I'm wondering if there's a way to do it without installing a new package.</p>

triphook
<p>Define an <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">initContainer</a> that mounts a <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">PersistentVolume</a> and uses the aws CLI or some other tool to retrieve files from your S3 bucket and copy them to the PV. Then mount this PV in your normal container as well and reference the files you retrieved accordingly.</p>
<p>Bonus points if you configure your initContainer to accept your AWS Access &amp; Secret Access Keys as well as the S3 Bucket via Environment Variable and you pass these in on runtime.</p>
<p>Alternatively retrieve the files as part of a CI/CD pipeline before deploying the containers to Kubernetes. And volume mount them in accordingly using file or block storage.</p>
<p>EDIT: Looks like an <a href="https://operatorhub.io/operator/awss3-operator-registry" rel="nofollow noreferrer">AWS S3 Operator</a> exists too. However, the <a href="https://github.com/yard-turkey/aws-s3-provisioner" rel="nofollow noreferrer">project</a> is not active nor is it officially created by AWS. I would not recommend using it. Especially when you can codify this process as part of a pipeline or your Deployment manifest.</p>
<p>EDIT 2: I also feel compelled to mention that containers are intended to be stateless and this might be why you're asking this question. While <code>kubectl cp</code> exists, it is by and large a non-standard way of getting files into Kubernetes. Normally you would do this through the use of a PersistentVolume that is provided by a <a href="https://kubernetes.io/docs/concepts/storage/storage-classes/" rel="nofollow noreferrer">StorageClass</a>. With Docker, any changes made to the OS after execution are not persisted; the layer is discarded when the container exits. So rather than <em>copying</em> files into a container like you would a VM, try and use volume mounts to ensure they're there from the start.</p>
