Last active
April 26, 2019 21:18
-
-
Save danielhanold/e7f753740e397e9e7b8a8729f4ced3f0 to your computer and use it in GitHub Desktop.
Bash script to update local hosts file with Minikube ingresses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# A script to update your /etc/hosts file from minikube ingest records. | |
# | |
# Installation | |
# ------------ | |
# curl -L https://gist.github.com/danielhanold/e7f753740e397e9e7b8a8729f4ced3f0/raw/minikube-update-hosts.sh > /usr/local/bin/minikube-update-hosts | |
# chmod +x /usr/local/bin/minikube-update-hosts | |
INGRESSES=$(kubectl --context=minikube --all-namespaces=true get ingress | grep -v NAMESPACE | awk '{ print $2 }' | awk '{ print $1".local"}' | tr '\r\n' ' ') | |
MINIKUBE_IP=$(minikube ip) | |
HOSTS_ENTRY="$MINIKUBE_IP $INGRESSES" | |
HOSTS_ENTRY_HEADER="## minikube-ip-host-entries-start" | |
HOSTS_ENTRY_FOOTER="## minikube-ip-host-entries-end" | |
if grep -Fq "${HOSTS_ENTRY_HEADER}" /etc/hosts > /dev/null | |
then | |
echo "Found existing host entry." | |
echo "Update Minikube IP to ${MINIKUBE_IP} for all Minikube ingresses:" | |
echo "${INGRESSES}" | |
sudo sed -i '' "s/.*192\.168\.99.*/${HOSTS_ENTRY}/g" /etc/hosts | |
else | |
echo "Modifying local hosts file: " | |
echo "" | sudo tee -a /etc/hosts | |
echo "${HOSTS_ENTRY_HEADER}" | sudo tee -a /etc/hosts | |
echo "$HOSTS_ENTRY" | sudo tee -a /etc/hosts | |
echo "${HOSTS_ENTRY_FOOTER}" | sudo tee -a /etc/hosts | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment