From 72fdc05d415e18b82f379134a6ea3254edb4e841 Mon Sep 17 00:00:00 2001 From: Alex Sukhov Date: Sun, 12 Dec 2021 22:14:44 +0300 Subject: [PATCH] Add unbound chart --- .github/workflows/lint-test.yml | 37 ++++++++++++ .github/workflows/release.yml | 25 ++++++++ charts/unbound/Chart.yaml | 6 ++ charts/unbound/files/no-forward.conf | 1 + charts/unbound/templates/NOTES.txt | 22 +++++++ charts/unbound/templates/_helpers.tpl | 62 +++++++++++++++++++ charts/unbound/templates/configmap.yaml | 20 +++++++ charts/unbound/templates/deployment.yaml | 76 ++++++++++++++++++++++++ charts/unbound/templates/service.yaml | 21 +++++++ charts/unbound/values.yaml | 74 +++++++++++++++++++++++ 10 files changed, 344 insertions(+) create mode 100644 .github/workflows/lint-test.yml create mode 100644 .github/workflows/release.yml create mode 100644 charts/unbound/Chart.yaml create mode 100644 charts/unbound/files/no-forward.conf create mode 100644 charts/unbound/templates/NOTES.txt create mode 100644 charts/unbound/templates/_helpers.tpl create mode 100644 charts/unbound/templates/configmap.yaml create mode 100644 charts/unbound/templates/deployment.yaml create mode 100644 charts/unbound/templates/service.yaml create mode 100644 charts/unbound/values.yaml diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml new file mode 100644 index 0000000..bf0a255 --- /dev/null +++ b/.github/workflows/lint-test.yml @@ -0,0 +1,37 @@ +name: Lint and Test Charts + +on: pull_request + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Fetch history + run: git fetch --prune --unshallow + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.1.0 + + - name: Run chart-testing (lint) + run: ct lint --config .github/ct-lint.yaml + + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Fetch history + run: git fetch --prune --unshallow + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.1.0 + + - name: Create kind cluster + uses: helm/kind-action@v1.2.0 + + - name: Run chart-testing (install) + run: ct install --config .github/ct-install.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1adac0b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,25 @@ +name: Release Charts + +on: + push: + branches: + - master + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.2.1 + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/charts/unbound/Chart.yaml b/charts/unbound/Chart.yaml new file mode 100644 index 0000000..fe840e7 --- /dev/null +++ b/charts/unbound/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: unbound +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: "1.13.1" diff --git a/charts/unbound/files/no-forward.conf b/charts/unbound/files/no-forward.conf new file mode 100644 index 0000000..ac4414e --- /dev/null +++ b/charts/unbound/files/no-forward.conf @@ -0,0 +1 @@ +forward-zone: diff --git a/charts/unbound/templates/NOTES.txt b/charts/unbound/templates/NOTES.txt new file mode 100644 index 0000000..635b975 --- /dev/null +++ b/charts/unbound/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 }}{{ .path }} + {{- 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 "unbound.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 "unbound.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "unbound.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 "unbound.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/unbound/templates/_helpers.tpl b/charts/unbound/templates/_helpers.tpl new file mode 100644 index 0000000..48572eb --- /dev/null +++ b/charts/unbound/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "unbound.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 "unbound.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 "unbound.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "unbound.labels" -}} +helm.sh/chart: {{ include "unbound.chart" . }} +{{ include "unbound.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "unbound.selectorLabels" -}} +app.kubernetes.io/name: {{ include "unbound.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "unbound.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "unbound.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/unbound/templates/configmap.yaml b/charts/unbound/templates/configmap.yaml new file mode 100644 index 0000000..fc3a0b1 --- /dev/null +++ b/charts/unbound/templates/configmap.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: unbound-forward-records +data: + forward-records.conf: | + #forward-zone: + # Forward all queries (except those in cache and local zone) to + # upstream recursive servers + #name: "." + # Queries to this forward zone use TLS + #forward-tls-upstream: yes + + # https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers + + ## Cloudflare + #forward-addr: 1.1.1.1@853#cloudflare-dns.com + #forward-addr: 1.0.0.1@853#cloudflare-dns.com + # forward-addr: 2606:4700:4700::1111@853#cloudflare-dns.com + # forward-addr: 2606:4700:4700::1001@853#cloudflare-dns.com diff --git a/charts/unbound/templates/deployment.yaml b/charts/unbound/templates/deployment.yaml new file mode 100644 index 0000000..3ba42a7 --- /dev/null +++ b/charts/unbound/templates/deployment.yaml @@ -0,0 +1,76 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "unbound.fullname" . }} + labels: + {{- include "unbound.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "unbound.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "unbound.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + 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 }} + ports: + - name: dns-tcp + containerPort: 53 + protocol: TCP + - name: dns-udp + containerPort: 53 + protocol: UDP +# livenessProbe: +# tcpSocket: +# port: 53 +# initialDelaySeconds: 30 +# periodSeconds: 5 +# readinessProbe: +# tcpSocket: +# port: 53 +# initialDelaySeconds: 25 +# periodSeconds: 5 + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: config-volume + mountPath: /opt/unbound/etc/unbound/forward-records.conf + subPath: forward-records.conf + volumes: + - name: config-volume + configMap: + name: unbound-forward-records +# items: +# - key: forward-records.conf +# path: forward-records.conf + {{- 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/unbound/templates/service.yaml b/charts/unbound/templates/service.yaml new file mode 100644 index 0000000..9e45e78 --- /dev/null +++ b/charts/unbound/templates/service.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "unbound.fullname" . }} + labels: + {{- include "unbound.labels" . | nindent 4 }} +spec: +# type: {{ .Values.service.type }} + type: LoadBalancer + loadBalancerIP: {{ .Values.service.loadBalancerIP }} + ports: +# - port: 5353 +# targetPort: 53 +# protocol: TCP +# name: dns-tcp + - port: 5353 + targetPort: 53 + protocol: UDP + name: dns-udp + selector: + {{- include "unbound.selectorLabels" . | nindent 4 }} diff --git a/charts/unbound/values.yaml b/charts/unbound/values.yaml new file mode 100644 index 0000000..480a7d9 --- /dev/null +++ b/charts/unbound/values.yaml @@ -0,0 +1,74 @@ +# Default values for unbound. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: mvance/unbound-rpi + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "1.13.1" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 5353 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + backend: + serviceName: chart-example.local + servicePort: 80 + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +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 + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {}