From 9a14ef4fd89e7218c38a7c1618bf67034e7c286a Mon Sep 17 00:00:00 2001 From: Utkarsh R Date: Fri, 5 Jul 2024 15:04:35 -0700 Subject: [PATCH] templating --- .../deployment.yaml} | 19 +----- manifest/base/kustomization.yaml | 5 ++ manifest/{service.yml => base/service.yaml} | 0 .../dev/deployment.yaml} | 4 +- manifest/overlays/dev/kustomization.yaml | 10 +++ my-app/.helmignore | 23 +++++++ my-app/Chart.yaml | 24 +++++++ my-app/templates/_helpers.tpl | 62 +++++++++++++++++++ my-app/templates/deployment.yaml | 24 +++++++ my-app/templates/service.yaml | 13 ++++ my-app/values.yaml | 3 + 11 files changed, 169 insertions(+), 18 deletions(-) rename manifest/{manifestfile.yml => base/deployment.yaml} (54%) create mode 100644 manifest/base/kustomization.yaml rename manifest/{service.yml => base/service.yaml} (100%) rename manifest/{deployment.yml => overlays/dev/deployment.yaml} (90%) create mode 100644 manifest/overlays/dev/kustomization.yaml create mode 100644 my-app/.helmignore create mode 100644 my-app/Chart.yaml create mode 100644 my-app/templates/_helpers.tpl create mode 100644 my-app/templates/deployment.yaml create mode 100644 my-app/templates/service.yaml create mode 100644 my-app/values.yaml diff --git a/manifest/manifestfile.yml b/manifest/base/deployment.yaml similarity index 54% rename from manifest/manifestfile.yml rename to manifest/base/deployment.yaml index 3b4db9e..3b713c6 100644 --- a/manifest/manifestfile.yml +++ b/manifest/base/deployment.yaml @@ -15,23 +15,10 @@ spec: app: my-app spec: containers: - - name: myapp - image: demolearnacr.azurecr.io/demo_dev/product_list_app: - imagePullPolicy: Always + - name: my-app + image: product-list-app:v1 + imagePullPolicy: IfNotPresent ports: - containerPort: 5070 imagePullSecrets: - name: my-secret - ---- -apiVersion: v1 -kind: Service -metadata: - name: my-app -spec: - selector: - app: my-app - ports: - - protocol: TCP - port: 5070 - targetPort: 5070 diff --git a/manifest/base/kustomization.yaml b/manifest/base/kustomization.yaml new file mode 100644 index 0000000..e387f4a --- /dev/null +++ b/manifest/base/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ./deployment.yaml + - ./service.yaml diff --git a/manifest/service.yml b/manifest/base/service.yaml similarity index 100% rename from manifest/service.yml rename to manifest/base/service.yaml diff --git a/manifest/deployment.yml b/manifest/overlays/dev/deployment.yaml similarity index 90% rename from manifest/deployment.yml rename to manifest/overlays/dev/deployment.yaml index 60b4fe7..a258c11 100644 --- a/manifest/deployment.yml +++ b/manifest/overlays/dev/deployment.yaml @@ -12,10 +12,10 @@ spec: template: metadata: labels: - app: my-appa + app: my-app spec: containers: - - name: myapp + - name: my-app image: demolearnacr.azurecr.io/demo_dev/product-list-app:v1 imagePullPolicy: IfNotPresent ports: diff --git a/manifest/overlays/dev/kustomization.yaml b/manifest/overlays/dev/kustomization.yaml new file mode 100644 index 0000000..5ac9940 --- /dev/null +++ b/manifest/overlays/dev/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../base +patches: + - path: deployment.yaml +images: + - name: demolearnacr.azurecr.io/demo_dev/product-list-app + newName: demolearnacr.azurecr.io/demo_dev/product-list-app + newTag: dev diff --git a/my-app/.helmignore b/my-app/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/my-app/.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/my-app/Chart.yaml b/my-app/Chart.yaml new file mode 100644 index 0000000..f2e9f20 --- /dev/null +++ b/my-app/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: my-app +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. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +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. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/my-app/templates/_helpers.tpl b/my-app/templates/_helpers.tpl new file mode 100644 index 0000000..da4015b --- /dev/null +++ b/my-app/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "my-app.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 "my-app.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 "my-app.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "my-app.labels" -}} +helm.sh/chart: {{ include "my-app.chart" . }} +{{ include "my-app.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "my-app.selectorLabels" -}} +app.kubernetes.io/name: {{ include "my-app.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "my-app.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "my-app.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/my-app/templates/deployment.yaml b/my-app/templates/deployment.yaml new file mode 100644 index 0000000..b277207 --- /dev/null +++ b/my-app/templates/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-app + labels: + app: my-app +spec: + replicas: 1 + selector: + matchLabels: + app: my-app + template: + metadata: + labels: + app: my-app + spec: + containers: + - name: my-app + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: IfNotPresent + ports: + - containerPort: 5070 + imagePullSecrets: + - name: my-secret diff --git a/my-app/templates/service.yaml b/my-app/templates/service.yaml new file mode 100644 index 0000000..58b0c0e --- /dev/null +++ b/my-app/templates/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: my-app +spec: + #type: NodePort + selector: + app.kubernetes.io/name: my-app + ports: + - protocol: TCP + port: 5070 + targetPort: 5070 + # nodePort: 30100 diff --git a/my-app/values.yaml b/my-app/values.yaml new file mode 100644 index 0000000..61d8087 --- /dev/null +++ b/my-app/values.yaml @@ -0,0 +1,3 @@ +image: + repository: product-list-app + tag: latest