How to run a single one-time command on a kubernetes instance/pod Currently I have a setup on AWS with 4 EC2 machines. They provide a web interface that among other things also has a database search. My recent project was to move the database search to AWS Elastic Search. That took a while but in the end it was fine, because to create the initial index I simply had to SSH into one of the machines, run the command to create the index and I was done.
I could not have done it without SSH'ing into it because the production environment (meaning DB and ES instances) is not directly accessible from dev PCs (which makes sense to me).
So, being quite new to Kubernetes my question is: if we were to migrate these EC2 instances and switch to a Kubernetes kind of setup, how would I run the initial command to create the ES index?
I know I can connect to a pod when it's a single container but these would most likely have containers at least for nginx, redis and django (the one I'd want to connect).
A little more information is needed about specific operations you are doing, but generally your options are:

For one-time operations: use kubectl exec to get into containers and do commands (works similar to docker exec).

Also for one-time operations, spawn separate pods with shell access to interact with existing pods, something along the lines:


kubectl run -it --rm --restart=Never --image busybox tempbusybox -- sh


For reproducible (not one-time) operations, you may use kubernetes jobs.

In some cases you may use init containers for setup tasks.