From 5da696cb7f98f0db2d8caba4796f176b0481978c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adnan=20Rahi=C4=87?= Date: Tue, 3 Sep 2024 12:36:26 +0200 Subject: [PATCH] Add simplified Helm chart with a guide (#43) * k8s: added basic manifest files * fix postgres manifest * cleanup * add tt agent * simplify manifests * add readme * improve readme * add port env * delete kompose file * added deps to helm chart * remove stream simplify chart --------- Co-authored-by: Matheus Nogueira --- helm-chart/Chart.lock | 16 ++- helm-chart/Chart.yaml | 6 ++ helm-chart/readme.md | 27 +++++ helm-chart/templates/deployment.yaml | 23 +--- helm-chart/templates/service.yaml | 4 + helm-chart/templates/stream.deployment.yaml | 68 ------------ helm-chart/templates/stream.service.yaml | 20 ---- helm-chart/values.yaml | 113 +++++++++++++++++--- k8s/readme.md | 3 +- 9 files changed, 156 insertions(+), 124 deletions(-) create mode 100644 helm-chart/readme.md delete mode 100644 helm-chart/templates/stream.deployment.yaml delete mode 100644 helm-chart/templates/stream.service.yaml diff --git a/helm-chart/Chart.lock b/helm-chart/Chart.lock index 0c90569..8327e0c 100644 --- a/helm-chart/Chart.lock +++ b/helm-chart/Chart.lock @@ -1,12 +1,18 @@ dependencies: - name: postgresql repository: https://charts.bitnami.com/bitnami - version: 11.1.19 + version: 12.1.6 - name: rabbitmq repository: https://charts.bitnami.com/bitnami - version: 8.30.0 + version: 11.2.2 - name: redis repository: https://charts.bitnami.com/bitnami - version: 16.8.5 -digest: sha256:7cba0f80b53fc0f7da7cf6402dd131cbfbeab5d7615feb26a005f3f861277195 -generated: "2022-04-15T14:45:15.128266901-03:00" + version: 17.3.17 +- name: opentelemetry-collector + repository: https://open-telemetry.github.io/opentelemetry-helm-charts + version: 0.92.0 +- name: jaeger + repository: https://jaegertracing.github.io/helm-charts + version: 3.0.10 +digest: sha256:3004524c4ef3f6cb0d3b04bd4f652b239ff0f0ffb73b39ae96c89f71d7221591 +generated: "2024-08-28T14:20:10.713465+02:00" diff --git a/helm-chart/Chart.yaml b/helm-chart/Chart.yaml index 055ee07..6f28614 100644 --- a/helm-chart/Chart.yaml +++ b/helm-chart/Chart.yaml @@ -33,3 +33,9 @@ dependencies: - name: redis version: 17.3.17 repository: https://charts.bitnami.com/bitnami + - name: opentelemetry-collector + version: 0.92.0 + repository: https://open-telemetry.github.io/opentelemetry-helm-charts + - name: jaeger + version: 3.0.10 + repository: https://jaegertracing.github.io/helm-charts diff --git a/helm-chart/readme.md b/helm-chart/readme.md new file mode 100644 index 0000000..afe32e8 --- /dev/null +++ b/helm-chart/readme.md @@ -0,0 +1,27 @@ +# Install Pokeshop with Helm + +1. Update Helm dependencies + + ```bash + helm dependency update + ``` + +2. Install the Helm chart + + ```bash + helm install -f ./values.yaml pokeshop . + ``` + +3. [Get your Tracetest API key and env id](https://app.tracetest.io/retrieve-token) +4. Install Tracetest Agent + + ```bash + helm repo add tracetestcloud https://kubeshop.github.io/tracetest-cloud-charts --force-update && helm install agent tracetestcloud/tracetest-agent --set agent.apiKey= --set agent.environmentId= + ``` + +5. Create and run a test by going to [`app.tracetest.io`](https://app.tracetest.io) and using the internal Kubernetes service networking: + + - **POST** `http://pokeshop-pokemon-api:8081/pokemon/import` - Body: `{ "id": 1 }` + - **GET** `http://pokeshop-pokemon-api:8081/pokemon` + + ![](https://res.cloudinary.com/djwdcmwdz/image/upload/v1725358889/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_4b0e8945dbe5045a_test_Q6Mr5o3Ig_run_24_trigger_agj1ls.png) diff --git a/helm-chart/templates/deployment.yaml b/helm-chart/templates/deployment.yaml index e32cb3c..23c8f5c 100644 --- a/helm-chart/templates/deployment.yaml +++ b/helm-chart/templates/deployment.yaml @@ -1,4 +1,6 @@ {{- $rpcPort := .Values.service.rpcPort -}} +{{- $httpPort := .Values.service.httpPort -}} +{{- $port := .Values.service.port -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -36,7 +38,7 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http - containerPort: 80 + containerPort: {{ $httpPort }} protocol: TCP resources: {{- toYaml .Values.resources | nindent 12 }} @@ -79,23 +81,8 @@ spec: value: rpc - name: SERVICE_NAME value: pokeshop - {{- toYaml .Values.env | nindent 12 }} - - name: {{ .Chart.Name }}-stream-worker - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - ports: - - name: http - containerPort: 80 - protocol: TCP - resources: - {{- toYaml .Values.resources | nindent 12 }} - env: - - name: NPM_RUN_COMMAND - value: stream-worker - - name: SERVICE_NAME - value: pokeshop-stream-worker + - name: RPC_PORT + value: "8082" {{- toYaml .Values.env | nindent 12 }} {{- with .Values.nodeSelector }} nodeSelector: diff --git a/helm-chart/templates/service.yaml b/helm-chart/templates/service.yaml index 767f942..5c9a949 100644 --- a/helm-chart/templates/service.yaml +++ b/helm-chart/templates/service.yaml @@ -8,6 +8,10 @@ spec: type: {{ .Values.service.type }} ports: - port: {{ .Values.service.port }} + targetPort: 80 + protocol: TCP + name: ingress + - port: {{ .Values.service.httpPort }} targetPort: 8081 protocol: TCP name: http diff --git a/helm-chart/templates/stream.deployment.yaml b/helm-chart/templates/stream.deployment.yaml deleted file mode 100644 index 56c0c5d..0000000 --- a/helm-chart/templates/stream.deployment.yaml +++ /dev/null @@ -1,68 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "pokemon-api.fullname" . }}-stream - labels: - {{- include "pokemon-api.labels" . | nindent 4 }} -spec: - {{- if not .Values.autoscaling.enabled }} - replicas: {{ .Values.replicaCount }} - {{- end }} - selector: - matchLabels: - {{- include "pokemon-api.selectorLabelsStream" . | nindent 6 }} - template: - metadata: - {{- with .Values.podAnnotations }} - annotations: - {{- toYaml . | nindent 8 }} - {{- end }} - labels: - {{- include "pokemon-api.selectorLabelsStream" . | nindent 8 }} - spec: - containers: - - name: {{ .Chart.Name }}-stream - image: "confluentinc/cp-kafka:latest-ubi8" - imagePullPolicy: IfNotPresent - ports: - - containerPort: 9092 - name: plaintext - protocol: TCP - - containerPort: 9093 - name: controller - protocol: TCP - resources: - {{- toYaml .Values.kafka.resources | nindent 12 }} - env: - - name: KAFKA_ADVERTISED_LISTENERS - value: PLAINTEXT://stream.{{ .Release.Namespace }}:9092 - - name: KAFKA_LISTENERS - value: PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093 - - name: KAFKA_CONTROLLER_QUORUM_VOTERS - value: 1@0.0.0.0:9093 - - name: KAFKA_CONTROLLER_LISTENER_NAMES - value: CONTROLLER - - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP - value: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT - - name: KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS - value: "0" - - name: KAFKA_PROCESS_ROLES - value: controller,broker - - name: KAFKA_NODE_ID - value: "1" - - name: KAFKA_METADATA_LOG_SEGMENT_MS - value: "15000" - - name: KAFKA_METADATA_MAX_RETENTION_MS - value: "60000" - - name: KAFKA_METADATA_LOG_MAX_RECORD_BYTES_BETWEEN_SNAPSHOTS - value: "2800" - - name: KAFKA_AUTO_CREATE_TOPICS_ENABLE - value: "true" - - name: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR - value: "1" - - name: KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR - value: "1" - - name: KAFKA_HEAP_OPTS - value: -Xmx200m -Xms200m - - name: CLUSTER_ID - value: ckjPoprWQzOf0-FuNkGfFQ \ No newline at end of file diff --git a/helm-chart/templates/stream.service.yaml b/helm-chart/templates/stream.service.yaml deleted file mode 100644 index 7b4e0a7..0000000 --- a/helm-chart/templates/stream.service.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: stream - labels: - {{- include "pokemon-api.labels" . | nindent 4 }} -spec: - type: ClusterIP - ports: - - name: plaintext - port: 9092 - protocol: TCP - targetPort: 9092 - - name: controller - port: 9093 - protocol: TCP - targetPort: 9093 - - selector: - {{- include "pokemon-api.selectorLabelsStream" . | nindent 4 }} diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index b30024a..fe2c619 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -6,29 +6,21 @@ replicaCount: 1 image: repository: kubeshop/demo-pokemon-api - pullPolicy: IfNotPresent + pullPolicy: Always # Overrides the image tag whose default is the chart appVersion. tag: latest env: + - name: COLLECTOR_ENDPOINT + value: http://pokeshop-opentelemetry-collector:44317 - name: DATABASE_URL value: postgresql://ashketchum:squirtle123@postgresql:5432/pokeshop?schema=public - name: REDIS_URL - value: redis-master + value: redis-headless - name: RABBITMQ_HOST value: guest:guest@rabbitmq-headless - name: POKE_API_BASE_URL value: https://pokeapi.co/api/v2 - - name: COLLECTOR_ENDPOINT - value: http://otel-collector.tracetest.svc.cluster.local:4317 - - name: ZIPKIN_URL - value: http://jaeger-agent.tracetest.svc.cluster.local:9411 - - name: KAFKA_BROKER - value: stream:9092 - - name: KAFKA_TOPIC - value: pokemon - - name: KAFKA_CLIENT_ID - value: streaming-worker imagePullSecrets: [] nameOverride: "" @@ -61,6 +53,7 @@ securityContext: service: type: ClusterIP port: 80 + httpPort: 8081 rpcPort: 8082 ingress: @@ -144,3 +137,99 @@ rabbitmq: requests: cpu: 400m memory: 512Mi + +opentelemetry-collector: + mode: deployment + + image: + repository: "otel/opentelemetry-collector-contrib" + + + ports: + otlp: + enabled: true + containerPort: 4317 + servicePort: 44317 + hostPort: 44317 + protocol: TCP + appProtocol: grpc + otlp-http: + enabled: true + containerPort: 4318 + servicePort: 44318 + hostPort: 44318 + protocol: TCP + jaeger-compact: + enabled: false + jaeger-thrift: + enabled: false + jaeger-grpc: + enabled: false + zipkin: + enabled: false + + config: + receivers: + otlp: + protocols: + http: + grpc: + + processors: + batch: + timeout: 5s + + exporters: + debug/noop: + verbosity: normal + sampling_initial: 0 + sampling_thereafter: 0 + + debug: + verbosity: detailed + + otlp/jaeger: + endpoint: pokeshop-jaeger-collector:4317 + tls: + insecure: true + + otlp/tracetest: + endpoint: agent-tracetest-agent:4317 + tls: + insecure: true + + service: + pipelines: + logs: + exporters: [debug/noop] + processors: [memory_limiter, batch] + receivers: [otlp] + metrics: + exporters: [debug/noop] + processors: [memory_limiter, batch] + receivers: [otlp,prometheus] + traces/jaeger: + receivers: [otlp] + processors: [batch] + exporters: [otlp/jaeger] + traces/tracetest: + receivers: [otlp] + processors: [batch] + exporters: [otlp/tracetest] + +jaeger: + enabled: true + provisionDataStore: + cassandra: false + allInOne: + enabled: true + + storage: + type: memory + + agent: + enabled: false + collector: + enabled: false + query: + enabled: false diff --git a/k8s/readme.md b/k8s/readme.md index c20fb20..2cd8114 100644 --- a/k8s/readme.md +++ b/k8s/readme.md @@ -7,6 +7,7 @@ ```bash kubectl apply -f . ``` + 4. Create and run a test by going to [`app.tracetest.io`](https://app.tracetest.io) and using the internal Kubernetes service networking: - **POST** `http://api.default.svc.cluster.local:8081/pokemon/import` - Body: `{ "id": 1 }` @@ -16,4 +17,4 @@ 5. View the trace and create test specs by going to the `Test` tab. - ![](https://res.cloudinary.com/djwdcmwdz/image/upload/v1724764098/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_4b0e8945dbe5045a_test_tTFZ453Ig_run_9_selectedSpan_bb8ba205b42a8619_1_xaxlbi.png) \ No newline at end of file + ![](https://res.cloudinary.com/djwdcmwdz/image/upload/v1724764098/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_4b0e8945dbe5045a_test_tTFZ453Ig_run_9_selectedSpan_bb8ba205b42a8619_1_xaxlbi.png)