diff --git a/README.md b/README.md index 06a0d0a..3274d5a 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,16 @@ $ docker-compose up -d You can check the metrics by accessing Prometheus ([http://127.0.0.1:9200]()). +#### Running with `helm` + +##### Prerequisites + +https://github.com/aslafy-z/helm-git + +``` +$ helm repo add sendgrid-stats-exporter git+https://github.com/chatwork/sendgrid-stats-exporter@charts?ref=v0.0.1 +``` + ## Building ### Building locally diff --git a/charts/.helmignore b/charts/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/.helmignore @@ -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/ diff --git a/charts/Chart.yaml b/charts/Chart.yaml new file mode 100644 index 0000000..2ed4c52 --- /dev/null +++ b/charts/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: sendgrid-stats-exporter +description: A Helm chart for chatwork/sendgrid-stats-exporter (It's till private for now, but will make it public soon) +type: application +version: 0.0.1 +appVersion: 0.0.3 diff --git a/charts/Makefile b/charts/Makefile new file mode 100644 index 0000000..c743a34 --- /dev/null +++ b/charts/Makefile @@ -0,0 +1,25 @@ +KUBERNETES_VERSION="1.18.1" +RELEASE = $$(basename $$PWD) + +.PHONY: install +install: + helm upgrade -i --wait $(RELEASE) . + +.PHONY: lint +lint: lint-default + +.PHONY: lint-default +lint-default: + @echo "=> Linting default values.yaml" + helm lint --strict + @echo "=> Validating default value.yaml" + helm template . | kubeval --kubernetes-version $(KUBERNETES_VERSION) + @echo "" + +.PHONY: test +test: + helm test --logs $(RELEASE) + +.PHONY: uninstall +uninstall: + helm uninstall $(RELEASE) \ No newline at end of file diff --git a/charts/README.md b/charts/README.md new file mode 100644 index 0000000..74c1e1f --- /dev/null +++ b/charts/README.md @@ -0,0 +1,71 @@ +sendgrid-stats-exporter +=========== + +A Helm chart for [chatwork/sendgrid-stats-exporter](https://github.com/chatwork/sendgrid-stats-exporter). + +## Installing the Chart + +``` +$ cat configmap.yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: sendgrid-config + data: + SENDGRID_API_KEY: 'secret' +$ kubectl apply -f configmap.yaml +configmap/sendgrid-config created + +$ helm install --set 'envFrom[0].configMapRef.name=sendgrid-config' sendgrid-stats-exporter ./ +``` + +``` +$ kubectl get svc +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +sendgrid-stats-exporter ClusterIP 10.108.179.32 9154/TCP 2m54s + +$ kubectl run -it --rm=true busybox --image=yauritux/busybox-curl --restart=Never +/home # curl 10.108.179.32:9154/-/healthy +OK +``` + +## Configuration + +The following table lists the configurable parameters of the Sendgrid-stats-exporter chart and their default values. + +| Parameter | Description | Default | +| ------------------------ | ----------------------- | -------------- | +| `replicaCount` | Number of replicas | `1` | +| `image.repository` | Image repository | `"chatwork/sendgrid-stats-exporter"` | +| `image.pullPolicy` | Image pull policy | `"IfNotPresent"` | +| `image.tag` | Image tag | `"0.0.3"` | +| `imagePullSecrets` | Image pull secret | `[]` | +| `nameOverride` | Override the name of the chart | `""` | +| `fullnameOverride` | Override the full-name of the chart | `""` | +| `serviceAccount.create` | If true, create a new service account | `true` | +| `serviceAccount.annotations` | Annotations for serviceAccount | `{}` | +| `serviceAccount.name` | Name of the service account | `""` | +| `podAnnotations` | Annotations for the pod | `{}` | +| `podSecurityContext` | Security context for the pod | `{}` | +| `securityContext` | Security context for container | `{}` | +| `envFrom` | Extra custom environment variables from ConfigMaps | `[]` | +| `service.type` | Service Type | `"ClusterIP"` | +| `service.port` | Service port | `9154` | +| `ingress.enabled` | If true, enable Ingress | `false` | +| `ingress.annotations` | Annotations for ingress | `{}` | +| `ingress.hosts` | Ingress accepted hostnames | `[{"host": "chart-example.local", "paths": []}]` | +| `ingress.tls` | Ingress TLS configuration | `[]` | +| `resources.limits.cpu` | | `"200m"` | +| `resources.limits.memory` | | `"256Mi"` | +| `resources.requests.cpu` | | `"100m"` | +| `resources.requests.memory` | | `"128Mi"` | +| `autoscaling.enabled` | If true, enable auto-scaling | `false` | +| `autoscaling.minReplicas` | | `1` | +| `autoscaling.maxReplicas` | | `5` | +| `autoscaling.targetCPUUtilizationPercentage` | | `80` | +| `nodeSelector` | Node labels for pod assignment | `{}` | +| `tolerations` | Add tolerations | `[]` | +| `affinity` | Node/Pod affinities | `{}` | + +--- +_Documentation generated by [Frigate](https://frigate.readthedocs.io)._ \ No newline at end of file diff --git a/charts/templates/NOTES.txt b/charts/templates/NOTES.txt new file mode 100644 index 0000000..38d6191 --- /dev/null +++ b/charts/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "sendgrid-stats-exporter.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "sendgrid-stats-exporter.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "sendgrid-stats-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "sendgrid-stats-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/templates/_helpers.tpl b/charts/templates/_helpers.tpl new file mode 100644 index 0000000..d020648 --- /dev/null +++ b/charts/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "sendgrid-stats-exporter.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 "sendgrid-stats-exporter.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 "sendgrid-stats-exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "sendgrid-stats-exporter.labels" -}} +helm.sh/chart: {{ include "sendgrid-stats-exporter.chart" . }} +{{ include "sendgrid-stats-exporter.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "sendgrid-stats-exporter.selectorLabels" -}} +app.kubernetes.io/name: {{ include "sendgrid-stats-exporter.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "sendgrid-stats-exporter.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "sendgrid-stats-exporter.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/templates/deployment.yaml b/charts/templates/deployment.yaml new file mode 100644 index 0000000..a40e54b --- /dev/null +++ b/charts/templates/deployment.yaml @@ -0,0 +1,63 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "sendgrid-stats-exporter.fullname" . }} + labels: + {{- include "sendgrid-stats-exporter.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "sendgrid-stats-exporter.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "sendgrid-stats-exporter.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "sendgrid-stats-exporter.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 }} + envFrom: + {{- toYaml .Values.envFrom | nindent 12 }} + ports: + - name: http + containerPort: 9154 + protocol: TCP + livenessProbe: + httpGet: + path: /-/healthy + port: http + readinessProbe: + httpGet: + path: /-/healthy + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/templates/ingress.yaml b/charts/templates/ingress.yaml new file mode 100644 index 0000000..e5e671c --- /dev/null +++ b/charts/templates/ingress.yaml @@ -0,0 +1,41 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "sendgrid-stats-exporter.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "sendgrid-stats-exporter.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} diff --git a/charts/templates/service.yaml b/charts/templates/service.yaml new file mode 100644 index 0000000..966f651 --- /dev/null +++ b/charts/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "sendgrid-stats-exporter.fullname" . }} + labels: + {{- include "sendgrid-stats-exporter.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "sendgrid-stats-exporter.selectorLabels" . | nindent 4 }} diff --git a/charts/templates/serviceaccount.yaml b/charts/templates/serviceaccount.yaml new file mode 100644 index 0000000..f954982 --- /dev/null +++ b/charts/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "sendgrid-stats-exporter.serviceAccountName" . }} + labels: + {{- include "sendgrid-stats-exporter.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/templates/tests/test-connection.yaml b/charts/templates/tests/test-connection.yaml new file mode 100644 index 0000000..1173f6c --- /dev/null +++ b/charts/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "sendgrid-stats-exporter.fullname" . }}-test-connection" + labels: + {{- include "sendgrid-stats-exporter.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "sendgrid-stats-exporter.fullname" . }}:{{ .Values.service.port }}/-/healthy'] + restartPolicy: Never diff --git a/charts/values.yaml b/charts/values.yaml new file mode 100644 index 0000000..cf0f5c5 --- /dev/null +++ b/charts/values.yaml @@ -0,0 +1,68 @@ +replicaCount: 1 + +image: + repository: chatwork/sendgrid-stats-exporter + pullPolicy: IfNotPresent + tag: "0.0.3" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: true + annotations: {} + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +envFrom: [] + +service: + type: ClusterIP + port: 9154 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 5 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {}