Skip to content

Commit

Permalink
feat(*): add helm chart (#18)
Browse files Browse the repository at this point in the history
* feat(*): add helm chart

* fix(*): fix imageRepository

* fix(*): address comments

* fix(*): update priorityClassName
  • Loading branch information
Xinzhao Xu authored Dec 16, 2020
1 parent 4805a5b commit 7d5d41b
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 0 deletions.
23 changes: 23 additions & 0 deletions manifests/infra-mongo/.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 manifests/infra-mongo/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
appVersion: 4.0.3
description: A helm chart for mongo
name: infra-mongo
type: application
version: 4.0.3
10 changes: 10 additions & 0 deletions manifests/infra-mongo/templates/_capabilities.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{/*
Return the appropriate apiVersion for statefulset.
*/}}
{{- define "common.capabilities.statefulset.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}
{{- print "extensions/v1beta1" -}}
{{- else -}}
{{- print "apps/v1" -}}
{{- end -}}
{{- end -}}
7 changes: 7 additions & 0 deletions manifests/infra-mongo/templates/_images.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{/*
Return the proper image name
{{ include "common.images.image" ( dict "context" $ "repository" .Values.platformConfig.imageRepositoryRelease "imageRoot" .Values.image ) }}
*/}}
{{- define "common.images.image" -}}
{{- printf "%s/%s/%s:%s" .context.Values.platformConfig.imageRegistry .repository .imageRoot.name ( default .context.Chart.AppVersion .imageRoot.tag ) -}}
{{- end -}}
17 changes: 17 additions & 0 deletions manifests/infra-mongo/templates/_labels.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{/*
Kubernetes standard labels
*/}}
{{- define "common.labels.standard" -}}
helm.sh/chart: {{ include "common.names.chart" . }}
app.kubernetes.io/name: {{ include "common.names.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector
*/}}
{{- define "common.labels.matchLabels" -}}
app.kubernetes.io/name: {{ include "common.names.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
31 changes: 31 additions & 0 deletions manifests/infra-mongo/templates/_names.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "common.names.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "common.names.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | 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 "common.names.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 -}}
12 changes: 12 additions & 0 deletions manifests/infra-mongo/templates/_tplvalues.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{/*
Renders a value that contains template.
Usage:
{{ include "common.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $) }}
*/}}
{{- define "common.tplvalues.render" -}}
{{- if typeIs "string" .value }}
{{- tpl .value .context }}
{{- else }}
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end -}}
27 changes: 27 additions & 0 deletions manifests/infra-mongo/templates/pv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{- range $index, $value := tuple "kube-master-1" "kube-master-2" "kube-master-3" }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: infra-mongo-infra-mongo-{{ $index }}
spec:
capacity:
storage: 100Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
claimRef:
namespace: {{ $.Release.Namespace | quote }}
name: infra-mongo-infra-mongo-{{ $index }}
local:
path: /var/lib/compass/db/mongo
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- {{ $value }}
{{- end }}
15 changes: 15 additions & 0 deletions manifests/infra-mongo/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- range tuple "0" "1" "2" }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: infra-mongo-infra-mongo-{{ . }}
namespace: {{ $.Release.Namespace | quote }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
volumeName: infra-mongo-infra-mongo-{{ . }}
{{- end }}
22 changes: 22 additions & 0 deletions manifests/infra-mongo/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.serviceName | quote }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations:
{{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
selector: {{- include "common.labels.matchLabels" . | nindent 4 }}
type: ClusterIP
clusterIP: None
ports:
- name: mongo
port: {{ .Values.serverPort }}
protocol: TCP
targetPort: {{ .Values.serverPort }}
96 changes: 96 additions & 0 deletions manifests/infra-mongo/templates/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
kind: StatefulSet
metadata:
name: {{ include "common.names.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
serviceName: {{ .Values.serviceName | quote }}
selector:
matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
replicas: {{ default 1 .Values.replicaCount }}
template:
metadata:
labels: {{- include "common.labels.standard" . | nindent 8 }}
{{- if .Values.podLabels }}
{{- include "common.tplvalues.render" (dict "value" .Values.podLabels "context" $) | nindent 8 }}
{{- end }}
{{- if .Values.podAnnotations }}
annotations:
{{- include "common.tplvalues.render" (dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
{{- end }}
spec:
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName | quote }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: {{ include "common.images.image" (dict "context" $ "repository" .Values.platformConfig.imageRepositoryLibrary "imageRoot" .Values.image) | quote }}
imagePullPolicy: {{ default "Always" .Values.platformConfig.imagePullPolicy | quote }}
{{- if .Values.command }}
command: {{- include "common.tplvalues.render" ( dict "value" .Values.command "context" $) | nindent 8 }}
{{- else }}
command:
- "mongod"
{{- end }}
{{- if .Values.args }}
args: {{- include "common.tplvalues.render" ( dict "value" .Values.args "context" $) | nindent 8 }}
{{- else }}
args:
- "--replSet"
- "rs0"
- "--bind_ip"
- "0.0.0.0"
{{- end }}
{{- if .Values.serverPort }}
ports:
- name: mongo
containerPort: {{ .Values.serverPort }}
{{- end }}
{{- if .Values.resources }}
resources: {{- toYaml .Values.resources | nindent 10 }}
{{- end }}
{{- if .Values.persistence.enabled }}
volumeMounts:
- name: {{ include "common.names.fullname" . }}
mountPath: {{ .Values.persistence.mountPath | quote }}
{{- end }}
- name: {{ .Chart.Name }}-sidecar
image: {{ include "common.images.image" (dict "context" $ "repository" .Values.platformConfig.imageRepositoryRelease "imageRoot" .Values.sidecar.image) | quote }}
imagePullPolicy: {{ default "Always" .Values.platformConfig.imagePullPolicy | quote }}
env:
- name: "KUBE_NAMESPACE"
value: {{ .Release.Namespace | quote }}
- name: "MONGO_SIDECAR_POD_LABELS"
value: "app.kubernetes.io/name=infra-mongo"
- name: "MONGO_PORT"
value: {{ .Values.serverPort | quote }}
- name: "KUBERNETES_MONGO_SERVICE_NAME"
value: {{ .Values.serviceName | quote }}
{{- if .Values.sidecar.resources }}
resources: {{- toYaml .Values.sidecar.resources | nindent 10 }}
{{- end }}
{{- if .Values.persistence.enabled }}
volumeClaimTemplates:
- metadata:
name: {{ include "common.names.fullname" . }}
labels: {{- include "common.labels.standard" . | nindent 8 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 8 }}
{{- end }}
spec:
accessModes:
{{- range .Values.persistence.accessModes }}
- {{ . | quote }}
{{- end }}
storageClassName: {{ .Values.persistence.storageClass | quote }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- end }}
74 changes: 74 additions & 0 deletions manifests/infra-mongo/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
platformConfig:
imageRegistry: cargo.dev.caicloud.xyz
imageRepositoryLibrary: library
imageRepositoryRelease: release
imagePullPolicy: Always

image:
name: mongo
# tag:

serverPort: 27017
priorityClassName: system-cluster-critical
replicaCount: 3
serviceName: mgo-cluster

persistence:
enabled: true
storageClass:
accessModes:
- ReadWriteOnce
size: 50Gi
mountPath: /data/db

resources:
limits:
memory: 5Gi
cpu: 500m
requests:
memory: 2Gi
cpu: 100m

sidecar:
image:
name: mongo-k8s-sidecar
tag: v0.0.9
resources:
requests:
cpu: 20m
memory: 100Mi
limits:
cpu: 50m
memory: 200Mi

## String to partially override aspnet-core.fullname template (will maintain the release name)
##
# nameOverride:

## String to fully override aspnet-core.fullname template
##
# fullnameOverride:

## Command and args for running the container (set to default if not set). Use array form
##
# command: []
# args: []

## Add labels to all the deployed resources
##
# commonLabels: {}

## Add annotations to all the deployed resources
##
# commonAnnotations: {}

## Pod labels
## Ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
##
# podLabels: {}

## Pod annotations
## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
##
# podAnnotations: {}

0 comments on commit 7d5d41b

Please sign in to comment.