Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions k8s/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions k8s/helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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

# For upgrade chart
helm upgrade helloenv . -n helloenv

# For delete chart
helm uninstall helloenv -n helloenv
7 changes: 7 additions & 0 deletions k8s/helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -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).
26 changes: 26 additions & 0 deletions k8s/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
10 changes: 10 additions & 0 deletions k8s/helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
97 changes: 97 additions & 0 deletions k8s/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
22 changes: 22 additions & 0 deletions k8s/helm/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
35 changes: 35 additions & 0 deletions k8s/helm/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
14 changes: 14 additions & 0 deletions k8s/helm/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
16 changes: 16 additions & 0 deletions k8s/helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions k8s/helm/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
109 changes: 109 additions & 0 deletions k8s/helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
image:
repository: ghcr.io/nikodevops/helloenv
tag: "latest"
pullPolicy: IfNotPresent
pullSecrets: []

replicaCount: 2

serviceAccount:
create: true
name: ""
annotations: {}
automount: false

autoscaling:
enabled: false
minReplicas: 2
maxReplicas: 5
targetCPUUtilizationPercentage: 70

pdb:
enabled: false
minAvailable: 1

service:
type: ClusterIP
port: 80

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:
- 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
Loading