问题
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>
回答1:
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
回答2:
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'
来源:https://stackoverflow.com/questions/52309342/run-command-on-minikube-startup