From e2bd24e0e2ddc61132e63b0d1af5a82c3a2cd7ed Mon Sep 17 00:00:00 2001 From: Matthias Theuermann Date: Fri, 9 Feb 2024 19:25:05 +0100 Subject: [PATCH] fix: setup of nomad and consul with dapr working --- .../hashicorp/components/barista_pubsub.yaml | 13 ++++ .../hashicorp/components/consul.yml | 14 ++++ .../hashicorp/components/daprConfig.yaml | 26 ++++++++ .../hashicorp/components/kitchen_pubsub.yaml | 13 ++++ .../hashicorp/components/orderup_pubsub.yaml | 13 ++++ .../hashicorp/local/install-consule.sh | 0 .../hashicorp/local/install-nomad-consul.sh | 18 ++++- .../hashicorp/local/install-nomad.sh | 18 ++++- .../hashicorp/local/start-mac.sh | 65 ------------------- 9 files changed, 113 insertions(+), 67 deletions(-) create mode 100644 dapr-distributed-calendar/hashicorp/components/barista_pubsub.yaml create mode 100644 dapr-distributed-calendar/hashicorp/components/consul.yml create mode 100644 dapr-distributed-calendar/hashicorp/components/daprConfig.yaml create mode 100644 dapr-distributed-calendar/hashicorp/components/kitchen_pubsub.yaml create mode 100644 dapr-distributed-calendar/hashicorp/components/orderup_pubsub.yaml mode change 100644 => 100755 dapr-distributed-calendar/hashicorp/local/install-consule.sh mode change 100644 => 100755 dapr-distributed-calendar/hashicorp/local/install-nomad-consul.sh mode change 100644 => 100755 dapr-distributed-calendar/hashicorp/local/install-nomad.sh delete mode 100755 dapr-distributed-calendar/hashicorp/local/start-mac.sh diff --git a/dapr-distributed-calendar/hashicorp/components/barista_pubsub.yaml b/dapr-distributed-calendar/hashicorp/components/barista_pubsub.yaml new file mode 100644 index 0000000..1bf5aa6 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/components/barista_pubsub.yaml @@ -0,0 +1,13 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: baristapubsub + namespace: default +spec: + type: pubsub.redis + version: v1 + metadata: + - name: redisHost + value: redis:6379 + - name: redisPassword + value: "" \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/components/consul.yml b/dapr-distributed-calendar/hashicorp/components/consul.yml new file mode 100644 index 0000000..e2cb06a --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/components/consul.yml @@ -0,0 +1,14 @@ + +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: consul + namespace: default +spec: + type: state.consul + version: v1 + metadata: + - name: datacenter + value: dc1 # Required. Example: dc1 + - name: httpAddr + value: 127.0.0.1:8500 # TODO update here 10.1.0.4:8500 # Required. Example: "consul.default.svc.cluster.local:8500" \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/components/daprConfig.yaml b/dapr-distributed-calendar/hashicorp/components/daprConfig.yaml new file mode 100644 index 0000000..e06aea5 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/components/daprConfig.yaml @@ -0,0 +1,26 @@ + +apiVersion: dapr.io/v1alpha1 +kind: Configuration +metadata: + name: daprConfig +spec: + nameResolution: + component: "consul" + configuration: + selfRegister: true + client: + address: "127.0.0.1:8500" # TODO: update here "10.1.0.4:8500" # Required. Example: "consul.default.svc.cluster.local:8500" + checks: + - name: "Dapr Health Status" + checkID: "daprHealth: - ${APP_ID} - ${CONSUL_HTTP_ADDR}" + interval: "15s" + tcp: "127.0.0.1:8500" # TODO: update here "10.1.0.4:8500" # Required. Example: "consul.default.svc.cluster.local:8500" + tags: + - "dapr" + queryOptions: + useCache: true + filter: "Checks.ServiceTags contains dapr" + tracing: + samplingRate: "1" + zipkin: + endpointAddress: http://127.0.0.1:9411/api/v2/spans \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/components/kitchen_pubsub.yaml b/dapr-distributed-calendar/hashicorp/components/kitchen_pubsub.yaml new file mode 100644 index 0000000..f853359 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/components/kitchen_pubsub.yaml @@ -0,0 +1,13 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: kitchenpubsub + namespace: default +spec: + type: pubsub.redis + version: v1 + metadata: + - name: redisHost + value: redis:6379 + - name: redisPassword + value: "" \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/components/orderup_pubsub.yaml b/dapr-distributed-calendar/hashicorp/components/orderup_pubsub.yaml new file mode 100644 index 0000000..ea56d21 --- /dev/null +++ b/dapr-distributed-calendar/hashicorp/components/orderup_pubsub.yaml @@ -0,0 +1,13 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: orderuppubsub + namespace: default +spec: + type: pubsub.redis + version: v1 + metadata: + - name: redisHost + value: redis:6379 + - name: redisPassword + value: "" \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/local/install-consule.sh b/dapr-distributed-calendar/hashicorp/local/install-consule.sh old mode 100644 new mode 100755 diff --git a/dapr-distributed-calendar/hashicorp/local/install-nomad-consul.sh b/dapr-distributed-calendar/hashicorp/local/install-nomad-consul.sh old mode 100644 new mode 100755 index b05adf3..2e3c7f0 --- a/dapr-distributed-calendar/hashicorp/local/install-nomad-consul.sh +++ b/dapr-distributed-calendar/hashicorp/local/install-nomad-consul.sh @@ -3,4 +3,20 @@ sudo apt-get update && sudo apt-get install wget gpg coreutils wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt-get update && sudo apt-get install nomad -sudo apt update && sudo apt install consul \ No newline at end of file +sudo apt update && sudo apt install consul + +# fix plugin error for working with consul +cd +curl -L -o cni-plugins.tgz "https://github.com/containernetworking/plugins/releases/download/v1.0.0/cni-plugins-linux-$( [ $(uname -m) = aarch64 ] && echo arm64 || echo amd64)"-v1.0.0.tgz +sudo mkdir -p /opt/cni/bin +sudo tar -C /opt/cni/bin -xzf cni-plugins.tgz + +echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-arptables +echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-ip6tables +echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-iptables + +cd /etc/sysctl.d/ && sudo touch 10-bridge-nf-call-iptables.conf +echo "net.bridge.bridge-nf-call-arptables = 1" | sudo tee /etc/sysctl.d/10-bridge-nf-call-iptables.conf +echo "net.bridge.bridge-nf-call-ip6tables = 1" | sudo tee -a /etc/sysctl.d/10-bridge-nf-call-iptables.conf +echo "net.bridge.bridge-nf-call-iptables = 1" | sudo tee -a /etc/sysctl.d/10-bridge-nf-call-iptables.conf +sudo sysctl --system \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/local/install-nomad.sh b/dapr-distributed-calendar/hashicorp/local/install-nomad.sh old mode 100644 new mode 100755 index 5e6ad8e..0f6b1e7 --- a/dapr-distributed-calendar/hashicorp/local/install-nomad.sh +++ b/dapr-distributed-calendar/hashicorp/local/install-nomad.sh @@ -2,4 +2,20 @@ sudo apt-get update && sudo apt-get install wget gpg coreutils wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list -sudo apt-get update && sudo apt-get install nomad \ No newline at end of file +sudo apt-get update && sudo apt-get install nomad + +# fix plugin error for working with consul +cd +curl -L -o cni-plugins.tgz "https://github.com/containernetworking/plugins/releases/download/v1.0.0/cni-plugins-linux-$( [ $(uname -m) = aarch64 ] && echo arm64 || echo amd64)"-v1.0.0.tgz +sudo mkdir -p /opt/cni/bin +sudo tar -C /opt/cni/bin -xzf cni-plugins.tgz + +echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-arptables +echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-ip6tables +echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-iptables + +cd /etc/sysctl.d/ && sudo touch 10-bridge-nf-call-iptables.conf +echo "net.bridge.bridge-nf-call-arptables = 1" | sudo tee /etc/sysctl.d/10-bridge-nf-call-iptables.conf +echo "net.bridge.bridge-nf-call-ip6tables = 1" | sudo tee -a /etc/sysctl.d/10-bridge-nf-call-iptables.conf +echo "net.bridge.bridge-nf-call-iptables = 1" | sudo tee -a /etc/sysctl.d/10-bridge-nf-call-iptables.conf +sudo sysctl --system \ No newline at end of file diff --git a/dapr-distributed-calendar/hashicorp/local/start-mac.sh b/dapr-distributed-calendar/hashicorp/local/start-mac.sh deleted file mode 100755 index 80e77fc..0000000 --- a/dapr-distributed-calendar/hashicorp/local/start-mac.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -require() { - if ! hash "$1" &>/dev/null; then - echo "'$1' not found in PATH" - exit 1 - fi -} - -require consul -require nomad - -cleanup() { - echo - echo "Shutting down services" - kill $(jobs -p) - wait -} -trap cleanup EXIT - -# https://github.com/deislabs/hippo/blob/de73ae52d606c0a2351f90069e96acea831281bc/src/Infrastructure/Jobs/NomadJob.cs#L28 -# https://www.nomadproject.io/docs/drivers/exec#client-requirements -case "$OSTYPE" in - linux*) SUDO="sudo --preserve-env=PATH" ;; - *) SUDO= ;; -esac - -# change to the directory of this script -cd "$(dirname "${BASH_SOURCE[0]}")" - -${SUDO} rm -rf ./data -mkdir -p log - -IP_ADDRESS=$(ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}') - -echo "Starting consul..." -consul agent -dev \ - -config-file ./etc/consul.hcl \ - -bootstrap-expect 1 \ - -client '0.0.0.0' \ - -bind "${IP_ADDRESS}" \ - &>log/consul.log & - -echo "Waiting for consul..." -while ! consul members &>/dev/null; do - sleep 2 -done - -echo "Starting nomad..." -${SUDO} nomad agent -dev \ - -config ./etc/nomad.hcl \ - -network-interface en0 \ - -consul-address "${IP_ADDRESS}:8500" \ - &>log/nomad.log & - -echo "Waiting for nomad..." -while ! nomad server members 2>/dev/null | grep -q alive; do - sleep 2 -done - -echo -echo "Done!!!" - -wait \ No newline at end of file