Update 'firstboot.sh'

This commit is contained in:
Adolfo Delorenzo 2021-07-09 03:51:20 +02:00
parent 81e3553c73
commit cdf74890ea

View File

@ -34,40 +34,50 @@ docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /va
#Add the portainer user to the docker group #Add the portainer user to the docker group
usermod -aG docker portainer usermod -aG docker portainer
#Start minikube
sudo -u portainer minikube start --nodes 3 --driver=docker --ports=":30778" --ports=":9001" --docker-env "restart=unless-stopped"
#Add the metrics server to the minikube cluster
sudo -u portainer minikube addons enable metrics-server
#Define Admin user and Password #Define Admin user and Password
http POST http://localhost:9000/api/users/admin/init Username="portainer" Password="portainer1234" http POST http://localhost:9000/api/users/admin/init Username="portainer" Password="portainer1234"
#Add Portainer Agent to the local kind Kubernetes cluster
sudo -u portainer curl -L https://downloads.portainer.io/portainer-agent-k8s-nodeport.yaml -o /home/portainer/portainer-agent-k8s.yaml; sudo -u portainer kubectl apply -f /home/portainer/portainer-agent-k8s.yaml
sudo -u portainer rm /home/portainer/portainer-agent-k8s.yaml
sleep 15
#Get the admin JWT token #Get the admin JWT token
jwt=`http POST :9000/api/auth Username="portainer" Password="portainer1234" | jq '.jwt' | sed 's/^.//' | sed 's/.$//'` jwt=`http POST :9000/api/auth Username="portainer" Password="portainer1234" | jq '.jwt' | sed 's/^.//' | sed 's/.$//'`
#Add local Docker endpoint #Add local Docker endpoint
http --form POST :9000/api/endpoints \ http --form POST :9000/api/endpoints "Authorization: Bearer $jwt" Name="docker" EndpointCreationType=1
"Authorization: Bearer $jwt" \
Name="docker" EndpointCreationType=1 #Start minikube
sudo -u portainer minikube start --nodes 2 --driver=docker --ports=":30778" --ports=":9001"
#Add the metrics server to the minikube cluster
sudo -u portainer minikube addons enable metrics-server
#Add ingress to the minikube cluster
sudo -u portainer minikube addons enable ingress
#Add Portainer Agent to the local kind Kubernetes cluster
sudo -u portainer curl -qL https://downloads.portainer.io/portainer-agent-k8s-nodeport.yaml -o /home/portainer/portainer-agent-k8s.yaml; sudo -u portainer kubectl apply -f /home/portainer/portainer-agent-k8s.yaml
sudo -u portainer rm /home/portainer/portainer-agent-k8s.yaml
#Check if the Portainer Agent is running
echo ""
echo ""
while true
do
agent_state=`sudo -u portainer kubectl get pod -n portainer | awk '{ print $3 }' | tail -1`
if [ "$agent_state" != "Running" ]; then
echo -ne '⚡ Portainer Agent Not Running yet\r'
else
break
fi
sleep 1
done
#Get mapped 30778 port from control-plane #Get mapped 30778 port from control-plane
jwt=`http POST :9000/api/auth Username="portainer" Password="portainer1234" | jq '.jwt' | sed 's/^.//' | sed 's/.$//'` jwt=`http POST :9000/api/auth Username="portainer" Password="portainer1234" | jq '.jwt' | sed 's/^.//' | sed 's/.$//'`
port=`docker port minikube | grep 30778 | head -1 | awk '$1=$1' FS=":" OFS=" " | awk '{ print $4 }'` port=`docker port minikube | grep 30778 | head -1 | awk '$1=$1' FS=":" OFS=" " | awk '{ print $4 }'`
#Add local Kubernetes endpoint #Add local Kubernetes endpoint
sleep 20 sleep 5
sudo -u portainer http --form POST :9000/api/endpoints \ sudo -u portainer http --form POST :9000/api/endpoints "Authorization: Bearer $jwt" Name="kubernetes" URL="tcp://10.0.2.8:$port" EndpointCreationType=2 TLS="true" TLSSkipVerify="true" TLSSkipClientVerify="true"
"Authorization: Bearer $jwt" \
Name="kubernetes" URL="tcp://10.0.2.8:$port" \
EndpointCreationType=2 \
TLS="true" TLSSkipVerify="true" \
TLSSkipClientVerify="true"
#Housekeeping #Housekeeping
sed -i /@reboot/d /etc/crontab sed -i /@reboot/d /etc/crontab
echo '@reboot root /usr/bin/tmux new-session -d /usr/local/bin/rebuild' >> /etc/crontab