Skip to content

Commit a810132

Browse files
add helm-chart with samples (#603)
1 parent c516188 commit a810132

18 files changed

+667
-1
lines changed

charts/filed/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
charts/

charts/filed/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

charts/filed/Chart.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: elasticsearch
3+
repository: oci://registry-1.docker.io/bitnamicharts
4+
version: 19.18.0
5+
digest: sha256:759bc43df1848f8586a2f99f2c36c57bf685ef6f0f42c4679e288f7f8b913edc
6+
generated: "2024-03-19T19:55:51.969713998+07:00"

charts/filed/Chart.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: v2
2+
name: filed
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "v0.24.0"
25+
26+
dependencies:
27+
- name: elasticsearch
28+
version: "19.18.0"
29+
repository: "oci://registry-1.docker.io/bitnamicharts"
30+
condition: elasticsearch.enabled

charts/filed/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Helm Chart
2+
3+
Install [Helm](https://helm.sh/docs/intro/install/)
4+
5+
```shell
6+
cd charts/filed
7+
8+
helm dependency update
9+
```
10+
11+
## Examples for Minikube Minikube
12+
13+
Install [Minikube](https://minikube.sigs.k8s.io/docs/start/)
14+
15+
### Install collectors and storage for k8s-logs
16+
17+
```shell
18+
helm upgrade --install k8s-logs . -f values.minikube.k8s-logs.yaml
19+
20+
kubectl create clusterrolebinding k8s-logs-filed --clusterrole=cluster-admin --serviceaccount=default:k8s-logs-filed
21+
22+
kubectl port-forward svc/k8s-logs-elasticsearch 9200:9200
23+
24+
curl -X GET "http://localhost:9200/k8s-logs/_search/?size=10" -H 'Content-Type: application/json' -d '{
25+
"query": {
26+
"match": {
27+
"k8s_namespace": "ingress-nginx"
28+
}
29+
}
30+
}'
31+
```
32+
33+
### Collect logs from Web
34+
35+
```shell
36+
helm upgrade --install web-logs . -f values.minikube.web-logs.yaml
37+
38+
curl --resolve "web-logs.local:80:$( minikube ip )" -H 'Content-Type: application/json' http://web-logs.local -d \
39+
'{"message": "Test event", "level": "info"}'
40+
41+
kubectl port-forward svc/web-logs-elasticsearch 9201:9200
42+
43+
curl -X GET "http://localhost:9201/web-logs-filed/_search/?size=10" -H 'Content-Type: application/json' -d '{
44+
"sort": [
45+
{"time": {"order":"desc"}}
46+
]
47+
}'
48+
```
49+
50+
## TODO
51+
52+
- [ ] export metrics
53+
- [ ] basics prometheus rules
54+
- [ ] throttle with redis limiter_backend

charts/filed/templates/NOTES.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1. Watch all containers come up.
2+
$ kubectl get pods --namespace={{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "filed.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -w
3+
{{ if .Values.ingress.enabled }}
4+
2. Get the application URL by running these commands:
5+
{{- range $host := .Values.ingress.hosts }}
6+
{{- range .paths }}
7+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
8+
{{- end }}
9+
{{- end }}
10+
{{- end }}

charts/filed/templates/_helpers.tpl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "filed.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "filed.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "filed.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "filed.labels" -}}
37+
helm.sh/chart: {{ include "filed.chart" . }}
38+
{{ include "filed.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "filed.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "filed.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "filed.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "filed.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}

charts/filed/templates/app.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
apiVersion: apps/v1
2+
kind: {{ .Values.resourceType }}
3+
metadata:
4+
name: {{ include "filed.fullname" . }}
5+
labels:
6+
{{- include "filed.labels" . | nindent 4 }}
7+
spec:
8+
{{- if eq "Deployment" .Values.resourceType }}
9+
replicas: {{ .Values.replicas }}
10+
strategy:
11+
type: RollingUpdate
12+
rollingUpdate:
13+
maxSurge: 25%
14+
maxUnavailable: 25%
15+
{{- end }}
16+
selector:
17+
matchLabels:
18+
{{- include "filed.selectorLabels" . | nindent 6 }}
19+
template:
20+
metadata:
21+
annotations:
22+
{{- with .Values.podAnnotations }}
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
25+
checksum/config: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum }}
26+
labels:
27+
{{- include "filed.labels" . | nindent 8 }}
28+
{{- with .Values.podLabels }}
29+
{{- toYaml . | nindent 8 }}
30+
{{- end }}
31+
spec:
32+
{{- with .Values.imagePullSecrets }}
33+
imagePullSecrets:
34+
{{- toYaml . | nindent 8 }}
35+
{{- end }}
36+
serviceAccountName: {{ include "filed.serviceAccountName" . }}
37+
securityContext:
38+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
39+
containers:
40+
- name: {{ .Chart.Name }}
41+
securityContext:
42+
{{- toYaml .Values.securityContext | nindent 12 }}
43+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
44+
imagePullPolicy: {{ .Values.image.pullPolicy }}
45+
command:
46+
- /file.d/file.d
47+
- --config=/config/file.d.yaml
48+
ports:
49+
- name: http
50+
containerPort: {{ .Values.service.port }}
51+
protocol: TCP
52+
- name: metrics
53+
containerPort: 9000
54+
protocol: TCP
55+
resources:
56+
{{- toYaml .Values.resources | nindent 12 }}
57+
volumeMounts:
58+
- name: "{{ template "filed.fullname" . }}-config"
59+
mountPath: "/config"
60+
readOnly: true
61+
{{- with .Values.volumeMounts }}
62+
{{- toYaml . | nindent 12 }}
63+
{{- end }}
64+
volumes:
65+
- name: {{ template "filed.fullname" . }}-config
66+
configMap:
67+
name: {{ template "filed.fullname" . }}-config
68+
{{- with .Values.volumes }}
69+
{{- toYaml . | nindent 8 }}
70+
{{- end }}
71+
{{- with .Values.nodeSelector }}
72+
nodeSelector:
73+
{{- toYaml . | nindent 8 }}
74+
{{- end }}
75+
{{- with .Values.affinity }}
76+
affinity:
77+
{{- toYaml . | nindent 8 }}
78+
{{- end }}
79+
{{- with .Values.tolerations }}
80+
tolerations:
81+
{{- toYaml . | nindent 8 }}
82+
{{- end }}

charts/filed/templates/configmap.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ template "filed.fullname" . }}-config
5+
labels:
6+
app: "{{ template "filed.fullname" . }}"
7+
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
8+
heritage: {{ .Release.Service | quote }}
9+
release: {{ .Release.Name | quote }}
10+
data:
11+
file.d.yaml: |
12+
pipelines:
13+
{{ .Release.Name | replace "-" "_" }}:
14+
input:
15+
{{- toYaml .Values.input | nindent 10 }}
16+
actions:
17+
{{- if .Values.actions }}
18+
{{- toYaml .Values.actions | nindent 8 }}
19+
{{- end }}
20+
output:
21+
{{- if .Values.elasticsearch.enabled }}
22+
type: elasticsearch
23+
index_format: {{ template "filed.fullname" . }}
24+
endpoints:
25+
- http://{{ .Release.Name }}-elasticsearch.{{ .Release.Namespace }}.svc.cluster.local.:9200
26+
{{- end }}
27+
{{- if .Values.output }}
28+
{{- toYaml .Values.output | nindent 10 }}
29+
{{- end }}

charts/filed/templates/hpa.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if and (.Values.autoscaling.enabled) (eq "Deployment" .Values.resourceType) }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "filed.fullname" . }}
6+
labels:
7+
{{- include "filed.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "filed.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
23+
{{- end }}
24+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
31+
{{- end }}
32+
{{- end }}

0 commit comments

Comments
 (0)