Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Distributed binary helm chart #1410

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ cmd/cortex/cortex
.pkg
.cache
images/
requirements.lock
*.tgz
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all test clean images protos exes
.PHONY: all test clean images protos exes generated helm
.DEFAULT_GOAL := all

# Boiler plate for bulding Docker containers.
Expand Down Expand Up @@ -185,3 +185,8 @@ prime-minikube: save-images
docker tag $$image_name:$(IMAGE_TAG) $$image_name:latest ; \
fi \
done

helm:
helm lint k8s/helm/cortex
helm dependency build k8s/helm/cortex
helm package k8s/helm/cortex
22 changes: 22 additions & 0 deletions k8s/helm/cortex/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
13 changes: 13 additions & 0 deletions k8s/helm/cortex/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: cortex
version: 0.0.1
appVersion: 0.0.1
kubeVersion: "^1.10.0-0"
description: "Cortex: A multitenant, horizontally scalable Prometheus as a Service."
home: https://github.com/cortexproject/
icon: https://github.com/cortexproject/cortex/blob/master/imgs/logo.png?raw=true
sources:
- https://github.com/cortexproject/cortex
maintainers:
- name: Cortex Maintainers
email: cortex-users@lists.cncf.io
engine: gotpl
3 changes: 3 additions & 0 deletions k8s/helm/cortex/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Verify the application is working by running these commands:
kubectl port-forward service/{{ include "cortex.fullname" . }} {{ .Values.service.port }}
curl http://127.0.0.1:{{ .Values.service.port }}/api/prom/api/v1/labels
43 changes: 43 additions & 0 deletions k8s/helm/cortex/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "cortex.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 "cortex.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 "cortex.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the name of the service account
*/}}
{{- define "cortex.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "cortex.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
45 changes: 45 additions & 0 deletions k8s/helm/cortex/templates/_service.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

{{- define "cortex.service" -}}
{{ $root := .root }}
{{ $role := .role}}
{{ $settings := .settings }}
apiVersion: v1
kind: Service
metadata:
name: {{ template "cortex.fullname" $root }}-{{ $role }}
labels:
app: {{ template "cortex.name" $root }}
chart: {{ template "cortex.chart" $root }}
release: {{ $root.Release.Name }}
heritage: {{ $root.Release.Service }}
{{- with $root.Values.service.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- toYaml $root.Values.service.annotations | nindent 4 }}
spec:
type: {{ $settings.serviceType }}
{{- if (and (eq $settings.serviceType "ClusterIP") (not (empty $settings.clusterIP))) }}
clusterIP: {{ $settings.clusterIP }}
{{- end }}
ports:
{{- if $settings.http_listen_port }}
- port: {{ $settings.http_listen_port }}
protocol: TCP
name: http-metrics
targetPort: http-metrics
{{- end }}
{{- if $settings.grpc_listen_port }}
- port: {{ $settings.grpc_listen_port }}
protocol: TCP
name: grpc
targetPort: grpc
{{- end }}
{{- if (and (eq $settings.serviceType "NodePort") (not (empty $settings.nodePort))) }}
nodePort: {{ $settings.nodePort }}
{{- end }}
selector:
app: {{ template "cortex.name" $root }}
release: {{ $root.Release.Name }}
role: {{ $role }}
{{- end -}}
96 changes: 96 additions & 0 deletions k8s/helm/cortex/templates/distributed-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{{ if .Values.distributedMode.enabled }}
{{ $root := . }}
{{ range $role, $settings := .Values.distributedMode.deployments }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "cortex.fullname" $root }}-{{$role}}
labels:
app: {{ template "cortex.name" $root }}
chart: {{ template "cortex.chart" $root }}
role: {{ $role }}
release: {{ $root.Release.Name }}
heritage: {{ $root.Release.Service }}
annotations:
{{- toYaml $root.Values.annotations | nindent 4 }}
spec:
podManagementPolicy: {{ $root.Values.podManagementPolicy }}
replicas: {{ $settings.replicas }}
selector:
matchLabels:
app: {{ template "cortex.name" $root }}
release: {{ $root.Release.Name }}
role: {{ $role }}
serviceName: {{ template "cortex.fullname" $root }}-headless
updateStrategy:
{{- toYaml $root.Values.updateStrategy | nindent 4 }}
template:
metadata:
labels:
app: {{ template "cortex.name" $root }}
name: {{ template "cortex.name" $root }}
role: {{ $role }}
release: {{ $root.Release.Name }}
{{- with $root.Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") $root | sha256sum }}
{{- with $root.Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ template "cortex.serviceAccountName" $root }}
{{- if $root.Values.priorityClassName }}
priorityClassName: {{ $root.Values.priorityClassName }}
{{- end }}
securityContext:
{{- toYaml $root.Values.securityContext | nindent 8 }}
containers:
- name: {{ $root.Chart.Name }}-{{ $role }}
image: "{{ $root.Values.image.repository }}:{{ $root.Values.image.tag }}"
imagePullPolicy: {{ $root.Values.image.pullPolicy }}
args:
- "-config.file=/etc/cortex/cortex.yaml"
{{- range $key, $value := $settings.extraArgs }}
- "-{{ $key }}={{ $value }}"
{{- end }}
volumeMounts:
- name: config
mountPath: /etc/cortex
ports:
{{- if $settings.http_listen_port }}
- name: http-metrics
containerPort: {{ $settings.http_listen_port }}
protocol: TCP
{{- end }}
{{- if $settings.grpc_listen_port }}
- name: grpc
containerPort: {{ $settings.grpc_listen_port }}
protocol: TCP
{{- end }}
livenessProbe:
{{- toYaml $root.Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml $root.Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml $settings.resources | nindent 12 }}
securityContext:
readOnlyRootFilesystem: true
env:
- name: JAEGER_AGENT_HOST
value: "{{ $root.Values.tracing.jaegerAgentHost }}"
nodeSelector:
{{- toYaml $root.nodeSelector | nindent 8 }}
affinity:
{{- toYaml $root.affinity | nindent 8 }}
tolerations:
{{- toYaml $root.tolerations | nindent 8 }}
terminationGracePeriodSeconds: {{ $settings.terminationGracePeriodSeconds | default "30" }}
volumes:
- name: config
secret:
secretName: {{ template "cortex.fullname" $root }}
{{- end }}
{{- end }}
17 changes: 17 additions & 0 deletions k8s/helm/cortex/templates/distributed-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ if .Values.distributedMode.enabled }}
{{ $root := . }}
{{ range $role, $settings := .Values.distributedMode.deployments }}
{{ if .enableService}}
---
{{ $context := dict "root" $root "role" $role "settings" $settings}}
{{ template "cortex.service" $context }}
{{- end }}
{{- end }}
{{ range $role, $settings := .Values.distributedMode.statefulsets }}
{{ if .enableService}}
---
{{ $context := dict "root" $root "role" $role "settings" $settings}}
{{ template "cortex.service" $context }}
{{- end }}
{{- end }}
{{- end }} #if .Values.distributedMode.enabled
120 changes: 120 additions & 0 deletions k8s/helm/cortex/templates/distributed-statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{{ if .Values.distributedMode.enabled }}
{{ $root := . }}
{{ range $role, $settings := .Values.distributedMode.statefulsets }}
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ template "cortex.fullname" $root }}-{{$role}}
labels:
app: {{ template "cortex.name" $root }}
chart: {{ template "cortex.chart" $root }}
role: {{ $role }}
release: {{ $root.Release.Name }}
heritage: {{ $root.Release.Service }}
annotations:
{{- toYaml $root.Values.annotations | nindent 4 }}
spec:
podManagementPolicy: {{ $root.Values.podManagementPolicy }}
replicas: {{ $settings.replicas }}
selector:
matchLabels:
app: {{ template "cortex.name" $root }}
release: {{ $root.Release.Name }}
role: {{ $role }}
serviceName: {{ template "cortex.fullname" $root }}-headless
updateStrategy:
{{- toYaml $root.Values.updateStrategy | nindent 4 }}
template:
metadata:
labels:
app: {{ template "cortex.name" $root }}
name: {{ template "cortex.name" $root }}
role: {{ $role }}
release: {{ $root.Release.Name }}
{{- with $root.Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") $root | sha256sum }}
{{- with $root.Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ template "cortex.serviceAccountName" $root }}
{{- if $root.Values.priorityClassName }}
priorityClassName: {{ $root.Values.priorityClassName }}
{{- end }}
securityContext:
{{- toYaml $root.Values.securityContext | nindent 8 }}
containers:
- name: {{ $root.Chart.Name }}-{{ $role }}
image: "{{ $root.Values.image.repository }}:{{ $root.Values.image.tag }}"
imagePullPolicy: {{ $root.Values.image.pullPolicy }}
args:
- "-config.file=/etc/cortex/cortex.yaml"
{{- range $key, $value := $settings.extraArgs }}
- "-{{ $key }}={{ $value }}"
{{- end }}
volumeMounts:
- name: config
mountPath: /etc/cortex
- name: storage
mountPath: "/data"
subPath: {{ $root.Values.persistence.subPath }}
ports:
{{- if $settings.http_listen_port }}
- name: http-metrics
containerPort: {{ $settings.http_listen_port }}
protocol: TCP
{{- end }}
{{- if $settings.grpc_listen_port }}
- name: grpc
containerPort: {{ $settings.grpc_listen_port }}
protocol: TCP
{{- end }}
livenessProbe:
{{- toYaml $root.Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml $root.Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml $settings.resources | nindent 12 }}
securityContext:
readOnlyRootFilesystem: true
env:
- name: JAEGER_AGENT_HOST
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be wrapped in an if like grafana/loki#621

value: "{{ $root.Values.tracing.jaegerAgentHost }}"
nodeSelector:
{{- toYaml $root.nodeSelector | nindent 8 }}
affinity:
{{- toYaml $root.affinity | nindent 8 }}
tolerations:
{{- toYaml $root.tolerations | nindent 8 }}
terminationGracePeriodSeconds: {{ $settings.terminationGracePeriodSeconds | default "30" }}
volumes:
- name: config
secret:
secretName: {{ template "cortex.fullname" $root }}
{{- if not $root.Values.persistence.enabled }}
- name: storage
emptyDir: {}
{{- else if $root.Values.persistence.existingClaim }}
- name: storage
persistentVolumeClaim:
claimName: {{ $root.Values.persistence.existingClaim }}
{{- else }}
volumeClaimTemplates:
- metadata:
name: storage
annotations:
{{- toYaml $root.Values.persistence.annotations | nindent 8 }}
spec:
accessModes:
{{- toYaml $root.Values.persistence.accessModes | nindent 8 }}
resources:
requests:
storage: {{ $root.Values.persistence.size | quote }}
storageClassName: {{ $root.Values.persistence.storageClassName }}
{{- end }}
{{- end }}
{{- end }}
Loading