From 7f28935d65414d4cdac80982e0bb7d2b00c0171a Mon Sep 17 00:00:00 2001 From: Nikolai Date: Sun, 28 Sep 2025 13:02:33 -0400 Subject: [PATCH 1/3] added helm and simple manifests for k8s --- k8s/helm/Chart.yaml | 6 ++ k8s/helm/templates/NOTES.txt | 7 ++ k8s/helm/templates/_helpers.tpl | 26 ++++++ k8s/helm/templates/configmap.yaml | 10 +++ k8s/helm/templates/deployment.yaml | 97 ++++++++++++++++++++++ k8s/helm/templates/hpa.yaml | 22 +++++ k8s/helm/templates/ingress.yaml | 35 ++++++++ k8s/helm/templates/pdb.yaml | 14 ++++ k8s/helm/templates/service.yaml | 16 ++++ k8s/helm/templates/serviceaccount.yaml | 11 +++ k8s/helm/values.yaml | 107 +++++++++++++++++++++++++ k8s/manifests/configmap.yaml | 7 ++ k8s/manifests/deployment.yaml | 38 +++++++++ k8s/manifests/service.yaml | 13 +++ 14 files changed, 409 insertions(+) create mode 100644 k8s/helm/Chart.yaml create mode 100644 k8s/helm/templates/NOTES.txt create mode 100644 k8s/helm/templates/_helpers.tpl create mode 100644 k8s/helm/templates/configmap.yaml create mode 100644 k8s/helm/templates/deployment.yaml create mode 100644 k8s/helm/templates/hpa.yaml create mode 100644 k8s/helm/templates/ingress.yaml create mode 100644 k8s/helm/templates/pdb.yaml create mode 100644 k8s/helm/templates/service.yaml create mode 100644 k8s/helm/templates/serviceaccount.yaml create mode 100644 k8s/helm/values.yaml create mode 100644 k8s/manifests/configmap.yaml create mode 100644 k8s/manifests/deployment.yaml create mode 100644 k8s/manifests/service.yaml diff --git a/k8s/helm/Chart.yaml b/k8s/helm/Chart.yaml new file mode 100644 index 0000000..966f2c8 --- /dev/null +++ b/k8s/helm/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: helloenv +version: 0.1.0 +appVersion: "1.0.0" +description: Minimal Helm chart for helloenv (.NET 9) app +type: application \ No newline at end of file diff --git a/k8s/helm/templates/NOTES.txt b/k8s/helm/templates/NOTES.txt new file mode 100644 index 0000000..2d3d52e --- /dev/null +++ b/k8s/helm/templates/NOTES.txt @@ -0,0 +1,7 @@ +1. Get the application URL by running these commands: + export RELEASE={{ .Release.Name }} + export NAMESPACE={{ .Release.Namespace }} + + kubectl get svc $RELEASE-helloenv -n $NAMESPACE + +2. If Ingress is enabled, open the configured host(s). \ No newline at end of file diff --git a/k8s/helm/templates/_helpers.tpl b/k8s/helm/templates/_helpers.tpl new file mode 100644 index 0000000..30ea964 --- /dev/null +++ b/k8s/helm/templates/_helpers.tpl @@ -0,0 +1,26 @@ +{{- define "helloenv.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{- define "helloenv.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 -}} + +{{- define "helloenv.labels" -}} +app.kubernetes.io/name: {{ include "helloenv.name" . }} +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +{{- end -}} \ No newline at end of file diff --git a/k8s/helm/templates/configmap.yaml b/k8s/helm/templates/configmap.yaml new file mode 100644 index 0000000..06f2782 --- /dev/null +++ b/k8s/helm/templates/configmap.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "helloenv.fullname" . }}-config + labels: + {{- include "helloenv.labels" . | nindent 4 }} +data: + {{- range $k, $v := .Values.config }} + {{ $k }}: {{ $v | quote }} + {{- end }} \ No newline at end of file diff --git a/k8s/helm/templates/deployment.yaml b/k8s/helm/templates/deployment.yaml new file mode 100644 index 0000000..bb3ba04 --- /dev/null +++ b/k8s/helm/templates/deployment.yaml @@ -0,0 +1,97 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "helloenv.fullname" . }} + labels: + {{- include "helloenv.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + revisionHistoryLimit: 2 + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + maxSurge: 1 + selector: + matchLabels: + app.kubernetes.io/name: {{ include "helloenv.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "helloenv.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + spec: + {{- if .Values.image.pullSecrets }} + imagePullSecrets: + {{- toYaml .Values.image.pullSecrets | nindent 8 }} + {{- end }} + serviceAccountName: {{ default (include "helloenv.fullname" .) .Values.serviceAccount.name }} + terminationGracePeriodSeconds: 30 + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchLabels: + app.kubernetes.io/name: {{ include "helloenv.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + containers: + - name: {{ include "helloenv.name" . }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 8080 + env: + - name: ASPNETCORE_URLS + value: "http://+:8080" + envFrom: + - configMapRef: + name: {{ include "helloenv.fullname" . }}-config + securityContext: + {{- toYaml .Values.containerSecurityContext | nindent 12 }} + volumeMounts: + {{- toYaml .Values.extraVolumeMounts | nindent 12 }} + {{- if .Values.probes.startup.enabled }} + startupProbe: + httpGet: + path: {{ .Values.probes.startup.path }} + port: http + periodSeconds: {{ .Values.probes.startup.periodSeconds }} + failureThreshold: {{ .Values.probes.startup.failureThreshold }} + {{- end }} + readinessProbe: + httpGet: + path: {{ .Values.probes.readiness.path }} + port: http + periodSeconds: {{ .Values.probes.readiness.periodSeconds }} + timeoutSeconds: {{ .Values.probes.readiness.timeoutSeconds }} + failureThreshold: {{ .Values.probes.readiness.failureThreshold }} + livenessProbe: + httpGet: + path: {{ .Values.probes.liveness.path }} + port: http + periodSeconds: {{ .Values.probes.liveness.periodSeconds }} + timeoutSeconds: {{ .Values.probes.liveness.timeoutSeconds }} + failureThreshold: {{ .Values.probes.liveness.failureThreshold }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + {{- toYaml .Values.extraVolumes | nindent 8 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} \ No newline at end of file diff --git a/k8s/helm/templates/hpa.yaml b/k8s/helm/templates/hpa.yaml new file mode 100644 index 0000000..70c4b2f --- /dev/null +++ b/k8s/helm/templates/hpa.yaml @@ -0,0 +1,22 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "helloenv.fullname" . }} + labels: + {{- include "helloenv.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "helloenv.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} +{{- end }} \ No newline at end of file diff --git a/k8s/helm/templates/ingress.yaml b/k8s/helm/templates/ingress.yaml new file mode 100644 index 0000000..53605f6 --- /dev/null +++ b/k8s/helm/templates/ingress.yaml @@ -0,0 +1,35 @@ +{{- if .Values.ingress.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "helloenv.fullname" . }} + labels: + {{- include "helloenv.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.className }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ include "helloenv.fullname" $ }} + port: + name: http + {{- end }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- toYaml .Values.ingress.tls | nindent 4 }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/k8s/helm/templates/pdb.yaml b/k8s/helm/templates/pdb.yaml new file mode 100644 index 0000000..7cf7d8f --- /dev/null +++ b/k8s/helm/templates/pdb.yaml @@ -0,0 +1,14 @@ +{{- if .Values.pdb.enabled }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "helloenv.fullname" . }}-pdb + labels: + {{- include "helloenv.labels" . | nindent 4 }} +spec: + minAvailable: {{ .Values.pdb.minAvailable }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "helloenv.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} \ No newline at end of file diff --git a/k8s/helm/templates/service.yaml b/k8s/helm/templates/service.yaml new file mode 100644 index 0000000..ded27e8 --- /dev/null +++ b/k8s/helm/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "helloenv.fullname" . }} + labels: + {{- include "helloenv.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + selector: + app.kubernetes.io/name: {{ include "helloenv.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: http + protocol: TCP \ No newline at end of file diff --git a/k8s/helm/templates/serviceaccount.yaml b/k8s/helm/templates/serviceaccount.yaml new file mode 100644 index 0000000..3c976cb --- /dev/null +++ b/k8s/helm/templates/serviceaccount.yaml @@ -0,0 +1,11 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ default (include "helloenv.fullname" .) .Values.serviceAccount.name }} + labels: + {{- include "helloenv.labels" . | nindent 4 }} + annotations: + {{- toYaml .Values.serviceAccount.annotations | nindent 4 }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount | default false }} +{{- end }} \ No newline at end of file diff --git a/k8s/helm/values.yaml b/k8s/helm/values.yaml new file mode 100644 index 0000000..dc6829d --- /dev/null +++ b/k8s/helm/values.yaml @@ -0,0 +1,107 @@ +image: + repository: ghcr.io/nikodevops/helloenv + tag: "latest" + pullPolicy: IfNotPresent + pullSecrets: [] + +replicaCount: 2 + +serviceAccount: + create: false + name: "" + annotations: {} + automount: false + +autoscaling: + enabled: false + minReplicas: 2 + maxReplicas: 5 + targetCPUUtilizationPercentage: 70 + +pdb: + enabled: true + minAvailable: 1 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "nginx" + annotations: {} + hosts: + - host: helloenv.example.com + paths: + - path: / + pathType: Prefix + tls: [] + # - secretName: helloenv-tls + # hosts: + # - helloenv.example.com + +config: + GREETING: "World" + +resources: + requests: + cpu: 50m + memory: 128Mi + limits: + cpu: 250m + memory: 256Mi + +nodeSelector: {} + +affinity: {} + +tolerations: [] + +podAnnotations: {} + +podSecurityContext: + runAsNonRoot: true + runAsUser: 10000 + runAsGroup: 10000 + fsGroup: 2000 + seccompProfile: + type: RuntimeDefault + +containerSecurityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: ["ALL"] + +probes: + startup: + enabled: true + path: "/" + periodSeconds: 2 + failureThreshold: 30 + readiness: + path: "/" + periodSeconds: 5 + timeoutSeconds: 2 + failureThreshold: 3 + liveness: + path: "/" + periodSeconds: 10 + timeoutSeconds: 2 + failureThreshold: 3 + +extraEnv: [] +# - name: SOME_VAR +# value: some-value + +extraEnvFrom: [] +# - secretRef: +# name: my-secret + +extraVolumes: + - name: tmp + emptyDir: {} + +extraVolumeMounts: + - name: tmp + mountPath: /tmp \ No newline at end of file diff --git a/k8s/manifests/configmap.yaml b/k8s/manifests/configmap.yaml new file mode 100644 index 0000000..d69e619 --- /dev/null +++ b/k8s/manifests/configmap.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: helloenv-config +data: + GREETING: "World" \ No newline at end of file diff --git a/k8s/manifests/deployment.yaml b/k8s/manifests/deployment.yaml new file mode 100644 index 0000000..892fc35 --- /dev/null +++ b/k8s/manifests/deployment.yaml @@ -0,0 +1,38 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: helloenv + labels: + app: helloenv +spec: + replicas: 2 + selector: + matchLabels: + app: helloenv + template: + metadata: + labels: + app: helloenv + spec: + containers: + - name: helloenv + image: ghcr.io/nikodevops/helloenv:99772a4 + imagePullPolicy: IfNotPresent + ports: + - containerPort: 8080 + envFrom: + - configMapRef: + name: helloenv-config + readinessProbe: + httpGet: + path: / + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + livenessProbe: + httpGet: + path: / + port: 8080 + initialDelaySeconds: 15 + periodSeconds: 20 \ No newline at end of file diff --git a/k8s/manifests/service.yaml b/k8s/manifests/service.yaml new file mode 100644 index 0000000..9a0e66b --- /dev/null +++ b/k8s/manifests/service.yaml @@ -0,0 +1,13 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: helloenv-service +spec: + selector: + app: helloenv + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + type: ClusterIP \ No newline at end of file From e95028c934808764c69e7adc4658564cf0dae1c5 Mon Sep 17 00:00:00 2001 From: Nikolai Date: Sun, 28 Sep 2025 13:10:24 -0400 Subject: [PATCH 2/3] added readme --- k8s/helm/README.md | 17 +++++++++++++++++ k8s/helm/values.yaml | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 k8s/helm/README.md diff --git a/k8s/helm/README.md b/k8s/helm/README.md new file mode 100644 index 0000000..b52dab3 --- /dev/null +++ b/k8s/helm/README.md @@ -0,0 +1,17 @@ +# Quick start + +# create namespace (if needed) +kubectl create ns helloenv || true + +# Install chart from local folder ./helloenv +helm install helloenv . -n helloenv \ + --set image.repository=ghcr.io/nikodevops/helloenv \ + --set image.tag=dev \ + --set config.GREETING="Kuber" + +# Enable Ingress (example) +helm upgrade helloenv ./helloenv -n helloenv \ + --set ingress.enabled=true \ + --set ingress.hosts[0].host=helloenv.example.com \ + --set ingress.hosts[0].paths[0].path=/ \ + --set ingress.hosts[0].paths[0].pathType=Prefix \ No newline at end of file diff --git a/k8s/helm/values.yaml b/k8s/helm/values.yaml index dc6829d..fe7e9ee 100644 --- a/k8s/helm/values.yaml +++ b/k8s/helm/values.yaml @@ -7,7 +7,7 @@ image: replicaCount: 2 serviceAccount: - create: false + create: true name: "" annotations: {} automount: false @@ -19,7 +19,7 @@ autoscaling: targetCPUUtilizationPercentage: 70 pdb: - enabled: true + enabled: false minAvailable: 1 service: From 77b2203aebd107e19d2dbcf78c04975d43e0d7b1 Mon Sep 17 00:00:00 2001 From: Nikolai Date: Sun, 28 Sep 2025 13:36:06 -0400 Subject: [PATCH 3/3] updated readme --- k8s/helm/README.md | 10 ++++++++-- k8s/helm/values.yaml | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/k8s/helm/README.md b/k8s/helm/README.md index b52dab3..3bac756 100644 --- a/k8s/helm/README.md +++ b/k8s/helm/README.md @@ -1,6 +1,6 @@ # Quick start -# create namespace (if needed) +# Create namespace (if needed) kubectl create ns helloenv || true # Install chart from local folder ./helloenv @@ -14,4 +14,10 @@ helm upgrade helloenv ./helloenv -n helloenv \ --set ingress.enabled=true \ --set ingress.hosts[0].host=helloenv.example.com \ --set ingress.hosts[0].paths[0].path=/ \ - --set ingress.hosts[0].paths[0].pathType=Prefix \ No newline at end of file + --set ingress.hosts[0].paths[0].pathType=Prefix + +# For upgrade chart +helm upgrade helloenv . -n helloenv + +# For delete chart +helm uninstall helloenv -n helloenv \ No newline at end of file diff --git a/k8s/helm/values.yaml b/k8s/helm/values.yaml index fe7e9ee..6b49805 100644 --- a/k8s/helm/values.yaml +++ b/k8s/helm/values.yaml @@ -30,6 +30,8 @@ ingress: enabled: false className: "nginx" annotations: {} + # cert-manager.io/cluster-issuer: letsencrypt + # external-dns.alpha.kubernetes.io/hostname: helloenv.example.com hosts: - host: helloenv.example.com paths: