Skip to content

Commit

Permalink
add helm-chart with samples (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryRomanov authored Mar 26, 2024
1 parent c516188 commit a810132
Show file tree
Hide file tree
Showing 18 changed files with 667 additions and 1 deletion.
1 change: 1 addition & 0 deletions charts/filed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
charts/
23 changes: 23 additions & 0 deletions charts/filed/.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/
6 changes: 6 additions & 0 deletions charts/filed/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: elasticsearch
repository: oci://registry-1.docker.io/bitnamicharts
version: 19.18.0
digest: sha256:759bc43df1848f8586a2f99f2c36c57bf685ef6f0f42c4679e288f7f8b913edc
generated: "2024-03-19T19:55:51.969713998+07:00"
30 changes: 30 additions & 0 deletions charts/filed/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v2
name: filed
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: "v0.24.0"

dependencies:
- name: elasticsearch
version: "19.18.0"
repository: "oci://registry-1.docker.io/bitnamicharts"
condition: elasticsearch.enabled
54 changes: 54 additions & 0 deletions charts/filed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Helm Chart

Install [Helm](https://helm.sh/docs/intro/install/)

```shell
cd charts/filed

helm dependency update
```

## Examples for Minikube Minikube

Install [Minikube](https://minikube.sigs.k8s.io/docs/start/)

### Install collectors and storage for k8s-logs

```shell
helm upgrade --install k8s-logs . -f values.minikube.k8s-logs.yaml

kubectl create clusterrolebinding k8s-logs-filed --clusterrole=cluster-admin --serviceaccount=default:k8s-logs-filed

kubectl port-forward svc/k8s-logs-elasticsearch 9200:9200

curl -X GET "http://localhost:9200/k8s-logs/_search/?size=10" -H 'Content-Type: application/json' -d '{
"query": {
"match": {
"k8s_namespace": "ingress-nginx"
}
}
}'
```

### Collect logs from Web

```shell
helm upgrade --install web-logs . -f values.minikube.web-logs.yaml

curl --resolve "web-logs.local:80:$( minikube ip )" -H 'Content-Type: application/json' http://web-logs.local -d \
'{"message": "Test event", "level": "info"}'

kubectl port-forward svc/web-logs-elasticsearch 9201:9200

curl -X GET "http://localhost:9201/web-logs-filed/_search/?size=10" -H 'Content-Type: application/json' -d '{
"sort": [
{"time": {"order":"desc"}}
]
}'
```

## TODO

- [ ] export metrics
- [ ] basics prometheus rules
- [ ] throttle with redis limiter_backend
10 changes: 10 additions & 0 deletions charts/filed/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1. Watch all containers come up.
$ kubectl get pods --namespace={{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "filed.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -w
{{ if .Values.ingress.enabled }}
2. Get the application URL by running these commands:
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- end }}
62 changes: 62 additions & 0 deletions charts/filed/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "filed.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "filed.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "filed.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "filed.labels" -}}
helm.sh/chart: {{ include "filed.chart" . }}
{{ include "filed.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "filed.selectorLabels" -}}
app.kubernetes.io/name: {{ include "filed.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "filed.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "filed.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
82 changes: 82 additions & 0 deletions charts/filed/templates/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apiVersion: apps/v1
kind: {{ .Values.resourceType }}
metadata:
name: {{ include "filed.fullname" . }}
labels:
{{- include "filed.labels" . | nindent 4 }}
spec:
{{- if eq "Deployment" .Values.resourceType }}
replicas: {{ .Values.replicas }}
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
{{- end }}
selector:
matchLabels:
{{- include "filed.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
checksum/config: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum }}
labels:
{{- include "filed.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "filed.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /file.d/file.d
- --config=/config/file.d.yaml
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
- name: metrics
containerPort: 9000
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: "{{ template "filed.fullname" . }}-config"
mountPath: "/config"
readOnly: true
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
volumes:
- name: {{ template "filed.fullname" . }}-config
configMap:
name: {{ template "filed.fullname" . }}-config
{{- with .Values.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
29 changes: 29 additions & 0 deletions charts/filed/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "filed.fullname" . }}-config
labels:
app: "{{ template "filed.fullname" . }}"
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
data:
file.d.yaml: |
pipelines:
{{ .Release.Name | replace "-" "_" }}:
input:
{{- toYaml .Values.input | nindent 10 }}
actions:
{{- if .Values.actions }}
{{- toYaml .Values.actions | nindent 8 }}
{{- end }}
output:
{{- if .Values.elasticsearch.enabled }}
type: elasticsearch
index_format: {{ template "filed.fullname" . }}
endpoints:
- http://{{ .Release.Name }}-elasticsearch.{{ .Release.Namespace }}.svc.cluster.local.:9200
{{- end }}
{{- if .Values.output }}
{{- toYaml .Values.output | nindent 10 }}
{{- end }}
32 changes: 32 additions & 0 deletions charts/filed/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if and (.Values.autoscaling.enabled) (eq "Deployment" .Values.resourceType) }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "filed.fullname" . }}
labels:
{{- include "filed.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "filed.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Loading

0 comments on commit a810132

Please sign in to comment.