Skip to content

Commit

Permalink
Merge pull request #25 from myspotontheweb/feature/helm-chart
Browse files Browse the repository at this point in the history
Add a helm chart to install tesoro
  • Loading branch information
ademariag committed Nov 22, 2020
2 parents 254a031 + 4cf46d5 commit b8eaa87
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ You can also setup Prometheus monitoring for this. See [Monitoring](https://gith

Tesoro is a Kubernetes Admission Controller [Mutating Webhook](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#mutatingadmissionwebhook), which means that you'll need at minimum a Kubernetes v1.9 cluster.


### Example Kubernetes Config

You'll find the predefined example config in the [k8s/](./k8s) directory. Please make sure you read about setting up Mutating Webhooks [here](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#configure-admission-webhooks-on-the-fly)!
Expand Down Expand Up @@ -131,6 +132,48 @@ kubectl apply -f tests/k8s/nginx_deployment_bad.yml
Error from server: error when creating "nginx_deployment_bad.yml": admission webhook "tesoro-admission-controller.tesoro.svc" denied the request: Kapitan reveal failed
```

### Helm chart

This repository includes a helm chart which offers an alternative way to install Tesoro

```
kubectl create ns tesoro
helm install tesoro chart -n tesoro
```

#### Vault support

In order to support Vault references Tesoro will need a VAULT token, this can be created by logging into vault using your defined auth backend.
This example uses github:

```
vault login -no-print -method=github token=XXXXXXXXXXX
```

The helm chart is installed specifying the addition of a VAULT_TOKEN

```
helm install tesoro chart -n tesoro --set env.VAULT_TOKEN=$(cat ~/.vault-token)
```

##### Upgrading the token

Should the token expire, it can be refreshed as follows:

```
vault login -no-print -method=github token=XXXXXXXXXXX
helm upgrade tesoro chart -n tesoro --set env.VAULT_TOKEN=$(cat ~/.vault-token)
```

##### Using a secret to store Vault token

A more secure option is to save the token as a secret

```
kubectl create secret generic vault-creds --from-literal=VAULT_TOKEN=$(cat ~/.vault-token) -n tesoro
helm install tesoro chart --set secrets[0]=vault-creds -n tesoro
```

## Monitoring

Tesoro exposes a Prometheus endpoint (by default on port 9095) and the following metrics:
Expand Down
23 changes: 23 additions & 0 deletions chart/.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/
23 changes: 23 additions & 0 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: tesoro
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.
appVersion: latest
62 changes: 62 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "tesoro.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 "tesoro.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 "tesoro.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "tesoro.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "tesoro.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
25 changes: 25 additions & 0 deletions chart/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "tesoro.fullname" . }}
labels:
{{- include "tesoro.labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
resources:
- pods
- events
- secrets
- configmaps
verbs:
- "*"
- apiGroups:
- apps
resources:
- deployments
- daemonsets
- replicasets
- statefulsets
verbs:
- "*"
10 changes: 10 additions & 0 deletions chart/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "tesoro.fullname" . }}
labels:
{{- include "tesoro.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "tesoro.fullname" . }}
78 changes: 78 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "tesoro.fullname" . }}
labels:
{{- include "tesoro.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "tesoro.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "tesoro.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: 443
name: tesoro-api
- containerPort: 9095
name: metrics
args:
- --port=443
- --cert-file=/certs/cert.pem
- --key-file=/certs/priv.key
env:
{{- range $index, $value := .Values.env }}
- name: {{ $index }}
value: {{ $value | quote }}
{{- end }}
envFrom:
{{- range .Values.secrets }}
- secretRef:
name: {{.}}
optional: false
{{- end }}
{{- with .Values.probes }}
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: tesoro-secrets
mountPath: /certs
readOnly: true
volumes:
- name: tesoro-secrets
secret:
secretName: {{ include "tesoro.fullname" . }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
52 changes: 52 additions & 0 deletions chart/templates/mutatingwebhook_bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{ $ca := genCA "tesoro-admission-controller-ca" 3650 }}
{{ $cn := printf "tesoro-admission-controller.%s.svc" .Release.Namespace }}
{{ $server := genSignedCert $cn nil nil 365 $ca }}
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: MutatingWebhookConfiguration
metadata:
name: {{ include "tesoro.fullname" . }}
labels:
{{- include "tesoro.labels" . | nindent 4 }}
webhooks:
- name: {{ include "tesoro.fullname" . }}.tesoro.svc
failurePolicy: Fail
objectSelector:
matchLabels:
tesoro.kapicorp.com: enabled
clientConfig:
service:
name: {{ include "tesoro.fullname" . }}
namespace: {{ .Release.Namespace }}
path: "/mutate"
caBundle: {{ b64enc $ca.Cert }}
rules:
- operations:
- CREATE
- UPDATE
apiGroups:
- ""
resources:
- "*"
apiVersions:
- "*"
- operations:
- CREATE
- UPDATE
apiGroups:
- "apps"
resources:
- "deployments"
apiVersions:
- "*"
---
apiVersion: v1
kind: Secret
metadata:
name: {{ include "tesoro.fullname" . }}
labels:
{{- include "tesoro.labels" . | nindent 4 }}
type: Opaque
data:
cert.pem: {{ b64enc $server.Cert }}
priv.key: {{ b64enc $server.Key }}
16 changes: 16 additions & 0 deletions chart/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "tesoro.fullname" . }}
labels:
{{- include "tesoro.labels" . | nindent 4 }}
spec:
ports:
- name: tesoro-api
port: 443
targetPort: tesoro-api
- name: metrics
port: 9095
targetPort: metrics
selector:
{{- include "tesoro.selectorLabels" . | nindent 4 }}
Loading

0 comments on commit b8eaa87

Please sign in to comment.