From 6521782246a8d70292ddeaa75ec3828e6aae38a8 Mon Sep 17 00:00:00 2001 From: "Anton Antonov (TONY)" Date: Wed, 4 Dec 2019 15:38:12 -0800 Subject: [PATCH] Fixing bug bash bugs. --- .../kubeadm/ubuntu-single-node-vm/README.md | 27 +++++++-- .../cleanup-controller.sh | 32 +++++----- .../ubuntu-single-node-vm/setup-controller.sh | 58 ++++++++++++------- 3 files changed, 74 insertions(+), 43 deletions(-) diff --git a/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/README.md b/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/README.md index 42af86d9..70ff93a2 100644 --- a/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/README.md +++ b/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/README.md @@ -6,11 +6,11 @@ Using this sample bash script, you will deploy a single node Kubernetes cluster ## Pre-requisites 1. A vanilla Ubuntu 16.04 or 18.04 virtual or physical machine. All dependencies will be setup by the script. Using Azure Linux VMs is not yet supported. -1. Machine should have at least 8 CPUs, 64GB RAM and 100GB disk space. After installing the images you will be left with 50GB for data/logs across all components. +1. Machine should have at least 16 CPUs, 96GB RAM and 100GB disk space. After installing the images you will be left with 50GB for data/logs across all components. 1. Update existing packages using commands below to ensure that the OS image is up to date ``` bash -sudo apt update&&apt upgrade -y +sudo apt update&& sudo apt upgrade -y sudo systemctl reboot ``` @@ -34,14 +34,31 @@ curl --output setup-controller.sh https://raw.githubusercontent.com/ananto-msft/ chmod +x setup-controller.sh ``` -3. Run the script (make sure you are running with sudo) +3. Run the script ``` bash -sudo ./setup-controller.sh +./setup-controller.sh ``` -When prompted, provide your input for the password that will be used for all external endpoints: controller, SQL Server master and gateway. The password should be sufficiently complex based on existing rules for SQL Server password. The controller username is defaulted to *controlleradmin*. +When prompted, provide your input for the password that will be used for all external endpoints: controller, SQL Server master and gateway. The password should be sufficiently complex based on existing rules for SQL Server password. +In case the setup-controller.sh fails and does not complete successfully, you should first cleanup your enviroment using [cleanup-controller.sh](cleanup-controller.sh/) before redoing the deployment. ## Cleanup 1. The [cleanup-controller.sh](cleanup-controller.sh/) script is provided as convenience to reset the environment in case of errors. However, we recommend that you use a virtual machine for testing purposes and use the snapshot capability in your hyper-visor to rollback the virtual machine to a clean state. + +``` bash +curl --output setup-controller.sh https://raw.githubusercontent.com/ananto-msft/sql-server-samples/master/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/cleanup-controller.sh +``` + +2. Make the script executable + +``` bash +chmod +x cleanup-controller.sh +``` + +3. Run the script + +``` bash +./cleanup-controller.sh +``` diff --git a/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/cleanup-controller.sh b/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/cleanup-controller.sh index ec100756..b706f325 100644 --- a/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/cleanup-controller.sh +++ b/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/cleanup-controller.sh @@ -1,9 +1,5 @@ #!/bin/bash -if [ "$EUID" -ne 0 ] - then echo "Please run as root" - exit -fi DIR_PREFIX=$1 kubeadm reset --force @@ -11,29 +7,31 @@ kubeadm reset --force # Clean up azdata-cli package. # unalias azdata +unalias az sudo dpkg --remove --force-all azdata-cli +sudo dpkg --remove --force-all azure-cli -systemctl stop kubelet -rm -rf /var/lib/cni/ -rm -rf /var/lib/etcd/ -rm -rf /run/flannel/ -rm -rf /var/lib/kubelet/* -rm -rf /etc/cni/ -rm -rf /etc/kubernetes/ +sudo systemctl stop kubelet +sudo rm -rf /var/lib/cni/ +sudo rm -rf /var/lib/etcd/ +sudo rm -rf /run/flannel/ +sudo rm -rf /var/lib/kubelet/* +sudo rm -rf /etc/cni/ +sudo rm -rf /etc/kubernetes/ -ip link set cni0 down +sudo ip link set cni0 down #brctl delbr cni0 -ip link set flannel.1 down +sudo ip link set flannel.1 down #brctl delbr flannel.1 -iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X +sudo iptables -F && sudo iptables -t nat -F && sudo iptables -t mangle -F && sudo iptables -X -rm -rf .azdata/ +sudo rm -rf .azdata/ # Remove mounts. # SERVICE_STOP_FAILED=0 -systemctl | grep "/var/lib/kubelet/pods" | while read -r line; do +sudo systemctl | grep "/var/lib/kubelet/pods" | while read -r line; do # Retrieve the mount path # @@ -50,7 +48,7 @@ systemctl | grep "/var/lib/kubelet/pods" | while read -r line; do echo "Mount "$MOUNT_PATH" no longer exists." echo "Stopping orphaned mount service: '$SERVICE'" - systemctl stop $SERVICE + sudo systemctl stop $SERVICE if [ $? -ne 0 ]; then SERVICE_STOP_FAILED=1 diff --git a/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/setup-controller.sh b/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/setup-controller.sh index 04c80535..83e29ee5 100644 --- a/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/setup-controller.sh +++ b/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/setup-controller.sh @@ -1,21 +1,47 @@ #!/bin/bash + +# Get controller username and password as input. It is used as default for the controller. +# +if [ -z "$CONTROLLER_USERNAME" ] +then + read -p "Create Username for Azure Arc Data Controller: " username + echo + export CONTROLLER_USERNAME=$username +fi +if [ -z "$CONTROLLER_PASSWORD" ] +then + while true; do + read -s -p "Create Password for Azure Arc Data Controller: " password + echo + read -s -p "Confirm your Password: " password2 + echo + [ "$password" = "$password2" ] && break + echo "Password mismatch. Please try again." + done + export CONTROLLER_PASSWORD=$password +fi + +# Prompt for private preview repository username and password provided by Microsoft +# +if [ -z "$DOCKER_USERNAME" ] +then + read -p 'Enter Azure Arc Data Controller repo username provided by Microsoft:' AADC_USERNAME + echo + export DOCKER_USERNAME=$AADC_USERNAME +fi +if [ -z "$DOCKER_PASSWORD" ] +then + read -sp 'Enter Azure Arc Data Controller repo password provided by Microsoft:' AADC_PASSWORD + echo + export DOCKER_PASSWORD=$AADC_PASSWORD +fi + set -Eeuo pipefail # This is a script to create single-node Kubernetes cluster and deploy Azure Arc Data Controller on it. # export AZUREARCDATACONTROLLER_DIR=aadatacontroller -# Get password as input. It is used as default for controller, SQL Server Master instance (sa account). -# -while true; do - read -s -p "Create Password for Azure Arc Data Controller: " password - echo - read -s -p "Confirm your Password: " password2 - echo - [ "$password" = "$password2" ] && break - echo "Password mismatch. Please try again." -done - # Name of virtualenv variable used. # export LOG_FILE="aadatacontroller.log" @@ -37,9 +63,6 @@ RETRY_INTERVAL=5 # Variables used for azdata cluster creation. # -export CONTROLLER_USERNAME=controlleradmin -export CONTROLLER_PASSWORD=$password - export ACCEPT_EULA=yes export CLUSTER_NAME=azure-arc-system export PV_COUNT="40" @@ -79,13 +102,6 @@ sudo apt-mark hold docker-ce sudo usermod --append --groups docker $USER -# Prompt for private preview repository username and password provided by Microsoft -# -read -p 'Enter Azure Arc Data Controller repo username provided by Microsoft:' AADC_USERNAME -read -sp 'Enter Azure Arc Data Controller repo password provided by Microsoft:' AADC_PASSWORD -export DOCKER_USERNAME=$AADC_USERNAME -export DOCKER_PASSWORD=$AADC_PASSWORD - # Create working directory # rm -f -r setupscript