Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/charts/*/charts
.idea
test.yaml
.DS_Store
24 changes: 24 additions & 0 deletions charts/dns-canary/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: dns-canary
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.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
9 changes: 9 additions & 0 deletions charts/dns-canary/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# DNS Canary Helm Chart

This Helm chart deploys a DNS Canary CronJob to your Kubernetes cluster.
The canary continuously tests internal service discovery and optionally pushes logs to CloudWatch and sends alerts via SNS.

## Installation Example

```bash
helm install dns-canary ./dns-canary -f values.yaml
62 changes: 62 additions & 0 deletions charts/dns-canary/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "dns-canary.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 "dns-canary.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 "dns-canary.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "dns-canary.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "dns-canary.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
88 changes: 88 additions & 0 deletions charts/dns-canary/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "dns-canary.fullname" . }}
labels:
{{- include "dns-canary.labels" . | nindent 4 }}
app: {{ .Values.name }}
spec:
schedule: {{ .Values.schedule | quote }}
concurrencyPolicy: Allow
failedJobsHistoryLimit: 1
successfulJobsHistoryLimit: 3
suspend: false
jobTemplate:
spec:
backoffLimit: 6
completions: 1
parallelism: 1
template:
metadata:
labels:
{{- include "dns-canary.selectorLabels" . | nindent 12 }}
app: {{ .Values.name }}
spec:
restartPolicy: OnFailure
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
serviceAccountName: {{ include "dns-canary.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 12 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 16 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/sh
- -c
- |
set -e
TARGET="{{ .Values.targetService }}"
echo "$(date) Checking DNS resolution for $TARGET"

if nslookup $TARGET; then
echo "$(date) DNS Canary check passed for $TARGET"
else
echo "$(date) DNS Canary check failed for $TARGET" >&2

if [ -n "{{`{{ .Values.cloudwatchLogGroup }}`}}" ]; then
echo "Sending failure log to CloudWatch"
aws logs put-log-events \
--log-group-name "{{`{{ .Values.cloudwatchLogGroup }}`}}" \
--log-stream-name "dns-canary-{{`{{ .Values.name }}`}}" \
--log-events "timestamp=$(date +%s%3N),message=\"DNS Canary failure: $TARGET\""
fi

if [ -n "{{`{{ .Values.alertSnsTopicArn }}`}}" ]; then
echo "Triggering SNS alert"
aws sns publish \
--topic-arn "{{`{{ .Values.alertSnsTopicArn }}`}}" \
--message "DNS Canary failure detected for $TARGET in cluster {{`{{ .Values.clusterName }}`}}"
fi
fi
resources:
{{- toYaml .Values.resources | nindent 16 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
13 changes: 13 additions & 0 deletions charts/dns-canary/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "dns-canary.serviceAccountName" . }}
labels:
{{- include "dns-canary.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
86 changes: 86 additions & 0 deletions charts/dns-canary/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Default values for dns-canary.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

targetService: kubernetes.default.svc.cluster.local

# Scheduled to run cronjob every 20 minutes.
schedule: "*/20 * * * *"

# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/
replicaCount: 1

# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/
image:
repository: busybox
# This sets the pull policy for images.
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "1.37"

# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
imagePullSecrets: []
# This is to override the chart name.
nameOverride: ""
fullnameOverride: ""

# This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/
serviceAccount:
# Specifies whether a service account should be created
create: true
# Automatically mount a ServiceAccount's API credentials?
automount: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""

# This is for setting Kubernetes Annotations to a Pod.
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
podAnnotations: {}
# This is for setting Kubernetes Labels to a Pod.
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
podLabels: {}

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

# Additional volumes on the output Deployment definition.
volumes: []
# - name: foo
# secret:
# secretName: mysecret
# optional: false

# Additional volumeMounts on the output Deployment definition.
volumeMounts: []
# - name: foo
# mountPath: "/etc/foo"
# readOnly: true

nodeSelector: {}

tolerations: []

affinity: {}