|
| 1 | +#!/bin/bash |
| 2 | +# Install a single node deployment of Stackable |
| 3 | + |
| 4 | +HOSTNAME=`/usr/bin/hostname -f` |
| 5 | +GPG_KEY_URL="https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xce45c7a0a3e41385acd4358916dd12f5c7a6d76a" |
| 6 | + |
| 7 | +# This is the list of currently supported operators for Stackable Quickstart |
| 8 | +# Don't edit this list unless you know what you're doing. If you get an error |
| 9 | +# that you're attempting to install an unsupported operator then check the |
| 10 | +# OPERATORS list for typos. |
| 11 | +ALLOWED_OPERATORS=(zookeeper kafka nifi spark) |
| 12 | + |
| 13 | +# Do you want to use the dev or release repository? |
| 14 | +REPO_TYPE=dev |
| 15 | + |
| 16 | +# List of operators to install |
| 17 | +OPERATORS=(zookeeper kafka nifi spark) |
| 18 | + |
| 19 | +function install_prereqs { |
| 20 | + . /etc/os-release |
| 21 | + |
| 22 | + if [ "$ID" = "centos" ] || [ "$ID" = "redhat" ]; then |
| 23 | + if [ "$VERSION" = "8" ] || [ "$VERSION" = "7" ]; then |
| 24 | + echo "$ID $VERSION found" |
| 25 | + REPO_URL="https://repo.stackable.tech/repository/rpm-${REPO_TYPE}/el${VERSION}" |
| 26 | + install_prereqs_redhat |
| 27 | + else |
| 28 | + echo "Only Redhat/CentOS 7 & 8 are supported. This host is running $VERSION." |
| 29 | + fi |
| 30 | + elif [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then |
| 31 | + REPO_URL="https://repo.stackable.tech/repository/deb-${REPO_TYPE}" |
| 32 | + install_prereqs_debian |
| 33 | + fi |
| 34 | +} |
| 35 | + |
| 36 | +function install_prereqs_redhat { |
| 37 | + /usr/bin/echo "Installing Stackable YUM repo" |
| 38 | + |
| 39 | + if [ -z $REPO_URL ]; then |
| 40 | + /usr/bin/echo "No YUM repo URL found, exiting." |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + |
| 44 | + # Download the Stackable GPG key used for package signing |
| 45 | + /usr/bin/yum -y install gnupg2 java-1.8.0-openjdk |
| 46 | + /usr/bin/curl -s "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xce45c7a0a3e41385acd4358916dd12f5c7a6d76a" > /etc/pki/rpm-gpg/RPM-GPG-KEY-stackable |
| 47 | + /usr/bin/rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-stackable |
| 48 | + |
| 49 | + # Create YUM repo configuration file |
| 50 | + # TODO: Enable GPG checking on Stackable repo |
| 51 | + /usr/bin/yum-config-manager --add-repo=$REPO_URL |
| 52 | + /usr/bin/yum clean all |
| 53 | +} |
| 54 | + |
| 55 | + |
| 56 | +function install_prereqs_debian { |
| 57 | + echo "Installing Stackable APT repo" |
| 58 | + |
| 59 | + if [ -z $REPO_URL ]; then |
| 60 | + /usr/bin/echo "No YUM repo URL found, exiting." |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + |
| 64 | + apt-get install gnupg openjdk-8-jdk -y |
| 65 | + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 16dd12f5c7a6d76a |
| 66 | + echo "deb $REPO_URL buster main" > /etc/apt/sources.list.d/stackable.list |
| 67 | + apt update |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | +function install_k8s { |
| 72 | + echo "Installing K8s" |
| 73 | + /usr/bin/curl -sfL https://get.k3s.io | /bin/sh - |
| 74 | + /usr/local/bin/kubectl cluster-info |
| 75 | + |
| 76 | + echo "Copying K8s configuration to /root/.kube/config" |
| 77 | + /usr/bin/mkdir -p /root/.kube |
| 78 | + /usr/bin/cp /etc/rancher/k3s/k3s.yaml /root/.kube/config |
| 79 | +} |
| 80 | + |
| 81 | +function install_crds { |
| 82 | + # TODO: Install the CRDs based on the list of operators to install |
| 83 | + echo "Installing Stackable CRDs" |
| 84 | + curl -s -S https://raw.githubusercontent.com/stackabletech/zookeeper-operator/main/deploy/crd/zookeepercluster.crd.yaml | kubectl apply -f - |
| 85 | + curl -s -S https://raw.githubusercontent.com/stackabletech/kafka-operator/main/deploy/crd/kafkacluster.crd.yaml | kubectl apply -f - |
| 86 | + curl -s -S https://raw.githubusercontent.com/stackabletech/spark-operator/main/deploy/crd/sparkcluster.crd.yaml | kubectl apply -f - |
| 87 | + curl -s -S https://raw.githubusercontent.com/stackabletech/spark-operator/main/deploy/crd/start.command.crd.yaml | kubectl apply -f - |
| 88 | + curl -s -S https://raw.githubusercontent.com/stackabletech/spark-operator/main/deploy/crd/stop.command.crd.yaml | kubectl apply -f - |
| 89 | + curl -s -S https://raw.githubusercontent.com/stackabletech/spark-operator/main/deploy/crd/restart.command.crd.yaml | kubectl apply -f - |
| 90 | + curl -s -S https://raw.githubusercontent.com/stackabletech/agent/main/deploy/crd/repository.crd.yaml | kubectl apply -f - |
| 91 | + curl -s -S https://raw.githubusercontent.com/stackabletech/nifi-operator/main/deploy/crd/nificluster.crd.yaml | kubectl apply -f - |
| 92 | +} |
| 93 | + |
| 94 | +function install_stackable_k8s_repo { |
| 95 | + echo Installing Stackable package repo |
| 96 | + cat <<EOF | kubectl apply -f - |
| 97 | +apiVersion: "stable.stackable.de/v1" |
| 98 | +kind: Repository |
| 99 | +metadata: |
| 100 | + name: stackablepublic |
| 101 | +spec: |
| 102 | + repo_type: StackableRepo |
| 103 | + properties: |
| 104 | + url: https://repo.stackable.tech/repository/packages/ |
| 105 | +EOF |
| 106 | +} |
| 107 | + |
| 108 | +function check_operator_list { |
| 109 | + for OPERATOR in ${OPERATORS[@]}; do |
| 110 | + if [[ ! " ${ALLOWED_OPERATORS[@]} " =~ " ${OPERATOR} " ]]; then |
| 111 | + echo "Operator $OPERATOR is not in the allowed operator list." |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | + done |
| 115 | + echo "List of operators checked" |
| 116 | +} |
| 117 | + |
| 118 | +function install_operator { |
| 119 | + operator=$1 |
| 120 | + |
| 121 | + if [ "$ID" == "redhat" ] || [ "$ID" == "centos" ]; then |
| 122 | + /usr/bin/yum -y install stackable |
| 123 | + fi |
| 124 | +} |
| 125 | + |
| 126 | +function install_stackable_operators { |
| 127 | + echo "Installing Stackable operators" |
| 128 | +# for OPERATOR in ${OPERATORS[@]}; do |
| 129 | +# install_operator($OPERATOR) |
| 130 | +# done |
| 131 | + |
| 132 | + apt install -y stackable-spark-operator-server stackable-zookeeper-operator-server stackable-kafka-operator-server stackable-nifi-operator-server |
| 133 | + systemctl enable stackable-spark-operator-server |
| 134 | + systemctl enable stackable-kafka-operator-server |
| 135 | + systemctl enable stackable-zookeeper-operator-server |
| 136 | + systemctl enable stackable-nifi-operator-server |
| 137 | + systemctl start stackable-spark-operator-server |
| 138 | + systemctl start stackable-kafka-operator-server |
| 139 | + systemctl start stackable-zookeeper-operator-server |
| 140 | + systemctl start stackable-nifi-operator-server |
| 141 | +} |
| 142 | + |
| 143 | +# MAIN |
| 144 | +# Check the list of operators to deploy against the allowed list |
| 145 | +check_operator_list |
| 146 | + |
| 147 | +# Install the prerequisite OS-dependant repos and packages |
| 148 | +install_prereqs |
| 149 | + |
| 150 | +# Install the K3s Kubernetes distribution |
| 151 | +install_k8s |
| 152 | +exit |
| 153 | + |
| 154 | +install_stackable_k8s_repo |
| 155 | +install_stackable_operators |
| 156 | + |
| 157 | +echo Installing Stackable agent |
| 158 | +apt install -y stackable-agent |
| 159 | +echo "--hostname=$HOSTNAME" > /etc/stackable/stackable-agent/agent.conf |
| 160 | +systemctl enable stackable-agent |
| 161 | +systemctl start stackable-agent |
| 162 | +kubectl certificate approve ${HOSTNAME}-tls |
| 163 | +kubectl get nodes |
| 164 | + |
| 165 | +echo Deploying Apache Zookeeper |
| 166 | +kubectl apply -f - <<EOF |
| 167 | +apiVersion: zookeeper.stackable.tech/v1 |
| 168 | +kind: ZookeeperCluster |
| 169 | +metadata: |
| 170 | + name: simple |
| 171 | +spec: |
| 172 | + version: 3.4.14 |
| 173 | + servers: |
| 174 | + selectors: |
| 175 | + default: |
| 176 | + selector: |
| 177 | + matchLabels: |
| 178 | + kubernetes.io/hostname: ${HOSTNAME} |
| 179 | + instances: 1 |
| 180 | + instancesPerNode: 1 |
| 181 | +EOF |
| 182 | + |
| 183 | +echo Deploying Apache Kafka |
| 184 | +kubectl apply -f - <<EOF |
| 185 | +apiVersion: kafka.stackable.tech/v1 |
| 186 | +kind: KafkaCluster |
| 187 | +metadata: |
| 188 | + name: simple |
| 189 | +spec: |
| 190 | + version: |
| 191 | + kafka_version: 2.8.0 |
| 192 | + zookeeperReference: |
| 193 | + namespace: default |
| 194 | + name: simple |
| 195 | + opaReference: |
| 196 | + namespace: default |
| 197 | + name: simple-opacluster |
| 198 | + brokers: |
| 199 | + selectors: |
| 200 | + default: |
| 201 | + selector: |
| 202 | + matchLabels: |
| 203 | + kubernetes.io/hostname: ${HOSTNAME} |
| 204 | + instances: 1 |
| 205 | + instancesPerNode: 1 |
| 206 | +EOF |
| 207 | + |
| 208 | +echo Deploying Apache Spark |
| 209 | +kubectl apply -f - <<EOF |
| 210 | +apiVersion: spark.stackable.tech/v1 |
| 211 | +kind: SparkCluster |
| 212 | +metadata: |
| 213 | + name: simple |
| 214 | +spec: |
| 215 | + version: "3.0.1" |
| 216 | + masters: |
| 217 | + selectors: |
| 218 | + default: |
| 219 | + selector: |
| 220 | + matchLabels: |
| 221 | + kubernetes.io/hostname: ${HOSTNAME} |
| 222 | + instances: 1 |
| 223 | + instancesPerNode: 1 |
| 224 | + config: |
| 225 | + masterPort: 7078 |
| 226 | + masterWebUiPort: 8081 |
| 227 | + workers: |
| 228 | + selectors: |
| 229 | + 2core2g: |
| 230 | + selector: |
| 231 | + matchLabels: |
| 232 | + kubernetes.io/hostname: ${HOSTNAME} |
| 233 | + instances: 1 |
| 234 | + instancesPerNode: 1 |
| 235 | + config: |
| 236 | + cores: 2 |
| 237 | + memory: "2g" |
| 238 | + workerPort: 3031 |
| 239 | + workerWebUiPort: 8083 |
| 240 | + historyServers: |
| 241 | + selectors: |
| 242 | + default: |
| 243 | + selector: |
| 244 | + matchLabels: |
| 245 | + kubernetes.io/hostname: ${HOSTNAME} |
| 246 | + instances: 1 |
| 247 | + instancesPerNode: 1 |
| 248 | + config: |
| 249 | + historyWebUiPort: 18081 |
| 250 | +EOF |
| 251 | + |
| 252 | +echo Deploying Apache Nifi |
| 253 | +kubectl apply -f - <<EOF |
| 254 | +apiVersion: nifi.stackable.tech/v1 |
| 255 | +kind: NifiCluster |
| 256 | +metadata: |
| 257 | + name: simple-nificluster |
| 258 | +spec: |
| 259 | + version: "1.13.2" |
| 260 | + zookeeperReference: |
| 261 | + name: simple |
| 262 | + namespace: default |
| 263 | + chroot: /nifi |
| 264 | + nodes: |
| 265 | + selectors: |
| 266 | + default: |
| 267 | + selector: |
| 268 | + matchLabels: |
| 269 | + kubernetes.io/hostname: ${HOSTNAME} |
| 270 | + instances: 1 |
| 271 | + instancesPerNode: 1 |
| 272 | + config: |
| 273 | + httpPort: 10000 |
| 274 | + nodeProtocolPort: 10443 |
| 275 | + nodeLoadBalancingPort: 6342 |
| 276 | +EOF |
| 277 | + |
| 278 | +# TODO: Create TLS certificate |
| 279 | +# TODO: Create Spark client configuration |
| 280 | +# TODO: Install Python |
| 281 | +# TODO: Write output to a log file an tidy up the user feedback |
| 282 | + |
| 283 | + |
| 284 | +# TODO: Install OpenLDAP and boostrap with default creds |
| 285 | +# kubectl create secret generic openldap --from-literal=adminpassword=adminpassword \ |
| 286 | +# --from-literal=users=user01,user02 \ |
| 287 | +# --from-literal=passwords=password01,password02 |
0 commit comments