From e4f3eedd621acc552f014e5babc3d66ea9c03675 Mon Sep 17 00:00:00 2001 From: ewk-elwa Date: Tue, 22 Apr 2025 14:05:17 -0700 Subject: [PATCH 1/8] Update guestbook-ui-deployment.yaml Change replicas to 3 --- guestbook/guestbook-ui-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guestbook/guestbook-ui-deployment.yaml b/guestbook/guestbook-ui-deployment.yaml index 8a0975e363..446900062e 100644 --- a/guestbook/guestbook-ui-deployment.yaml +++ b/guestbook/guestbook-ui-deployment.yaml @@ -3,7 +3,7 @@ kind: Deployment metadata: name: guestbook-ui spec: - replicas: 1 + replicas: 3 revisionHistoryLimit: 3 selector: matchLabels: From 149c2bee1cdbfe84541ebb2d28cd2c593195a2d3 Mon Sep 17 00:00:00 2001 From: ewk-elwa Date: Tue, 22 Apr 2025 14:11:42 -0700 Subject: [PATCH 2/8] Update guestbook-ui-deployment.yaml Trying nginx --- guestbook/guestbook-ui-deployment.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guestbook/guestbook-ui-deployment.yaml b/guestbook/guestbook-ui-deployment.yaml index 446900062e..4a8ccc6920 100644 --- a/guestbook/guestbook-ui-deployment.yaml +++ b/guestbook/guestbook-ui-deployment.yaml @@ -14,7 +14,8 @@ spec: app: guestbook-ui spec: containers: - - image: gcr.io/heptio-images/ks-guestbook-demo:0.2 + # - image: gcr.io/heptio-images/ks-guestbook-demo:0.2 + - image: nginx:stable-alpine3.20 name: guestbook-ui ports: - containerPort: 80 From 6eae9651f0bd6692539fd6e2d420b74923f31268 Mon Sep 17 00:00:00 2001 From: ewk-elwa Date: Tue, 22 Apr 2025 14:25:37 -0700 Subject: [PATCH 3/8] Update guestbook-ui-deployment.yaml --- guestbook/guestbook-ui-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guestbook/guestbook-ui-deployment.yaml b/guestbook/guestbook-ui-deployment.yaml index 4a8ccc6920..2ca87d23fd 100644 --- a/guestbook/guestbook-ui-deployment.yaml +++ b/guestbook/guestbook-ui-deployment.yaml @@ -3,7 +3,7 @@ kind: Deployment metadata: name: guestbook-ui spec: - replicas: 3 + replicas: 1 revisionHistoryLimit: 3 selector: matchLabels: From 2ae43beffad4d7ab2a8995c54aebd15313f9a31b Mon Sep 17 00:00:00 2001 From: ewk-elwa Date: Tue, 22 Apr 2025 15:09:33 -0700 Subject: [PATCH 4/8] Update guestbook-ui-deployment.yaml happy with 3 --- guestbook/guestbook-ui-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guestbook/guestbook-ui-deployment.yaml b/guestbook/guestbook-ui-deployment.yaml index 2ca87d23fd..4a8ccc6920 100644 --- a/guestbook/guestbook-ui-deployment.yaml +++ b/guestbook/guestbook-ui-deployment.yaml @@ -3,7 +3,7 @@ kind: Deployment metadata: name: guestbook-ui spec: - replicas: 1 + replicas: 3 revisionHistoryLimit: 3 selector: matchLabels: From 61a339c1e509a8794a5f826ebd12127033e3473d Mon Sep 17 00:00:00 2001 From: ewk-elwa Date: Thu, 24 Apr 2025 16:21:07 -0700 Subject: [PATCH 5/8] Update guestbook-ui-deployment.yaml --- guestbook/guestbook-ui-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guestbook/guestbook-ui-deployment.yaml b/guestbook/guestbook-ui-deployment.yaml index 4a8ccc6920..2ca87d23fd 100644 --- a/guestbook/guestbook-ui-deployment.yaml +++ b/guestbook/guestbook-ui-deployment.yaml @@ -3,7 +3,7 @@ kind: Deployment metadata: name: guestbook-ui spec: - replicas: 3 + replicas: 1 revisionHistoryLimit: 3 selector: matchLabels: From a4c3bd19b51922d8f464d8043f9c1af0871da9b3 Mon Sep 17 00:00:00 2001 From: ewk-elwa Date: Mon, 28 Apr 2025 15:13:21 -0700 Subject: [PATCH 6/8] Update guestbook-ui-deployment.yaml --- guestbook/guestbook-ui-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guestbook/guestbook-ui-deployment.yaml b/guestbook/guestbook-ui-deployment.yaml index 2ca87d23fd..4a8ccc6920 100644 --- a/guestbook/guestbook-ui-deployment.yaml +++ b/guestbook/guestbook-ui-deployment.yaml @@ -3,7 +3,7 @@ kind: Deployment metadata: name: guestbook-ui spec: - replicas: 1 + replicas: 3 revisionHistoryLimit: 3 selector: matchLabels: From 3e10f8ee27f23cb4b3523748ac8ff44cdbba0554 Mon Sep 17 00:00:00 2001 From: GitClient Date: Wed, 25 Jun 2025 17:59:44 -0700 Subject: [PATCH 7/8] Added simple webapp based on nginx --- nginx-webapp/.helmignore | 0 nginx-webapp/Chart.yaml | 17 ++ nginx-webapp/templates/NOTES.txt | 25 +++ nginx-webapp/templates/_helpers.tpl | 60 +++++++ nginx-webapp/templates/configmap.yaml | 11 ++ nginx-webapp/templates/deployment.yaml | 90 +++++++++++ nginx-webapp/templates/hpa.yaml | 24 +++ nginx-webapp/templates/ingress.yaml | 41 +++++ nginx-webapp/templates/service.yaml | 15 ++ nginx-webapp/templates/serviceaccount.yaml | 12 ++ nginx-webapp/values.yaml | 179 +++++++++++++++++++++ 11 files changed, 474 insertions(+) create mode 100644 nginx-webapp/.helmignore create mode 100644 nginx-webapp/Chart.yaml create mode 100644 nginx-webapp/templates/NOTES.txt create mode 100644 nginx-webapp/templates/_helpers.tpl create mode 100644 nginx-webapp/templates/configmap.yaml create mode 100644 nginx-webapp/templates/deployment.yaml create mode 100644 nginx-webapp/templates/hpa.yaml create mode 100644 nginx-webapp/templates/ingress.yaml create mode 100644 nginx-webapp/templates/service.yaml create mode 100644 nginx-webapp/templates/serviceaccount.yaml create mode 100644 nginx-webapp/values.yaml diff --git a/nginx-webapp/.helmignore b/nginx-webapp/.helmignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/nginx-webapp/Chart.yaml b/nginx-webapp/Chart.yaml new file mode 100644 index 0000000000..08e1886ebf --- /dev/null +++ b/nginx-webapp/Chart.yaml @@ -0,0 +1,17 @@ +apiVersion: v2 +name: nginx-webapp +description: A Helm chart for deploying a simple nginx web application +type: application +version: 0.1.0 +appVersion: "1.25.3" +keywords: + - nginx + - web + - frontend +home: https://github.com/your-org/nginx-webapp +sources: + - https://github.com/your-org/nginx-webapp +maintainers: + - name: Your Name + email: your.email@company.com +dependencies: [] \ No newline at end of file diff --git a/nginx-webapp/templates/NOTES.txt b/nginx-webapp/templates/NOTES.txt new file mode 100644 index 0000000000..ca50ae6a70 --- /dev/null +++ b/nginx-webapp/templates/NOTES.txt @@ -0,0 +1,25 @@ +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 "nginx-webapp.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 "nginx-webapp.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "nginx-webapp.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 "nginx-webapp.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 }} + +2. Check the health endpoint: + curl http://your-app-url/health \ No newline at end of file diff --git a/nginx-webapp/templates/_helpers.tpl b/nginx-webapp/templates/_helpers.tpl new file mode 100644 index 0000000000..1f67e3ac9f --- /dev/null +++ b/nginx-webapp/templates/_helpers.tpl @@ -0,0 +1,60 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "nginx-webapp.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +*/}} +{{- define "nginx-webapp.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 "nginx-webapp.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "nginx-webapp.labels" -}} +helm.sh/chart: {{ include "nginx-webapp.chart" . }} +{{ include "nginx-webapp.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "nginx-webapp.selectorLabels" -}} +app.kubernetes.io/name: {{ include "nginx-webapp.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "nginx-webapp.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "nginx-webapp.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/nginx-webapp/templates/configmap.yaml b/nginx-webapp/templates/configmap.yaml new file mode 100644 index 0000000000..1752998a5d --- /dev/null +++ b/nginx-webapp/templates/configmap.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "nginx-webapp.fullname" . }}-config + labels: + {{- include "nginx-webapp.labels" . | nindent 4 }} +data: + nginx.conf: | + {{- .Values.nginx.config | nindent 4 }} + index.html: | + {{- .Values.nginx.html | nindent 4 }} \ No newline at end of file diff --git a/nginx-webapp/templates/deployment.yaml b/nginx-webapp/templates/deployment.yaml new file mode 100644 index 0000000000..dd76528dec --- /dev/null +++ b/nginx-webapp/templates/deployment.yaml @@ -0,0 +1,90 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "nginx-webapp.fullname" . }} + labels: + {{- include "nginx-webapp.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "nginx-webapp.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "nginx-webapp.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "nginx-webapp.serviceAccountName" . }} + 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: http + containerPort: 8080 + protocol: TCP + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: nginx-config + mountPath: /etc/nginx/nginx.conf + subPath: nginx.conf + readOnly: true + - name: nginx-html + mountPath: /usr/share/nginx/html/index.html + subPath: index.html + readOnly: true + - name: nginx-cache + mountPath: /var/cache/nginx + - name: nginx-run + mountPath: /var/run + - name: nginx-logs + mountPath: /var/log/nginx + - name: tmp-volume + mountPath: /tmp + volumes: + - name: nginx-config + configMap: + name: {{ include "nginx-webapp.fullname" . }}-config + - name: nginx-html + configMap: + name: {{ include "nginx-webapp.fullname" . }}-config + - name: nginx-cache + emptyDir: {} + - name: nginx-run + emptyDir: {} + - name: nginx-logs + emptyDir: {} + - name: tmp-volume + emptyDir: {} + {{- 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/nginx-webapp/templates/hpa.yaml b/nginx-webapp/templates/hpa.yaml new file mode 100644 index 0000000000..f3493a2db3 --- /dev/null +++ b/nginx-webapp/templates/hpa.yaml @@ -0,0 +1,24 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "nginx-webapp.fullname" . }} + labels: + {{- include "nginx-webapp.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "nginx-webapp.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/nginx-webapp/templates/ingress.yaml b/nginx-webapp/templates/ingress.yaml new file mode 100644 index 0000000000..7791fd4079 --- /dev/null +++ b/nginx-webapp/templates/ingress.yaml @@ -0,0 +1,41 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "nginx-webapp.fullname" . }} + labels: + {{- include "nginx-webapp.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.className }} + 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 }} + pathType: {{ .pathType }} + backend: + service: + name: {{ include "nginx-webapp.fullname" $ }} + port: + number: {{ $.Values.service.port }} + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/nginx-webapp/templates/service.yaml b/nginx-webapp/templates/service.yaml new file mode 100644 index 0000000000..7c3eb85c5f --- /dev/null +++ b/nginx-webapp/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "nginx-webapp.fullname" . }} + labels: + {{- include "nginx-webapp.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.targetPort }} + protocol: TCP + name: http + selector: + {{- include "nginx-webapp.selectorLabels" . | nindent 4 }} \ No newline at end of file diff --git a/nginx-webapp/templates/serviceaccount.yaml b/nginx-webapp/templates/serviceaccount.yaml new file mode 100644 index 0000000000..f2bf5d7534 --- /dev/null +++ b/nginx-webapp/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "nginx-webapp.serviceAccountName" . }} + labels: + {{- include "nginx-webapp.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/nginx-webapp/values.yaml b/nginx-webapp/values.yaml new file mode 100644 index 0000000000..b790e2f9c0 --- /dev/null +++ b/nginx-webapp/values.yaml @@ -0,0 +1,179 @@ +# Default values for nginx-webapp +replicaCount: 2 + +image: + repository: nginx + pullPolicy: IfNotPresent + tag: "1.25.3-alpine" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: true + annotations: {} + name: "" + +podAnnotations: {} + +podSecurityContext: + fsGroup: 101 + runAsNonRoot: true + runAsUser: 101 + +securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + readOnlyRootFilesystem: true + runAsNonRoot: true + runAsUser: 101 + +service: + type: ClusterIP + port: 80 + targetPort: 8080 + +ingress: + enabled: false + className: "" + annotations: {} + hosts: + - host: webapp.example.com + paths: + - path: / + pathType: Prefix + tls: [] + +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 50m + memory: 64Mi + +autoscaling: + enabled: false + minReplicas: 2 + maxReplicas: 10 + targetCPUUtilizationPercentage: 80 + +nodeSelector: {} +tolerations: [] +affinity: {} + +# Nginx configuration +nginx: + config: | + user nginx; + worker_processes auto; + error_log /var/log/nginx/error.log notice; + pid /var/run/nginx.pid; + + + events { + worker_connections 1024; + } + + http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + server { + listen 8080; + server_name _; + root /usr/share/nginx/html; + index index.html index.htm; + + location / { + try_files $uri $uri/ =404; + } + + location /health { + access_log off; + return 200 "healthy\n"; + add_header Content-Type text/plain; + } + } + } + + # Custom HTML content + html: | + + + + Simple Web App + + + +
+

Welcome to Simple Web App

+
+

Application Information

+

Server: Nginx

+

Deployment: Kubernetes with Helm

+

Status: Running

+
+

This is a simple web application deployed using Helm chart with nginx.

+

Health check endpoint: /health

+
+ + + +# Probes configuration +livenessProbe: + httpGet: + path: /health + port: http + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + +readinessProbe: + httpGet: + path: /health + port: http + initialDelaySeconds: 5 + periodSeconds: 5 + timeoutSeconds: 3 + failureThreshold: 3 \ No newline at end of file From 96505253ba6bc23eb68d00a9ba312c54b30b4e3d Mon Sep 17 00:00:00 2001 From: GitClient Date: Wed, 25 Jun 2025 18:03:24 -0700 Subject: [PATCH 8/8] Resolved conflict --- guestbook/guestbook-ui-deployment.yaml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/guestbook/guestbook-ui-deployment.yaml b/guestbook/guestbook-ui-deployment.yaml index 4a8ccc6920..09c573419d 100644 --- a/guestbook/guestbook-ui-deployment.yaml +++ b/guestbook/guestbook-ui-deployment.yaml @@ -3,7 +3,7 @@ kind: Deployment metadata: name: guestbook-ui spec: - replicas: 3 + replicas: 1 revisionHistoryLimit: 3 selector: matchLabels: @@ -14,8 +14,7 @@ spec: app: guestbook-ui spec: containers: - # - image: gcr.io/heptio-images/ks-guestbook-demo:0.2 - - image: nginx:stable-alpine3.20 - name: guestbook-ui - ports: - - containerPort: 80 + - image: gcr.io/google-samples/gb-frontend:v5 + name: guestbook-ui + ports: + - containerPort: 80 \ No newline at end of file