Run command on Minikube startup

9/13/2018

I'm using Minikube for working with Kubernetes on my local machine, and would like to run a command on the VM just after startup (preferably before the Pods start). I can run it manually with minikube ssh, but that's a bit of a pain to do after every restart, and is difficult to wrap in a script.

Is there an easy way to do this?

The command in my case is this, so that paths on the VM match paths on my host machine:

sudo mount --bind /hosthome/<user> /home/<user>
-- Ralf
kubernetes
minikube

2 Answers

9/13/2018

Maybe flags which can you pass to minikube start would be useful in your case:

  --mount                          This will start the mount daemon and automatically mount files into minikube
  --mount-string string            The argument to pass the minikube mount command on start (default "/home/user:/minikube-host")

Edit: Maybe you could write script for starting your minikube like:

minikube start && ssh -t -i ~/.minikube/machines/minikube/id_rsa docker@$(minikube ip) "sudo mount --bind /hosthome/<user> /home/<user>"

that will start minikube and issue bind command using SSH after start

-- Jakub Bujny
Source: StackOverflow

1/29/2019

If you need a command run on every start/stop of minikube, you can put it in the script /var/lib/boot2docker/bootlocal.sh which will run on every VM start and is persisted. So, in order to put your command in bootlocal.sh, run from your host machine:

minikube ssh 'echo "sudo mount --bind /hosthome/<user> /home/<user>" | sudo tee -a /var/lib/boot2docker/bootlocal.sh'
-- Al Mahdi Chihaoui
Source: StackOverflow