ericsysmin's DevOps Blog

Copying files from host to K8s pod via Ansible

Copying files from host to K8s pod via Ansible

There weren’t a lot of resources out there to share how to execute commands or copy files using Ansible and the kubectl  Connection plugin. To help, I decided to document how to use the plugin. At least an example.

Usage is fairly easy. Top copy a file from your Ansible machine to the K8s pod you’ll need to have your ~/.kube/config file setup. Follow kubectl instructions for that part (it can differ depending on your cloud).

In this example, I add the K8s pod to inventory, then copy a file to the K8s pod. I added a step that allows you to see what the file contains if you use -vvv in the Ansible command

There are additional parameters, which are listed here: https://docs.ansible.com/ansible/latest/plugins/connection/kubectl.html