diff --git a/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/cleanup-controller-new.sh b/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/cleanup-controller-new.sh new file mode 100644 index 00000000..e09ecdd6 --- /dev/null +++ b/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/cleanup-controller-new.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +DIR_PREFIX=$1 + +sudo kubeadm reset --force + +# Clean up azdata-cli package. +# +sudo dpkg --remove --force-all azdata-cli + +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/ + +sudo ip link set cni0 down +#brctl delbr cni0 +sudo ip link set flannel.1 down +#brctl delbr flannel.1 +sudo iptables -F && sudo iptables -t nat -F && sudo iptables -t mangle -F && sudo iptables -X + +sudo rm -rf .azdata/ + +# Remove mounts. +# +SERVICE_STOP_FAILED=0 + +sudo systemctl | grep "/var/lib/kubelet/pods" | while read -r line; do + + # Retrieve the mount path + # + MOUNT_PATH=`echo "$line" | grep -v echo | egrep -oh -m 1 "(/var/lib/kubelet/pods).+"` + + if [ -z "$MOUNT_PATH" ]; then + continue + fi + + if [[ ! -d "$MOUNT_PATH" ]] && [[ ! -f "$MOUNT_PATH" ]]; then + + SERVICE=$(echo $line | cut -f1 -d' ') + + echo "Mount "$MOUNT_PATH" no longer exists." + echo "Stopping orphaned mount service: '$SERVICE'" + + sudo systemctl stop $SERVICE + + if [ $? -ne 0 ]; then + SERVICE_STOP_FAILED=1 + fi + + echo "" + fi +done + +if [ $SERVICE_STOP_FAILED -ne 0 ]; then + echo "Not all services were stopped successfully. Please check the above output for more inforamtion." +else + echo "All orphaned services successfully stopped." +fi + +# Clean the mounted volumes. +# + +for i in $(seq 1 80); do + + vol="vol$i" + + sudo umount /azurearc/local-storage/$vol + + sudo rm -rf /azurearc/local-storage/$vol + +done + +# Reset kube +# +sudo apt-get purge -y kubeadm --allow-change-held-packages +sudo apt-get purge -y kubectl --allow-change-held-packages +sudo apt-get purge -y kubelet --allow-change-held-packages +sudo apt-get purge -y kubernetes-cni --allow-change-held-packages +sudo apt-get purge -y kube* --allow-change-held-packages +sudo apt -y autoremove +sudo rm -rf ~/.kube + +# Clean up working folders. +# +export AZUREARCDATACONTROLLER_DIR=aadatacontroller +if [ -d "$AZUREARCDATACONTROLLER_DIR" ]; then + echo "Removing working directory $AZUREARCDATACONTROLLER_DIR." + rm -f -r $AZUREARCDATACONTROLLER_DIR +fi diff --git a/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/setup-controller-new.sh b/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/setup-controller-new.sh new file mode 100644 index 00000000..6435ad03 --- /dev/null +++ b/samples/features/azure-arc/deployment/kubeadm/ubuntu-single-node-vm/setup-controller-new.sh @@ -0,0 +1,362 @@ +#!/bin/bash + +# Get controller username and password as input. It is used as default for the controller. +# +if [ -z "$AZDATA_USERNAME" ] +then + read -p "Create Username for Azure Arc Data Controller: " username + echo + export AZDATA_USERNAME=$username +fi +if [ -z "$AZDATA_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 AZDATA_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 + + +# Propmpt for Arc Data Controller properties. +# +if [ -z "$ARC_DC_NAME" ] +then + read -p "Enter a name for the new Azure Arc Data Controller: " dc_name + echo + export ARC_DC_NAME=$dc_name +fi + +if [ -z "$ARC_DC_SUBSCRIPTION" ] +then + read -p "Enter a subscription ID for the new Azure Arc Data Controller: " dc_subscription + echo + export ARC_DC_SUBSCRIPTION=$dc_subscription +fi + +if [ -z "$ARC_DC_RG" ] +then + read -p "Enter a resource group for the new Azure Arc Data Controller: " dc_rg + echo + export ARC_DC_RG=$dc_rg +fi + +if [ -z "$ARC_DC_REGION" ] +then + read -p "Enter a region for the new Azure Arc Data Controller (eastus, eastus2, centralus, westus2, westeurope or southeastasia): " dc_region + echo + export ARC_DC_REGION=$dc_region +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=arc-data + +# Name of virtualenv variable used. +# +export LOG_FILE="arc-data-controller.log" +export DEBIAN_FRONTEND=noninteractive + +# Requirements file. +export OSCODENAME=$(lsb_release -cs) +export AZDATA_PRIVATE_PREVIEW_DEB_PACKAGE="https://aka.ms/jul-2020-arc-azdata-$OSCODENAME" + +# Kube version. +# +KUBE_DPKG_VERSION=1.16.3-00 +KUBE_VERSION=1.16.3 + +# Wait for 5 minutes for the cluster to be ready. +# +TIMEOUT=600 +RETRY_INTERVAL=5 + +# Variables used for azdata cluster creation. +# +export ACCEPT_EULA=yes +export CLUSTER_NAME=arc +export PV_COUNT="100" + +# Make a directory for installing the scripts and logs. +# +rm -f -r $AZUREARCDATACONTROLLER_DIR +mkdir -p $AZUREARCDATACONTROLLER_DIR +cd $AZUREARCDATACONTROLLER_DIR/ +touch $LOG_FILE + +{ +# Install all necessary packages: kuberenetes, docker, request, azdata. +# +echo "" +echo "######################################################################################" +echo "Starting installing packages..." + +# Install docker. +# +sudo apt-get update -q + +sudo apt --yes install \ + software-properties-common \ + apt-transport-https \ + ca-certificates \ + curl + +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + +sudo add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + +sudo apt update -q +sudo apt-get install -q --yes docker-ce=18.06.2~ce~3-0~ubuntu --allow-downgrades +sudo apt-mark hold docker-ce + +sudo usermod --append --groups docker $USER + +# Create working directory +# +rm -f -r setupscript +mkdir -p setupscript +cd setupscript/ + +# Download and install azdata prerequisites +# +sudo apt install -y libodbc1 odbcinst odbcinst1debian2 unixodbc apt-transport-https libkrb5-dev + +# Download and install azdata package +# +echo "" + +if [[ -v AZDATA_DEB_PACKAGE_PATH ]]; then + sudo dpkg -i $AZDATA_DEB_PACKAGE_PATH +elif [[ -v AZDATA_DEB_PACKAGE_URL ]]; then + echo "Downloading azdata installer from" $AZDATA_DEB_PACKAGE_URL + curl --location $AZDATA_DEB_PACKAGE_URL --output azdata_setup.deb + sudo dpkg -i azdata_setup.deb +else + echo "Downloading azdata installer from" $AZDATA_PRIVATE_PREVIEW_DEB_PACKAGE + curl --location $AZDATA_PRIVATE_PREVIEW_DEB_PACKAGE --output azdata_setup.deb + sudo dpkg -i azdata_setup.deb +fi + +cd - + +azdata --version +echo "Azdata has been successfully installed." + +# Install Azure CLI +# +#curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash + +# Load all pre-requisites for Kubernetes. +# +echo "###########################################################################" +echo "Starting to setup pre-requisites for kubernetes..." + +# Setup the kubernetes preprequisites. +# +sudo swapoff -a +sudo sed -i '/swap/s/^\(.*\)$/#\1/g' /etc/fstab + +curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - + +cat <