From fdaa0e67b502c644085948fc7392422c8443bdf3 Mon Sep 17 00:00:00 2001 From: Bastian Krol Date: Mon, 5 Feb 2024 12:11:32 +0100 Subject: [PATCH] [dash0] scripts for deploying the otel demo to k8s locally Either deploy to one namespace or to two different namespaces (just to make the deployment topology a bit more "interesting"). --- .licenserc.json | 6 +- kubernetes/local/.gitignore | 3 + kubernetes/local/README.md | 4 ++ .../local/cross-namespace-service-names.yaml | 57 +++++++++++++++++++ kubernetes/local/dash0-one-ns.yq | 2 + kubernetes/local/deploy-two-namespaces.sh | 26 +++++++++ kubernetes/local/deploy.sh | 28 +++++++++ kubernetes/local/ns1.yq | 29 ++++++++++ kubernetes/local/ns2.yq | 34 +++++++++++ .../postgres-service-two-namespaces.yaml | 15 +++++ kubernetes/local/postgres-service.yaml | 15 +++++ kubernetes/local/postgres-values.yaml | 6 ++ kubernetes/local/teardown.sh | 21 +++++++ 13 files changed, 243 insertions(+), 3 deletions(-) create mode 100644 kubernetes/local/.gitignore create mode 100644 kubernetes/local/README.md create mode 100644 kubernetes/local/cross-namespace-service-names.yaml create mode 100644 kubernetes/local/dash0-one-ns.yq create mode 100755 kubernetes/local/deploy-two-namespaces.sh create mode 100755 kubernetes/local/deploy.sh create mode 100644 kubernetes/local/ns1.yq create mode 100644 kubernetes/local/ns2.yq create mode 100644 kubernetes/local/postgres-service-two-namespaces.yaml create mode 100644 kubernetes/local/postgres-service.yaml create mode 100644 kubernetes/local/postgres-values.yaml create mode 100755 kubernetes/local/teardown.sh diff --git a/.licenserc.json b/.licenserc.json index 27a16f1ef8..55e6c5c332 100644 --- a/.licenserc.json +++ b/.licenserc.json @@ -46,7 +46,7 @@ "src/featureflagservice/priv/", "src/productcatalogservice/genproto/", "internal/tools/", - ".github/actions/deploy-demo/action.yaml", - ".github/actions/update-env-file/action.yaml" + ".github/actions/", + "kubernetes/local/" ] - } \ No newline at end of file + } diff --git a/kubernetes/local/.gitignore b/kubernetes/local/.gitignore new file mode 100644 index 0000000000..98aa33181f --- /dev/null +++ b/kubernetes/local/.gitignore @@ -0,0 +1,3 @@ +dash0-values.yaml +ns1-values.yaml +ns2-values.yaml diff --git a/kubernetes/local/README.md b/kubernetes/local/README.md new file mode 100644 index 0000000000..54fd7c6089 --- /dev/null +++ b/kubernetes/local/README.md @@ -0,0 +1,4 @@ +Helper Scripts to Deploy the Dash0 fork of the OpenTelemetry Demo to Kubernetes Locally +======================================================================================= + +See . diff --git a/kubernetes/local/cross-namespace-service-names.yaml b/kubernetes/local/cross-namespace-service-names.yaml new file mode 100644 index 0000000000..222173da14 --- /dev/null +++ b/kubernetes/local/cross-namespace-service-names.yaml @@ -0,0 +1,57 @@ +apiVersion: v1 +kind: Service +metadata: + name: opentelemetry-demo-in-ns2-emailservice + namespace: otel-demo-ns1 +spec: + type: ExternalName + externalName: opentelemetry-demo-ns2-emailservice.otel-demo-ns2.svc.cluster.local + ports: + - port: 8080 +--- +apiVersion: v1 +kind: Service +metadata: + name: opentelemetry-demo-in-ns2-paymentservice + namespace: otel-demo-ns1 +spec: + type: ExternalName + externalName: opentelemetry-demo-ns2-paymentservice.otel-demo-ns2.svc.cluster.local + ports: + - port: 8080 +--- +apiVersion: v1 +kind: Service +metadata: + name: opentelemetry-demo-in-ns2-shippingservice + namespace: otel-demo-ns1 +spec: + type: ExternalName + externalName: opentelemetry-demo-ns2-shippingservice.otel-demo-ns2.svc.cluster.local + ports: + - port: 8080 +--- +apiVersion: v1 +kind: Service +metadata: + name: opentelemetry-demo-in-ns1-featureflagservice + namespace: otel-demo-ns2 +spec: + type: ExternalName + externalName: opentelemetry-demo-ns1-featureflagservice.otel-demo-ns1.svc.cluster.local + ports: + - name: grpc + port: 50053 + - name: http + port: 8081 +--- +apiVersion: v1 +kind: Service +metadata: + name: opentelemetry-demo-in-ns1-quoteservice + namespace: otel-demo-ns2 +spec: + type: ExternalName + externalName: opentelemetry-demo-ns1-quoteservice.otel-demo-ns1.svc.cluster.local + ports: + - port: 8080 diff --git a/kubernetes/local/dash0-one-ns.yq b/kubernetes/local/dash0-one-ns.yq new file mode 100644 index 0000000000..3c7339c9b5 --- /dev/null +++ b/kubernetes/local/dash0-one-ns.yq @@ -0,0 +1,2 @@ +.otelDemo.helm | +.default.image.pullSecrets=[{"name": "regcred"}] diff --git a/kubernetes/local/deploy-two-namespaces.sh b/kubernetes/local/deploy-two-namespaces.sh new file mode 100755 index 0000000000..dcae6348de --- /dev/null +++ b/kubernetes/local/deploy-two-namespaces.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd -P -- "$(dirname -- "$0")" + +./teardown.sh + +sleep 5 + +yq --from-file ns1.yq ../../../dash0-configuration/demo/environments/aws/demo-eu-west-1-demo.yaml > ns1-values.yaml +yq --from-file ns2.yq ../../../dash0-configuration/demo/environments/aws/demo-eu-west-1-demo.yaml > ns2-values.yaml + +helm install --namespace otel-demo-ns1 --create-namespace opentelemetry-demo-postgresql oci://registry-1.docker.io/bitnamicharts/postgresql --values postgres-values.yaml +helm install --namespace otel-demo-ns1 --create-namespace opentelemetry-demo-ns1 open-telemetry/opentelemetry-demo --values ns1-values.yaml +helm install --namespace otel-demo-ns2 --create-namespace opentelemetry-demo-ns2 open-telemetry/opentelemetry-demo --values ns2-values.yaml +kubectl apply -f cross-namespace-service-names.yaml +kubectl apply --namespace otel-demo-ns1 -f postgres-service-two-namespaces.yaml + +kubectl cp ../../src/ffspostgres/init-scripts/10-ffs_schema.sql --namespace otel-demo-ns1 opentelemetry-demo-postgresql-0:/tmp/ +kubectl cp ../../src/ffspostgres/init-scripts/20-ffs_data.sql --namespace otel-demo-ns1 opentelemetry-demo-postgresql-0:/tmp/ +kubectl exec --namespace otel-demo-ns1 opentelemetry-demo-postgresql-0 -- psql postgresql://ffs:ffs@localhost/ffs -a -f /tmp/10-ffs_schema.sql +kubectl exec --namespace otel-demo-ns1 opentelemetry-demo-postgresql-0 -- psql postgresql://ffs:ffs@localhost/ffs -a -f /tmp/20-ffs_data.sql + +kubectl port-forward --namespace otel-demo-ns1 service/opentelemetry-demo-ns1-frontendproxy 8080:8080 + diff --git a/kubernetes/local/deploy.sh b/kubernetes/local/deploy.sh new file mode 100755 index 0000000000..34bf8b9d1c --- /dev/null +++ b/kubernetes/local/deploy.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd -P -- "$(dirname -- "$0")" + +./teardown.sh + +sleep 5 + +yq --from-file dash0-one-ns.yq ../../../dash0-configuration/demo/environments/aws/demo-eu-west-1-demo.yaml > dash0-values.yaml + +helm install --namespace otel-demo-ns --create-namespace opentelemetry-demo-postgresql oci://registry-1.docker.io/bitnamicharts/postgresql --values postgres-values.yaml +helm install \ + --namespace otel-demo-ns \ + --create-namespace \ + opentelemetry-demo \ + open-telemetry/opentelemetry-demo \ + --values dash0-values.yaml +kubectl apply --namespace otel-demo-ns -f postgres-service.yaml + +kubectl cp ../../src/ffspostgres/init-scripts/10-ffs_schema.sql --namespace otel-demo-ns opentelemetry-demo-postgresql-0:/tmp/ +kubectl cp ../../src/ffspostgres/init-scripts/20-ffs_data.sql --namespace otel-demo-ns opentelemetry-demo-postgresql-0:/tmp/ +kubectl exec --namespace otel-demo-ns opentelemetry-demo-postgresql-0 -- psql postgresql://ffs:ffs@localhost/ffs -a -f /tmp/10-ffs_schema.sql +kubectl exec --namespace otel-demo-ns opentelemetry-demo-postgresql-0 -- psql postgresql://ffs:ffs@localhost/ffs -a -f /tmp/20-ffs_data.sql + +kubectl port-forward --namespace otel-demo-ns service/opentelemetry-demo-frontendproxy 8080:8080 + diff --git a/kubernetes/local/ns1.yq b/kubernetes/local/ns1.yq new file mode 100644 index 0000000000..0a77a30c41 --- /dev/null +++ b/kubernetes/local/ns1.yq @@ -0,0 +1,29 @@ +.otelDemo.helm | +.default.image.pullSecrets=[{"name": "regcred"}] | +del(.default.envOverrides) | +.components.ffsPostgres.enabled=false | +.components.accountingService.enabled=true | +.components.adService.enabled=true | +.components.cartService.enabled=true | +.components.checkoutService.enabled=true | +.components.currencyService.enabled=true | +.components.emailService.enabled=true | +.components.cartService.enabled=true | +.components.checkoutService.enabled=true | +.components.checkoutService.envOverrides=[ +{ "name": "FEATURE_FLAG_GRPC_SERVICE_ADDR", "value": "opentelemetry-demo-featureflagservice:50053" }, { "name": "EMAIL_SERVICE_ADDR", "value": "http://opentelemetry-demo-in-ns2-emailservice:8080" }, { "name": "PAYMENT_SERVICE_ADDR", "value": "opentelemetry-demo-in-ns2-paymentservice:8080" }, {"name": "SHIPPING_SERVICE_ADDR", "value": "opentelemetry-demo-in-ns2-shippingservice:8080" } ] | +.components.currencyService.enabled=true | +.components.emailService.enabled=false | +.components.featureflagService.enabled=true | +.components.frauddetectionService.enabled=true | +.components.frontend.enabled=true | +.components.frontend.envOverrides=[{ "name": "SHIPPING_SERVICE_ADDR", "value": "opentelemetry-demo-in-ns2-shippingservice:8080" } ] | +.components.frontendProxy.enabled=true | +.components.kafka.enabled=true | +.components.loadgenerator.enabled=true | +.components.paymentService.enabled=false | +.components.productCatalogService.enabled=true | +.components.quoteService.enabled=true | +.components.recommendationService.enabled=true | +.components.redis.enabled=true | +.components.shippingService.enabled=false diff --git a/kubernetes/local/ns2.yq b/kubernetes/local/ns2.yq new file mode 100644 index 0000000000..519a9e16ab --- /dev/null +++ b/kubernetes/local/ns2.yq @@ -0,0 +1,34 @@ +.otelDemo.helm | +del(.prometheus) | +.default.image.pullSecrets=[{"name": "regcred"}] | +del(.default.envOverrides) | +.components.ffsPostgres.enabled=false | +.components.accountingService.enabled=false | +.components.adService.enabled=false | +.components.cartService.enabled=false | +.components.checkoutService.enabled=false | +.components.currencyService.enabled=false | +.components.emailService.enabled=false | +.components.cartService.enabled=false | +.components.checkoutService.enabled=false | +.components.currencyService.enabled=false | +.components.emailService.enabled=true | +.components.featureflagService.enabled=false | +.components.frauddetectionService.enabled=false | +.components.frontend.enabled=false | +.components.frontendProxy.enabled=false | +.components.kafka.enabled=false | +.components.loadgenerator.enabled=false | +.components.paymentService.enabled=true | +.components.paymentService.envOverrides=[{ "name": "FEATURE_FLAG_GRPC_SERVICE_ADDR", "value": "opentelemetry-demo-in-ns1-featureflagservice:50053" } ] | +.components.productCatalogService.enabled=false | +.components.quoteService.enabled=false | +.components.recommendationService.enabled=false | +.components.redis.enabled=false | +.components.shippingService.enabled=true | +.components.shippingService.envOverrides=[{ "name": "FEATURE_FLAG_GRPC_SERVICE_ADDR", "value": "opentelemetry-demo-in-ns1-featureflagservice:50053" }, { "name": "QUOTE_SERVICE_ADDR", "value": "http://opentelemetry-demo-in-ns1-quoteservice:8080" }] | +del(.grafana) | +.jaeger.enabled=false | +.prometheus.enabled=false | +.grafana.enabled=false + diff --git a/kubernetes/local/postgres-service-two-namespaces.yaml b/kubernetes/local/postgres-service-two-namespaces.yaml new file mode 100644 index 0000000000..fd167d1694 --- /dev/null +++ b/kubernetes/local/postgres-service-two-namespaces.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: opentelemetry-demo-ns1-ffspostgres +spec: + ports: + - name: tcp-postgresql + port: 5432 + protocol: TCP + targetPort: tcp-postgresql + selector: + app.kubernetes.io/component: primary + app.kubernetes.io/instance: opentelemetry-demo-postgresql + app.kubernetes.io/name: postgresql + type: ClusterIP diff --git a/kubernetes/local/postgres-service.yaml b/kubernetes/local/postgres-service.yaml new file mode 100644 index 0000000000..0bfd860cf2 --- /dev/null +++ b/kubernetes/local/postgres-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: opentelemetry-demo-ffspostgres +spec: + ports: + - name: tcp-postgresql + port: 5432 + protocol: TCP + targetPort: tcp-postgresql + selector: + app.kubernetes.io/component: primary + app.kubernetes.io/instance: opentelemetry-demo-postgresql + app.kubernetes.io/name: postgresql + type: ClusterIP diff --git a/kubernetes/local/postgres-values.yaml b/kubernetes/local/postgres-values.yaml new file mode 100644 index 0000000000..5f833baa6f --- /dev/null +++ b/kubernetes/local/postgres-values.yaml @@ -0,0 +1,6 @@ +global: + postgresql: + auth: + username: "ffs" + password: "ffs" + database: "ffs" diff --git a/kubernetes/local/teardown.sh b/kubernetes/local/teardown.sh new file mode 100755 index 0000000000..f0e51103a5 --- /dev/null +++ b/kubernetes/local/teardown.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd -P -- "$(dirname -- "$0")" + +pwd + +# tear down things installed by deploy.sh +helm uninstall --namespace otel-demo-ns --ignore-not-found opentelemetry-demo-postgresql +helm uninstall --namespace otel-demo-ns --ignore-not-found opentelemetry-demo +kubectl delete --namespace otel-demo-ns --ignore-not-found -f postgres-service.yaml +kubectl delete --namespace otel-demo-ns --ignore-not-found -f postgres-service-two-namespaces.yaml + +# tear down things installed by deploy-two-namespaces.sh +helm uninstall --namespace otel-demo-ns1 --ignore-not-found opentelemetry-demo-ns1 +helm uninstall --namespace otel-demo-ns2 --ignore-not-found opentelemetry-demo-ns2 +helm uninstall --namespace otel-demo-ns1 --ignore-not-found opentelemetry-demo-postgresql +kubectl delete --namespace otel-demo-ns1 --ignore-not-found -f postgres-service.yaml +kubectl delete --ignore-not-found -f cross-namespace-service-names.yaml +