update
This commit is contained in:
parent
7a7838468d
commit
3f8cfb9ce9
|
@ -110,6 +110,12 @@ sudo mkdir -p /etc/rancher/rke2
|
||||||
touch config.yaml
|
touch config.yaml
|
||||||
echo "tls-san:" >> config.yaml
|
echo "tls-san:" >> config.yaml
|
||||||
echo " - $vip" >> config.yaml
|
echo " - $vip" >> config.yaml
|
||||||
|
echo " - $master1" >> config.yaml
|
||||||
|
echo " - $master2" >> config.yaml
|
||||||
|
echo " - $master3" >> config.yaml
|
||||||
|
echo "write-kubeconfig-mode: 0644" >> config.yaml
|
||||||
|
echo "disable:" >> config.yaml
|
||||||
|
echo " - rke2-ingress-nginx" >> config.yaml
|
||||||
# copy config.yaml to rancher directory
|
# copy config.yaml to rancher directory
|
||||||
sudo cp ~/config.yaml /etc/rancher/rke2/config.yaml
|
sudo cp ~/config.yaml /etc/rancher/rke2/config.yaml
|
||||||
|
|
||||||
|
@ -138,24 +144,24 @@ echo "StrictHostKeyChecking no" > ~/.ssh/config
|
||||||
ssh-copy-id -i /home/$user/.ssh/$certName $user@$admin
|
ssh-copy-id -i /home/$user/.ssh/$certName $user@$admin
|
||||||
scp -i /home/$user/.ssh/$certName /var/lib/rancher/rke2/server/token $user@$admin:~/token
|
scp -i /home/$user/.ssh/$certName /var/lib/rancher/rke2/server/token $user@$admin:~/token
|
||||||
scp -i /home/$user/.ssh/$certName /etc/rancher/rke2/rke2.yaml $user@$admin:~/.kube/rke2.yaml
|
scp -i /home/$user/.ssh/$certName /etc/rancher/rke2/rke2.yaml $user@$admin:~/.kube/rke2.yaml
|
||||||
kubectl apply -f https://kube-vip.io/manifests/rbac.yaml
|
|
||||||
exit
|
exit
|
||||||
EOF
|
EOF
|
||||||
echo -e " \033[32;5mMaster1 Completed\033[0m"
|
echo -e " \033[32;5mMaster1 Completed\033[0m"
|
||||||
|
|
||||||
# Step 4: Install kube-vip as network LoadBalancer - Install the kube-vip Cloud Provider
|
# Step 4: Set variable to the token we just extracted, set kube config location
|
||||||
kubectl apply -f https://raw.githubusercontent.com/kube-vip/kube-vip-cloud-provider/main/manifest/kube-vip-cloud-controller.yaml
|
|
||||||
#IP range for loadbalancer services to use
|
|
||||||
kubectl create configmap -n kube-system kubevip --from-literal range-global=$lbrange
|
|
||||||
|
|
||||||
# Step 5: Set variable to the token we just extracted, set kube config location
|
|
||||||
token=`cat token`
|
token=`cat token`
|
||||||
sudo cat ~/.kube/rke2.yaml | sed 's/127.0.0.1/'$vip'/g' > $HOME/.kube/config
|
sudo cat ~/.kube/rke2.yaml | sed 's/127.0.0.1/'$master1'/g' > $HOME/.kube/config
|
||||||
sudo chown $(id -u):$(id -g) $HOME/.kube/config
|
sudo chown $(id -u):$(id -g) $HOME/.kube/config
|
||||||
export KUBECONFIG=${HOME}/.kube/config
|
export KUBECONFIG=${HOME}/.kube/config
|
||||||
sudo cp ~/.kube/config /etc/rancher/rke2/rke2.yaml
|
sudo cp ~/.kube/config /etc/rancher/rke2/rke2.yaml
|
||||||
kubectl get nodes
|
kubectl get nodes
|
||||||
|
|
||||||
|
# Step 5: Install kube-vip as network LoadBalancer - Install the kube-vip Cloud Provider
|
||||||
|
kubectl apply -f https://kube-vip.io/manifests/rbac.yaml
|
||||||
|
kubectl apply -f https://raw.githubusercontent.com/kube-vip/kube-vip-cloud-provider/main/manifest/kube-vip-cloud-controller.yaml
|
||||||
|
#IP range for loadbalancer services to use
|
||||||
|
kubectl create configmap -n kube-system kubevip --from-literal range-global=$lbrange
|
||||||
|
|
||||||
# Step 6: Add other Masternodes, note we import the token we extracted from step 3
|
# Step 6: Add other Masternodes, note we import the token we extracted from step 3
|
||||||
for newnode in "${masters[@]}"; do
|
for newnode in "${masters[@]}"; do
|
||||||
ssh -tt $user@$newnode -i ~/.ssh/$certName sudo su <<EOF
|
ssh -tt $user@$newnode -i ~/.ssh/$certName sudo su <<EOF
|
||||||
|
@ -165,6 +171,9 @@ for newnode in "${masters[@]}"; do
|
||||||
echo "server: https://$master1:9345" >> /etc/rancher/rke2/config.yaml
|
echo "server: https://$master1:9345" >> /etc/rancher/rke2/config.yaml
|
||||||
echo "tls-san:" >> /etc/rancher/rke2/config.yaml
|
echo "tls-san:" >> /etc/rancher/rke2/config.yaml
|
||||||
echo " - $vip" >> /etc/rancher/rke2/config.yaml
|
echo " - $vip" >> /etc/rancher/rke2/config.yaml
|
||||||
|
echo " - $master1" >> /etc/rancher/rke2/config.yaml
|
||||||
|
echo " - $master2" >> /etc/rancher/rke2/config.yaml
|
||||||
|
echo " - $master3" >> /etc/rancher/rke2/config.yaml
|
||||||
curl -sfL https://get.rke2.io | sh -
|
curl -sfL https://get.rke2.io | sh -
|
||||||
systemctl enable rke2-server.service
|
systemctl enable rke2-server.service
|
||||||
systemctl start rke2-server.service
|
systemctl start rke2-server.service
|
||||||
|
@ -173,6 +182,8 @@ EOF
|
||||||
echo -e " \033[32;5mMaster node joined successfully!\033[0m"
|
echo -e " \033[32;5mMaster node joined successfully!\033[0m"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
kubectl get nodes
|
||||||
|
|
||||||
# Step 7: Add Workers
|
# Step 7: Add Workers
|
||||||
for newnode in "${workers[@]}"; do
|
for newnode in "${workers[@]}"; do
|
||||||
ssh -tt $user@$newnode -i ~/.ssh/$certName sudo su <<EOF
|
ssh -tt $user@$newnode -i ~/.ssh/$certName sudo su <<EOF
|
||||||
|
@ -180,6 +191,9 @@ for newnode in "${workers[@]}"; do
|
||||||
touch /etc/rancher/rke2/config.yaml
|
touch /etc/rancher/rke2/config.yaml
|
||||||
echo "token: $token" >> /etc/rancher/rke2/config.yaml
|
echo "token: $token" >> /etc/rancher/rke2/config.yaml
|
||||||
echo "server: https://$vip:9345" >> /etc/rancher/rke2/config.yaml
|
echo "server: https://$vip:9345" >> /etc/rancher/rke2/config.yaml
|
||||||
|
echo "node-label:" >> /etc/rancher/rke2/config.yaml
|
||||||
|
echo " - worker=true" >> /etc/rancher/rke2/config.yaml
|
||||||
|
echo " - longhorn=true" >> /etc/rancher/rke2/config.yaml
|
||||||
curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE="agent" sh -
|
curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE="agent" sh -
|
||||||
systemctl enable rke2-agent.service
|
systemctl enable rke2-agent.service
|
||||||
systemctl start rke2-agent.service
|
systemctl start rke2-agent.service
|
||||||
|
@ -188,11 +202,9 @@ EOF
|
||||||
echo -e " \033[32;5mMaster node joined successfully!\033[0m"
|
echo -e " \033[32;5mMaster node joined successfully!\033[0m"
|
||||||
done
|
done
|
||||||
|
|
||||||
#Step 8: Setup Kube-VIP as LoadBalancer
|
kubectl get nodes
|
||||||
#IP range for loadbalancer services to use
|
|
||||||
kubectl create configmap -n kube-system kubevip --from-literal range-global=$lbrange
|
|
||||||
|
|
||||||
# Step 9: Install Rancher (Optional - Delete if not required)
|
# Step 8: Install Rancher (Optional - Delete if not required)
|
||||||
#Install Helm
|
#Install Helm
|
||||||
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
|
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
|
||||||
chmod 700 get_helm.sh
|
chmod 700 get_helm.sh
|
||||||
|
@ -203,7 +215,7 @@ helm repo add rancher-latest https://releases.rancher.com/server-charts/latest
|
||||||
kubectl create namespace cattle-system
|
kubectl create namespace cattle-system
|
||||||
|
|
||||||
# Install Cert-Manager
|
# Install Cert-Manager
|
||||||
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.11.0/cert-manager.crds.yaml
|
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.2/cert-manager.crds.yaml
|
||||||
helm repo add jetstack https://charts.jetstack.io
|
helm repo add jetstack https://charts.jetstack.io
|
||||||
helm repo update
|
helm repo update
|
||||||
helm install cert-manager jetstack/cert-manager \
|
helm install cert-manager jetstack/cert-manager \
|
||||||
|
@ -222,13 +234,14 @@ kubectl -n cattle-system get deploy rancher
|
||||||
|
|
||||||
# Add Rancher LoadBalancer
|
# Add Rancher LoadBalancer
|
||||||
kubectl get svc -n cattle-system
|
kubectl get svc -n cattle-system
|
||||||
# sometimes it skips the install so do it again here - need to debug
|
|
||||||
kubectl apply -f https://raw.githubusercontent.com/kube-vip/kube-vip-cloud-provider/main/manifest/kube-vip-cloud-controller.yaml
|
|
||||||
kubectl expose deployment rancher --name=rancher-lb --port=443 --type=LoadBalancer -n cattle-system
|
kubectl expose deployment rancher --name=rancher-lb --port=443 --type=LoadBalancer -n cattle-system
|
||||||
while [[ $(kubectl get svc name=rancher-lb -n cattle-system 'jsonpath={..status.conditions[?(@.type=="Pending")].status}') = "True" ]]; do
|
while [[ $(kubectl get svc -n cattle-system 'jsonpath={..status.conditions[?(@.type=="Pending")].status}') = "True" ]]; do
|
||||||
sleep 5
|
sleep 5
|
||||||
echo -e " \033[32;5mWaiting for LoadBalancer to come online\033[0m"
|
echo -e " \033[32;5mWaiting for LoadBalancer to come online\033[0m"
|
||||||
done
|
done
|
||||||
kubectl get svc -n cattle-system
|
kubectl get svc -n cattle-system
|
||||||
|
|
||||||
echo -e " \033[32;5mAccess Rancher from the IP above - Password is admin!\033[0m"
|
echo -e " \033[32;5mAccess Rancher from the IP above - Password is admin!\033[0m"
|
||||||
|
|
||||||
|
# Update Kube Config with VIP IP
|
||||||
|
sudo cat /etc/rancher/rke2/rke2.yaml | sed 's/'$master1'/'$vip'/g' > /etc/rancher/rke2/rke2.yaml
|
||||||
|
|
Loading…
Reference in New Issue