2021-07-08 13:47:42 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-07-08 20:11:46 +00:00
|
|
|
#Delete previous setup
|
|
|
|
sudo -u portainer minikube delete
|
|
|
|
docker stop portainer
|
|
|
|
docker rm portainer
|
|
|
|
docker volume rm portainer_data
|
2021-07-09 01:48:24 +00:00
|
|
|
docker container kill $(docker ps -q)
|
|
|
|
docker container rm $(docker ps -a -q)
|
2021-07-08 13:47:42 +00:00
|
|
|
|
2021-07-08 20:11:46 +00:00
|
|
|
#Install Portainer
|
|
|
|
docker volume create portainer_data
|
|
|
|
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
|
2021-07-08 13:47:42 +00:00
|
|
|
|
2021-07-08 20:11:46 +00:00
|
|
|
#Define Admin user and Password
|
|
|
|
http POST http://localhost:9000/api/users/admin/init Username="portainer" Password="portainer1234"
|
|
|
|
|
2021-07-08 21:27:33 +00:00
|
|
|
#Get the admin JWT token
|
|
|
|
jwt=`http POST :9000/api/auth Username="portainer" Password="portainer1234" | jq '.jwt' | sed 's/^.//' | sed 's/.$//'`
|
|
|
|
|
|
|
|
#Add local Docker endpoint
|
|
|
|
http --form POST :9000/api/endpoints "Authorization: Bearer $jwt" Name="docker" EndpointCreationType=1
|
|
|
|
|
2021-07-08 20:11:46 +00:00
|
|
|
#Start minikube
|
2021-07-08 21:27:33 +00:00
|
|
|
sudo -u portainer minikube start --nodes 2 --driver=docker --ports=":30778" --ports=":9001"
|
2021-07-08 20:11:46 +00:00
|
|
|
|
|
|
|
#Add the metrics server to the minikube cluster
|
|
|
|
sudo -u portainer minikube addons enable metrics-server
|
|
|
|
|
2021-07-09 01:48:24 +00:00
|
|
|
#Add ingress to the minikube cluster
|
|
|
|
sudo -u portainer minikube addons enable ingress
|
|
|
|
|
2021-07-08 20:11:46 +00:00
|
|
|
#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
|
2021-07-09 01:48:24 +00:00
|
|
|
|
|
|
|
#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
|
2021-07-08 20:11:46 +00:00
|
|
|
|
|
|
|
#Get mapped 30778 port from control-plane
|
|
|
|
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 }'`
|
|
|
|
|
|
|
|
#Add local Kubernetes endpoint
|
2021-07-09 01:48:24 +00:00
|
|
|
sleep 5
|
2021-07-08 20:11:46 +00:00
|
|
|
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"
|