From d6f5d019be9a1111ca40f64a3577cf72fefcc7ab Mon Sep 17 00:00:00 2001 From: wbsong111 Date: Thu, 20 Mar 2025 11:45:30 +0900 Subject: [PATCH] Add dnsup chart v1.0.1 --- charts/dnsup/.helmignore | 23 ++++++ charts/dnsup/Chart.yaml | 6 ++ charts/dnsup/custom-values.yaml | 18 +++++ charts/dnsup/templates/NOTES.txt | 22 ++++++ charts/dnsup/templates/_helpers.tpl | 62 +++++++++++++++ charts/dnsup/templates/deployment.yaml | 75 +++++++++++++++++++ charts/dnsup/templates/ingress.yaml | 61 +++++++++++++++ charts/dnsup/templates/service.yaml | 24 ++++++ .../templates/tests/test-connection.yaml | 15 ++++ charts/dnsup/values.yaml | 61 +++++++++++++++ 10 files changed, 367 insertions(+) create mode 100644 charts/dnsup/.helmignore create mode 100644 charts/dnsup/Chart.yaml create mode 100644 charts/dnsup/custom-values.yaml create mode 100644 charts/dnsup/templates/NOTES.txt create mode 100644 charts/dnsup/templates/_helpers.tpl create mode 100644 charts/dnsup/templates/deployment.yaml create mode 100644 charts/dnsup/templates/ingress.yaml create mode 100644 charts/dnsup/templates/service.yaml create mode 100644 charts/dnsup/templates/tests/test-connection.yaml create mode 100644 charts/dnsup/values.yaml diff --git a/charts/dnsup/.helmignore b/charts/dnsup/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/dnsup/.helmignore @@ -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/ diff --git a/charts/dnsup/Chart.yaml b/charts/dnsup/Chart.yaml new file mode 100644 index 0000000..d25a48b --- /dev/null +++ b/charts/dnsup/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +appVersion: 1.0.0 +description: A Helm chart for Kubernetes +name: dnsup +type: application +version: 1.0.1 diff --git a/charts/dnsup/custom-values.yaml b/charts/dnsup/custom-values.yaml new file mode 100644 index 0000000..e8d12be --- /dev/null +++ b/charts/dnsup/custom-values.yaml @@ -0,0 +1,18 @@ +image: + repository: paasup/dnsup + tag: "v0.3" + +# imagePullSecrets: +# - name: regcred + +service: + type: LoadBalancer + # LoadBalancerIP: "127.0.0.1" + +env: + DB_HOST: postgresql-postgresql-ha-postgresql.platform.svc.cluster.local + DB_PORT: "5432" + DB_USER: paasup + DB_PASSWORD: paasup + DB_NAME: paasup + UPPER_DNS: "8.8.8.8" \ No newline at end of file diff --git a/charts/dnsup/templates/NOTES.txt b/charts/dnsup/templates/NOTES.txt new file mode 100644 index 0000000..626e733 --- /dev/null +++ b/charts/dnsup/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 "dnsup.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 "dnsup.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "dnsup.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 "dnsup.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/dnsup/templates/_helpers.tpl b/charts/dnsup/templates/_helpers.tpl new file mode 100644 index 0000000..86bbf82 --- /dev/null +++ b/charts/dnsup/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "dnsup.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 "dnsup.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 "dnsup.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "dnsup.labels" -}} +helm.sh/chart: {{ include "dnsup.chart" . }} +{{ include "dnsup.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "dnsup.selectorLabels" -}} +app.kubernetes.io/name: {{ include "dnsup.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "dnsup.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "dnsup.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/dnsup/templates/deployment.yaml b/charts/dnsup/templates/deployment.yaml new file mode 100644 index 0000000..a1a229d --- /dev/null +++ b/charts/dnsup/templates/deployment.yaml @@ -0,0 +1,75 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "dnsup.fullname" . }} + labels: + {{- include "dnsup.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "dnsup.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "dnsup.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: udp + containerPort: {{ .Values.service.port }} + protocol: UDP + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + env: + - name: DB_HOST + value: "{{ .Values.env.DB_HOST }}" + - name: DB_PORT + value: "{{ .Values.env.DB_PORT }}" + - name: DB_USER + value: "{{ .Values.env.DB_USER }}" + - name: DB_PASSWORD + value: "{{ .Values.env.DB_PASSWORD }}" + - name: DB_NAME + value: "{{ .Values.env.DB_NAME }}" + - name: UPPER_DNS + value: "{{ .Values.env.UPPER_DNS }}" + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- 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/dnsup/templates/ingress.yaml b/charts/dnsup/templates/ingress.yaml new file mode 100644 index 0000000..b285581 --- /dev/null +++ b/charts/dnsup/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "dnsup.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "dnsup.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/dnsup/templates/service.yaml b/charts/dnsup/templates/service.yaml new file mode 100644 index 0000000..6b56755 --- /dev/null +++ b/charts/dnsup/templates/service.yaml @@ -0,0 +1,24 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "dnsup.fullname" . }} + labels: + {{- include "dnsup.labels" . | nindent 4 }} + annotations: + {{- .Values.service.annotations | toYaml | nindent 4 }} +spec: + type: {{ .Values.service.type }} + {{- if and (eq .Values.service.type "LoadBalancer" ) .Values.service.LoadBalancerIP }} + loadBalancerIP: {{ .Values.service.LoadBalancerIP }} + {{- end }} + ports: + - port: {{ .Values.service.port }} + targetPort: 53 + protocol: UDP + name: udp + - port: {{ .Values.service.port }} + targetPort: 53 + protocol: TCP + name: tcp + selector: + {{- include "dnsup.selectorLabels" . | nindent 4 }} \ No newline at end of file diff --git a/charts/dnsup/templates/tests/test-connection.yaml b/charts/dnsup/templates/tests/test-connection.yaml new file mode 100644 index 0000000..34048ca --- /dev/null +++ b/charts/dnsup/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "dnsup.fullname" . }}-test-connection" + labels: + {{- include "dnsup.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "dnsup.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/dnsup/values.yaml b/charts/dnsup/values.yaml new file mode 100644 index 0000000..1abe5bb --- /dev/null +++ b/charts/dnsup/values.yaml @@ -0,0 +1,61 @@ +# Default values for dnsup. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: paasup/dnsup + pullPolicy: IfNotPresent + tag: "v0.2" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +podSecurityContext: {} + +securityContext: {} + +service: + type: ClusterIP + port: 53 + LoadBalancerIP: "" + annotations: {} + +ingress: + enabled: false + className: "" + annotations: {} + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + +resources: {} + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + +volumes: [] + +volumeMounts: [] + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +env: + DB_HOST: "" + DB_PORT: "5432" + DB_USER: "" + DB_PASSWORD: "" + DB_NAME: "" + UPPER_DNS: "8.8.8.8" \ No newline at end of file