From ccd67f2ff74073454515a24fdfcf17de8efb9b33 Mon Sep 17 00:00:00 2001
From: rjshrjndrn <rjshrjndrn@gmail.com>
Date: Tue, 26 Nov 2019 16:25:45 +0530
Subject: [PATCH] Issue #000 feat: helm chart for 3 node private-ingress

---
 .../nginx-private-ingress/.helmignore         | 22 +++++++
 .../nginx-private-ingress/Chart.yaml          | 21 +++++++
 .../nginx-private-ingress/templates/NOTES.txt | 21 +++++++
 .../templates/_helpers.tpl                    | 63 +++++++++++++++++++
 .../templates/configMap.yaml                  | 24 +++++++
 .../templates/deployment.yaml                 | 45 +++++++++++++
 .../templates/service.yaml                    | 15 +++++
 .../templates/serviceaccount.yaml             |  8 +++
 8 files changed, 219 insertions(+)
 create mode 100644 3node/helm-charts/nginx-private-ingress/.helmignore
 create mode 100644 3node/helm-charts/nginx-private-ingress/Chart.yaml
 create mode 100644 3node/helm-charts/nginx-private-ingress/templates/NOTES.txt
 create mode 100644 3node/helm-charts/nginx-private-ingress/templates/_helpers.tpl
 create mode 100644 3node/helm-charts/nginx-private-ingress/templates/configMap.yaml
 create mode 100644 3node/helm-charts/nginx-private-ingress/templates/deployment.yaml
 create mode 100644 3node/helm-charts/nginx-private-ingress/templates/service.yaml
 create mode 100644 3node/helm-charts/nginx-private-ingress/templates/serviceaccount.yaml

diff --git a/3node/helm-charts/nginx-private-ingress/.helmignore b/3node/helm-charts/nginx-private-ingress/.helmignore
new file mode 100644
index 000000000..50af03172
--- /dev/null
+++ b/3node/helm-charts/nginx-private-ingress/.helmignore
@@ -0,0 +1,22 @@
+# 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
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
+.vscode/
diff --git a/3node/helm-charts/nginx-private-ingress/Chart.yaml b/3node/helm-charts/nginx-private-ingress/Chart.yaml
new file mode 100644
index 000000000..eef349c8e
--- /dev/null
+++ b/3node/helm-charts/nginx-private-ingress/Chart.yaml
@@ -0,0 +1,21 @@
+apiVersion: v2
+name: private-ingress
+description: A Helm chart for Kubernetes
+
+# A chart can be either an 'application' or a 'library' chart.
+#
+# Application charts are a collection of templates that can be packaged into versioned archives
+# to be deployed.
+#
+# Library charts provide useful utilities or functions for the chart developer. They're included as
+# a dependency of application charts to inject those utilities and functions into the rendering
+# pipeline. Library charts do not define any templates and therefore cannot be deployed.
+type: application
+
+# This is the chart version. This version number should be incremented each time you make changes
+# to the chart and its templates, including the app version.
+version: 0.1.0
+
+# This is the version number of the application being deployed. This version number should be
+# incremented each time you make changes to the application.
+appVersion: 1.16.0
diff --git a/3node/helm-charts/nginx-private-ingress/templates/NOTES.txt b/3node/helm-charts/nginx-private-ingress/templates/NOTES.txt
new file mode 100644
index 000000000..efc095b6b
--- /dev/null
+++ b/3node/helm-charts/nginx-private-ingress/templates/NOTES.txt
@@ -0,0 +1,21 @@
+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 }}{{ . }}
+  {{- 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 "private-ingress.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 "private-ingress.fullname" . }}'
+  export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "private-ingress.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 "private-ingress.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
+  echo "Visit http://127.0.0.1:8080 to use your application"
+  kubectl port-forward $POD_NAME 8080:80
+{{- end }}
diff --git a/3node/helm-charts/nginx-private-ingress/templates/_helpers.tpl b/3node/helm-charts/nginx-private-ingress/templates/_helpers.tpl
new file mode 100644
index 000000000..e910d49f3
--- /dev/null
+++ b/3node/helm-charts/nginx-private-ingress/templates/_helpers.tpl
@@ -0,0 +1,63 @@
+{{/* vim: set filetype=mustache: */}}
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "private-ingress.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 "private-ingress.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 "private-ingress.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
+
+{{/*
+Common labels
+*/}}
+{{- define "private-ingress.labels" -}}
+helm.sh/chart: {{ include "private-ingress.chart" . }}
+{{ include "private-ingress.selectorLabels" . }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end -}}
+
+{{/*
+Selector labels
+*/}}
+{{- define "private-ingress.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "private-ingress.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+{{- end -}}
+
+{{/*
+Create the name of the service account to use
+*/}}
+{{- define "private-ingress.serviceAccountName" -}}
+{{- if .Values.serviceAccount.create -}}
+    {{ default (include "private-ingress.fullname" .) .Values.serviceAccount.name }}
+{{- else -}}
+    {{ default "default" .Values.serviceAccount.name }}
+{{- end -}}
+{{- end -}}
diff --git a/3node/helm-charts/nginx-private-ingress/templates/configMap.yaml b/3node/helm-charts/nginx-private-ingress/templates/configMap.yaml
new file mode 100644
index 000000000..cef71c1e7
--- /dev/null
+++ b/3node/helm-charts/nginx-private-ingress/templates/configMap.yaml
@@ -0,0 +1,24 @@
+apiVersion: v1
+data:
+  default.conf: |
+    server {
+      listen 80;
+      listen [::]:80;
+
+      location /learner/ {
+        rewrite ^/learner/(.*) /$1 break;
+        proxy_pass http://learner;
+      }
+      location /api/ {
+        rewrite ^/api/(.*) /$1 break;
+        proxy_pass http://apimanager-service:8000;
+      }
+      location /admin-api/ {
+        rewrite ^/admin-api/(.*) /$1 break;
+        proxy_pass http://apimanager-service:8001;
+      }
+    }
+kind: ConfigMap
+metadata:
+  creationTimestamp: null
+  name: private-ingress.conf
diff --git a/3node/helm-charts/nginx-private-ingress/templates/deployment.yaml b/3node/helm-charts/nginx-private-ingress/templates/deployment.yaml
new file mode 100644
index 000000000..6b28dc694
--- /dev/null
+++ b/3node/helm-charts/nginx-private-ingress/templates/deployment.yaml
@@ -0,0 +1,45 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: private-ingress
+  namespace: dev
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: private-ingress
+  template:
+    metadata:
+      labels:
+        app: private-ingress
+    volumes:
+      - name: config-volume
+        configMap:
+          name: private-ingress.conf
+    spec:
+      containers:
+      - name: name
+        image: nginx
+        resources:
+          requests:
+            cpu: 100m
+            memory: 200Mi
+        ports:
+        - containerPort: 80
+        volumeMounts:
+        - mountPath: /etc/nginx/conf.d/
+          name: config-volume
+          readOnly: true
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: private-ingress
+  namespace: dev
+spec:
+  type: LoadBalancer
+  ports:
+  - port: 80
+    targetPort: 80
+  selector:
+    app: private-ingress
diff --git a/3node/helm-charts/nginx-private-ingress/templates/service.yaml b/3node/helm-charts/nginx-private-ingress/templates/service.yaml
new file mode 100644
index 000000000..d2126e459
--- /dev/null
+++ b/3node/helm-charts/nginx-private-ingress/templates/service.yaml
@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ include "private-ingress.fullname" . }}
+  labels:
+    {{- include "private-ingress.labels" . | nindent 4 }}
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+    - port: {{ .Values.service.port }}
+      targetPort: http
+      protocol: TCP
+      name: http
+  selector:
+    {{- include "private-ingress.selectorLabels" . | nindent 4 }}
diff --git a/3node/helm-charts/nginx-private-ingress/templates/serviceaccount.yaml b/3node/helm-charts/nginx-private-ingress/templates/serviceaccount.yaml
new file mode 100644
index 000000000..d25346fa6
--- /dev/null
+++ b/3node/helm-charts/nginx-private-ingress/templates/serviceaccount.yaml
@@ -0,0 +1,8 @@
+{{- if .Values.serviceAccount.create -}}
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: {{ include "private-ingress.serviceAccountName" . }}
+  labels:
+{{ include "private-ingress.labels" . | nindent 4 }}
+{{- end -}}
-- 
GitLab