Created
November 12, 2021 04:04
-
-
Save Vertiwell/2ee0dbb9808acce4a96754e98d639456 to your computer and use it in GitHub Desktop.
hashicorp_consul.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### Deploying Hashicorp Consul on Kubernetes for Debian/Ubuntu based OS | |
## Baseline Guide: https://learn.hashicorp.com/tutorials/consul/kubernetes-deployment-guide | |
# Type of Deployment: Helm | |
### Minimum Requirements ### | |
## Three Worker Node Cluster (Tested on K0s, K3s, K8s) | |
## A Storage Backend (Tested on Ceph, OpenEBS, Local, Longhorn) | |
# | |
## The following base packages are required: | |
# Helm, Package Manager | |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && \ | |
chmod 700 get_helm.sh && \ | |
./get_helm.sh && \ | |
# | |
### Installation ### | |
## Set Variables: | |
# Set a StorageClass (kubectl get sc) | |
STORAGE=longhorn | |
# Set a temporary directory to store files generated by this script | |
mkdir /tmp/consul && export TMPDIR=/tmp/consul && \ | |
# Install the Helm chart repo | |
helm repo add hashicorp https://helm.releases.hashicorp.com && helm repo update && \ | |
# Create custom values file for Consul (Used as backend storage) | |
# Helm Chart Values Consul: https://github.com/hashicorp/consul-helm/blob/master/values.yaml | |
cat <<EOF >${TMPDIR}/config.yaml | |
syncCatalog: | |
enabled: true | |
default: true | |
k8sAllowNamespaces: ['*'] | |
k8sDenyNamespaces: ['kube-system', 'kube-public'] | |
server: | |
resources: | |
requests: | |
memory: '512Mi' | |
cpu: '500m' | |
limits: | |
memory: '512Mi' | |
cpu: '500m' | |
storageClass: '$STORAGE' | |
storage: 2Gi | |
client: | |
resources: | |
requests: | |
memory: '512Mi' | |
cpu: '500m' | |
limits: | |
memory: '512Mi' | |
cpu: '500m' | |
ui: | |
enabled: true | |
connectInject: | |
enabled: true | |
default: false | |
controller: | |
enabled: true | |
EOF | |
helm install consul hashicorp/consul -f ${TMPDIR}/config.yaml --namespace consul --create-namespace && \ | |
# Wait until Consul is running | |
ROLLOUT_STATUS_CMD="kubectl rollout status -w --timeout=300s statefulset/consul-consul-server -n consul" | |
until $ROLLOUT_STATUS_CMD || [ $n -eq 300 ]; do | |
$ROLLOUT_STATUS_CMD | |
n=$((n + 1)) | |
sleep 5 | |
done | |
# Cleanup | |
rm -r /tmp/consul |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment