From f837ec6210a9f862995c203b82d515049cf4f3a7 Mon Sep 17 00:00:00 2001 From: Ari Croock Date: Tue, 14 Aug 2018 19:17:08 +0200 Subject: [PATCH] Initial helm chart --- k8s-external-ip-checker/.helmignore | 21 +++++++ k8s-external-ip-checker/Chart.yaml | 5 ++ k8s-external-ip-checker/templates/NOTES.txt | 0 .../templates/_helpers.tpl | 32 ++++++++++ .../templates/daemonset.yaml | 63 +++++++++++++++++++ k8s-external-ip-checker/values.yaml | 33 ++++++++++ 6 files changed, 154 insertions(+) create mode 100644 k8s-external-ip-checker/.helmignore create mode 100644 k8s-external-ip-checker/Chart.yaml create mode 100644 k8s-external-ip-checker/templates/NOTES.txt create mode 100644 k8s-external-ip-checker/templates/_helpers.tpl create mode 100644 k8s-external-ip-checker/templates/daemonset.yaml create mode 100644 k8s-external-ip-checker/values.yaml diff --git a/k8s-external-ip-checker/.helmignore b/k8s-external-ip-checker/.helmignore new file mode 100644 index 0000000..f0c1319 --- /dev/null +++ b/k8s-external-ip-checker/.helmignore @@ -0,0 +1,21 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/k8s-external-ip-checker/Chart.yaml b/k8s-external-ip-checker/Chart.yaml new file mode 100644 index 0000000..c95499f --- /dev/null +++ b/k8s-external-ip-checker/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: k8s-external-ip-checker +version: 0.1.0 diff --git a/k8s-external-ip-checker/templates/NOTES.txt b/k8s-external-ip-checker/templates/NOTES.txt new file mode 100644 index 0000000..e69de29 diff --git a/k8s-external-ip-checker/templates/_helpers.tpl b/k8s-external-ip-checker/templates/_helpers.tpl new file mode 100644 index 0000000..30fdcc1 --- /dev/null +++ b/k8s-external-ip-checker/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "k8s-external-ip-checker.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 "k8s-external-ip-checker.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 "k8s-external-ip-checker.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/k8s-external-ip-checker/templates/daemonset.yaml b/k8s-external-ip-checker/templates/daemonset.yaml new file mode 100644 index 0000000..e0ef80c --- /dev/null +++ b/k8s-external-ip-checker/templates/daemonset.yaml @@ -0,0 +1,63 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ template "k8s-external-ip-checker.fullname" . }} + labels: + app: {{ template "k8s-external-ip-checker.name" . }} + chart: {{ template "k8s-external-ip-checker.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + selector: + matchLabels: + app: {{ template "k8s-external-ip-checker.name" . }} + release: {{ .Release.Name }} + template: + metadata: + labels: + app: {{ template "k8s-external-ip-checker.name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - sh + - -c + - | + set -eu; + trap 'echo Exiting... && exit 0' SIGTERM; + apk add --no-cache bind-tools; + while :; + do + set -e; + ip=$(dig +short myip.opendns.com @resolver1.opendns.com); + set +e; + echo $ALLOWED_IPS | grep "$ip" > /dev/null; + res=$?; + if [[ $res -eq 0 ]] + then + echo "SUCCESS - $ip is allowed" + else + echo "FAIL - $ip is not allowed" + fi + sleep {{ .Values.pollInterval }} + done + env: + - name: ALLOWED_IPS + value: {{ .Values.allowedIps }} + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: +{{ toYaml . | indent 8 }} + {{- end }} diff --git a/k8s-external-ip-checker/values.yaml b/k8s-external-ip-checker/values.yaml new file mode 100644 index 0000000..1e91604 --- /dev/null +++ b/k8s-external-ip-checker/values.yaml @@ -0,0 +1,33 @@ +# Default values for k8s-external-ip-checker. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: alpine + tag: latest + pullPolicy: IfNotPresent + +# will check the external IP address every pollInternal seconds +pollInterval: 60 +# comma-seperated list of allowed IP addresses +allowedIps: 127.0.0.1,192.168.1.1 + +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 + +nodeSelector: {} + +tolerations: [] + +affinity: {}