Last active
October 26, 2022 15:50
-
-
Save jacobtomlinson/4b835d807ebcea73c6c8f602613803d4 to your computer and use it in GitHub Desktop.
A script to update your /etc/hosts file from minikube ingest records
This file contains hidden or 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/jacobtomlinson/4b835d807ebcea73c6c8f602613803d4/raw/minikube-update-hosts.sh > /usr/local/bin/minikube-update-hosts | |
# chmod +x /usr/local/bin/minikube-update-hosts | |
set -e | |
INGRESSES=$(kubectl --context=minikube --all-namespaces=true get ingress -o jsonpath='{.items[*].spec.rules[*].host}') | |
MINIKUBE_IP=$(minikube ip) | |
HOSTS_ENTRY="$MINIKUBE_IP $INGRESSES" | |
if grep -Fq "$MINIKUBE_IP" /etc/hosts > /dev/null | |
then | |
sudo sed -i '' "s/^$MINIKUBE_IP.*/$HOSTS_ENTRY/" /etc/hosts | |
echo "Updated hosts entry" | |
else | |
echo "$HOSTS_ENTRY" | sudo tee -a /etc/hosts | |
echo "Added hosts entry" | |
fi |
#!/bin/bash
#
# A script to update your /etc/hosts file from minikube ingest records
#
# Installation
# ------------
# curl -L https://gist.github.com/jacobtomlinson/4b835d807ebcea73c6c8f602613803d4/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 -o jsonpath='{.items[*].spec.rules[*].host}')
MINIKUBE_IP=$(minikube ip)
HOSTS_ENTRY="$MINIKUBE_IP $INGRESSES"
if grep -Fq "$MINIKUBE_IP" /etc/hosts > /dev/null
then
sudo sed -i '' "s/^$MINIKUBE_IP.*/$HOSTS_ENTRY/" /etc/hosts
echo "Updated hosts entry"
else
echo "$HOSTS_ENTRY" | sudo tee -a /etc/hosts
echo "Added hosts entry"
fi
Thanks @alwinmarkcf and @orefalo I've updated the gist.
I'd advise to use set -e
on top of the script, because if something goes wrong with the kubectl
or minikube
commands, you will end up scrambling up your /etc/hosts file
I'd advise to use
set -e
on top of the script, because if something goes wrong with thekubectl
orminikube
commands, you will end up scrambling up your /etc/hosts file
Done thanks @svilenkov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of:
Also for me it would have been
awk '{print $3}'