diff --git a/.gitignore b/.gitignore index 68354d5..ef1a88d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /charts/*/charts .idea test.yaml +.DS_Store \ No newline at end of file diff --git a/charts/dns-canary/Chart.yaml b/charts/dns-canary/Chart.yaml new file mode 100644 index 0000000..eb0c889 --- /dev/null +++ b/charts/dns-canary/Chart.yaml @@ -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" diff --git a/charts/dns-canary/README.md b/charts/dns-canary/README.md new file mode 100644 index 0000000..e2d71ff --- /dev/null +++ b/charts/dns-canary/README.md @@ -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 \ No newline at end of file diff --git a/charts/dns-canary/templates/_helpers.tpl b/charts/dns-canary/templates/_helpers.tpl new file mode 100644 index 0000000..584e736 --- /dev/null +++ b/charts/dns-canary/templates/_helpers.tpl @@ -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 }} diff --git a/charts/dns-canary/templates/cronjob.yaml b/charts/dns-canary/templates/cronjob.yaml new file mode 100644 index 0000000..be8b4a5 --- /dev/null +++ b/charts/dns-canary/templates/cronjob.yaml @@ -0,0 +1,71 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ include "dns-canary.fullname" . }} + labels: + {{- include "dns-canary.labels" . | nindent 4 }} +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 }} + 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 "[ERROR] $(date) DNS Canary check failed for $TARGET" >&2 + 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 }} \ No newline at end of file diff --git a/charts/dns-canary/templates/serviceaccount.yaml b/charts/dns-canary/templates/serviceaccount.yaml new file mode 100644 index 0000000..4db724f --- /dev/null +++ b/charts/dns-canary/templates/serviceaccount.yaml @@ -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 }} diff --git a/charts/dns-canary/values.yaml b/charts/dns-canary/values.yaml new file mode 100644 index 0000000..c7890df --- /dev/null +++ b/charts/dns-canary/values.yaml @@ -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: {}