Skip to content

Commit

Permalink
Add kafka consumer Helm deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
utr1903 committed Feb 1, 2024
1 parent 04fd5fe commit f1c826d
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker_build_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
description: Name of the application
options:
- httpserver
- kafkaconsumer

jobs:
docker_build:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/helm_deploy_application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
description: Name of the application
options:
- httpserver
- kafkaconsumer

jobs:
helm_deploy:
Expand Down
3 changes: 3 additions & 0 deletions infra/helm/kafkaconsumer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Kafka consumer

To be implemented...
23 changes: 23 additions & 0 deletions infra/helm/kafkaconsumer/chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions infra/helm/kafkaconsumer/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: kafkaconsumer
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.1.0"
62 changes: 62 additions & 0 deletions infra/helm/kafkaconsumer/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.name }}
namespace: {{ .Release.Namespace }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ .Values.name }}
template:
metadata:
labels:
app: {{ .Values.name }}
spec:
containers:
- name: {{ .Values.name }}
image: {{ .Values.imageName }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
env:
- name: K8S_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: APP_NAME
value: {{ .Values.name }}
- name: KAFKA_BROKER_ADDRESS
value: {{ .Values.kafka.address }}
- name: KAFKA_TOPIC
value: {{ .Values.kafka.topic }}
- name: KAFKA_CONSUMER_GROUP_ID
value: {{ .Values.kafka.groupId }}
- name: MYSQL_SERVER
value: {{ .Values.mysql.server }}
- name: MYSQL_USERNAME
value: {{ .Values.mysql.username }}
- name: MYSQL_PASSWORD
value: {{ .Values.mysql.password }}
- name: MYSQL_PORT
value: "{{ .Values.mysql.port }}"
- name: MYSQL_DATABASE
value: {{ .Values.mysql.database }}
- name: MYSQL_TABLE
value: {{ .Values.mysql.table }}
- name: OTEL_SERVICE_NAME
value: {{ .Values.name }}
- name: OTEL_RESOURCE_ATTRIBUTES
value: service.name=$(OTEL_SERVICE_NAME),service.instance.id=$(K8S_POD_NAME)
- name: OTEL_EXPORTER_TYPE
value: {{ .Values.otel.exporter }}
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.otlp.endpoint }}
- name: OTEL_EXPORTER_OTLP_HEADERS
value: {{ .Values.otlp.headers }}
resources:
requests:
cpu: {{ .Values.resources.requests.cpu }}
memory: {{ .Values.resources.requests.memory }}
limits:
cpu: {{ .Values.resources.limits.cpu }}
memory: {{ .Values.resources.limits.memory }}
57 changes: 57 additions & 0 deletions infra/helm/kafkaconsumer/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
### Variables

# Name
name: kafkaconsumer

# Replicas
replicas: 1

# Resources
resources:
# Requests
requests:
# CPU
cpu: 20m
# Memory
memory: 50Mi
# Limits
limits:
# CPU
cpu: 800m
# Memory
memory: 1000Mi

# OTel
otel:
exporter: "stdout"

# OTLP
otlp:
# Endpoint
endpoint: "https://otlp.nr-data.net:4317"
# Headers
headers: ""

# Kafka
kafka:
# Address
address: "kafka.otel.svc.cluster.local:9092"
# Topic
topic: "otel"
# Consumer group ID
groupId: "kafkaconsumer"

# MySQL
mysql:
# Server path
server: ""
# Username
username: "root"
# Password
password: ""
# Port
port: 3306
# Database
database: ""
# Table
table: ""
112 changes: 112 additions & 0 deletions infra/helm/kafkaconsumer/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash

# Get commandline arguments
while (( "$#" )); do
case "$1" in
--project)
project="${2}"
shift
;;
--instance)
instance="${2}"
shift
;;
--application)
application="${2}"
shift
;;
--language)
language="${2}"
shift
;;
*)
shift
;;
esac
done

### Check input

# Project
if [[ $project == "" ]]; then
echo -e "Project [--project] is not provided!\n"
exit 1
fi

# Instance
if [[ $instance == "" ]]; then
echo -e "Instance [--instance] is not provided!\n"
exit 1
fi

# Application
if [[ $application == "" ]]; then
echo -e "Application [--application] is not provided!\n"
exit 1
fi

# Language
if [[ $language == "" ]]; then
echo -e "Language [--language] is not provided!\n"
exit 1
fi

### Set variables

# kafka
declare -A kafka
kafka["name"]="kafka"
kafka["namespace"]="ops"
kafka["topic"]="${language}"

# mysql
declare -A mysql
mysql["name"]="mysql"
mysql["namespace"]="ops"
mysql["username"]="root"
mysql["password"]="verysecretpassword"
mysql["port"]=3306
mysql["database"]="otel"
mysql["table"]="${language}"

# otelcollectors
declare -A otelcollectors
otelcollectors["name"]="nrotelk8s"
otelcollectors["namespace"]="ops"
otelcollectors["endpoint"]="http://${otelcollectors[name]}-dep-rec-collector-headless.${otelcollectors[namespace]}.svc.cluster.local:4317"

# kafkaconsumer
declare -A kafkaconsumer
kafkaconsumer["name"]="kafkaconsumer"
kafkaconsumer["imageName"]="ghcr.io/utr1903/${project}-${kafkaconsumer[name]}-${language}:latest"
kafkaconsumer["namespace"]="${language}"
kafkaconsumer["replicas"]=2

###################
### Deploy Helm ###
###################

# kafkaconsumer
helm upgrade ${kafkaconsumer[name]} \
--install \
--wait \
--debug \
--create-namespace \
--namespace=${kafkaconsumer[namespace]} \
--set dockerhubName=$DOCKERHUB_NAME \
--set imageName=${kafkaconsumer[imageName]} \
--set imagePullPolicy="Always" \
--set name=${kafkaconsumer[name]} \
--set replicas=${kafkaconsumer[replicas]} \
--set kafka.address="${kafka[name]}.${kafka[namespace]}.svc.cluster.local:9092" \
--set kafka.topic=${kafka[topic]} \
--set kafka.groupId=${kafkaconsumer[name]} \
--set mysql.server="${mysql[name]}.${mysql[namespace]}.svc.cluster.local" \
--set mysql.username=${mysql[username]} \
--set mysql.password=${mysql[password]} \
--set mysql.port=${mysql[port]} \
--set mysql.database=${mysql[database]} \
--set mysql.table=${mysql[table]} \
--set otel.exporter="otlp" \
--set otlp.endpoint="${otelcollectors[endpoint]}" \
"./infra/helm/${application}/chart"

0 comments on commit f1c826d

Please sign in to comment.