From c84ddb7f40d4549e57f108319b861a5d3df8557e Mon Sep 17 00:00:00 2001 From: eiximenis Date: Thu, 14 Jun 2018 16:30:29 +0200 Subject: [PATCH] Identity api some refactor on common templates --- k8s/helm/app.yaml | 28 +++++-- k8s/helm/identity-api/.helmignore | 21 ++++++ k8s/helm/identity-api/Chart.yaml | 5 ++ k8s/helm/identity-api/templates/NOTES.txt | 19 +++++ k8s/helm/identity-api/templates/_helpers.tpl | 32 ++++++++ k8s/helm/identity-api/templates/_names.tpl | 37 ++++++++++ .../identity-api/templates/configmap.yaml | 36 +++++++++ .../identity-api/templates/deployment.yaml | 73 +++++++++++++++++++ k8s/helm/identity-api/templates/ingress.yaml | 38 ++++++++++ k8s/helm/identity-api/templates/service.yaml | 19 +++++ k8s/helm/identity-api/values.yaml | 64 ++++++++++++++++ k8s/helm/inf.yaml | 8 +- 12 files changed, 374 insertions(+), 6 deletions(-) create mode 100644 k8s/helm/identity-api/.helmignore create mode 100644 k8s/helm/identity-api/Chart.yaml create mode 100644 k8s/helm/identity-api/templates/NOTES.txt create mode 100644 k8s/helm/identity-api/templates/_helpers.tpl create mode 100644 k8s/helm/identity-api/templates/_names.tpl create mode 100644 k8s/helm/identity-api/templates/configmap.yaml create mode 100644 k8s/helm/identity-api/templates/deployment.yaml create mode 100644 k8s/helm/identity-api/templates/ingress.yaml create mode 100644 k8s/helm/identity-api/templates/service.yaml create mode 100644 k8s/helm/identity-api/values.yaml diff --git a/k8s/helm/app.yaml b/k8s/helm/app.yaml index 92a878363..946a6f594 100644 --- a/k8s/helm/app.yaml +++ b/k8s/helm/app.yaml @@ -1,7 +1,25 @@ # This heml values file defines app-based settings -# Charts use those values, so this file must be included in all chart releases +# Charts use those values, so this file **MUST** be included in all chart releases -app: - name: "my-eshop" # Override for custom application names. - ingress: - suffix: false # if true ingress endpoints are suffixed with .Values.appName value (or .Release.Name if the 1st do not exist) \ No newline at end of file + +app: # app global settings + name: "my-eshop" # Override for custom app name + ingress: # ingress related settings + suffix: false # if true ingress endpoints are suffixed with .Values.appName value (or .Release.Name if the 1st do not exist) + entries: + basket: basket-api # ingress entry for basket api + catalog: catalog-api # ingress entry for catalog api + ordering: ordering-api # ingress entry for ordering api + identity: identity # ingress entry for identity api + mvc: webmvc # ingress entry for web mvc + spa: webspa # ingress entry for web spa + status: webstatus # ingress entry for web status + webshoppingapigw: webshoppingapigw # ingress entry for web shopping Agw + webmarketingapigw: webmarketingapigw # ingress entry for web mkg Agw + mobilemarketingapigw: mobilemarketingapigw # ingress entry for mobile mkg Agw + mobileshoppingapigw: mobileshoppingapigw # ingress entry for mobile shopping Agw + webshoppingagg: webshoppingagg # ingress entry for web shopping aggregator + mobileshoppingagg: mobileshoppingagg # ingress entry for mobile shopping aggregator + payment: payment-api # ingress entry for payment api + locations: locations-api # ingress entry for locations api + marketing: marketing-api # ingress entry for marketing api diff --git a/k8s/helm/identity-api/.helmignore b/k8s/helm/identity-api/.helmignore new file mode 100644 index 000000000..f0c131944 --- /dev/null +++ b/k8s/helm/identity-api/.helmignore @@ -0,0 +1,21 @@ +# 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 diff --git a/k8s/helm/identity-api/Chart.yaml b/k8s/helm/identity-api/Chart.yaml new file mode 100644 index 000000000..7b9290ada --- /dev/null +++ b/k8s/helm/identity-api/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: identity-api +version: 0.1.0 diff --git a/k8s/helm/identity-api/templates/NOTES.txt b/k8s/helm/identity-api/templates/NOTES.txt new file mode 100644 index 000000000..a232b3af6 --- /dev/null +++ b/k8s/helm/identity-api/templates/NOTES.txt @@ -0,0 +1,19 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range .Values.ingress.hosts }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "identity-api.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 svc -w {{ template "identity-api.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "identity-api.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + 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={{ template "identity-api.name" . }},release={{ .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/k8s/helm/identity-api/templates/_helpers.tpl b/k8s/helm/identity-api/templates/_helpers.tpl new file mode 100644 index 000000000..fb47187b4 --- /dev/null +++ b/k8s/helm/identity-api/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "identity-api.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 "identity-api.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 "identity-api.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/k8s/helm/identity-api/templates/_names.tpl b/k8s/helm/identity-api/templates/_names.tpl new file mode 100644 index 000000000..bbf3888d5 --- /dev/null +++ b/k8s/helm/identity-api/templates/_names.tpl @@ -0,0 +1,37 @@ +{{- define "suffix-name" -}} +{{- if .Values.app.name -}} +{{- .Values.app.name -}} +{{- else -}} +{{- .Release.Name -}} +{{- end -}} +{{- end -}} + +{{- define "sql-name" -}} +{{- if .Values.inf.sql.host -}} +{{- .Values.inf.sql.host -}} +{{- else -}} +{{- printf "%s" "sql-data" -}} +{{- end -}} +{{- end -}} + +{{- define "url-of" -}} +{{- $name := first .}} +{{- $ctx := last .}} +{{- if $ctx.Values.app.ingress.suffix -}} +{{- $suffix := include "suffix-name" $ctx -}} +{{- printf "%s/%s-%s" $ctx.Values.inf.k8s.dns $name $suffix -}} +{{- else -}} +{{- printf "%s/%s" $ctx.Values.inf.k8s.dns $name -}} +{{- end -}} +{{- end -}} + + + +{{ define "pathBase" -}} +{{- if .Values.app.ingress.suffix -}} +{{- $suffix := include "suffix-name" . -}} +{{- printf "%s-%s" .Values.pathBase $suffix -}} +{{- else -}} +{{- .Values.pathBase -}} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/k8s/helm/identity-api/templates/configmap.yaml b/k8s/helm/identity-api/templates/configmap.yaml new file mode 100644 index 000000000..d3dd2b9a7 --- /dev/null +++ b/k8s/helm/identity-api/templates/configmap.yaml @@ -0,0 +1,36 @@ +{{- $name := include "identity-api.fullname" . -}} +{{- $sqlsrv := include "sql-name" . -}} +{{- $mvc_url := include "url-of" (list .Values.app.ingress.entries.mvc .) -}} +{{- $spa_url := include "url-of" (list .Values.app.ingress.entries.spa .) -}} +{{- $locations_url := include "url-of" (list .Values.app.ingress.entries.locations .) -}} +{{- $marketing_url := include "url-of" (list .Values.app.ingress.entries.marketing .) -}} +{{- $basket_url := include "url-of" (list .Values.app.ingress.entries.basket .) -}} +{{- $ordering_url := include "url-of" (list .Values.app.ingress.entries.ordering .) -}} +{{- $mobileshoppingagg := include "url-of" (list .Values.app.ingress.entries.mobileshoppingagg .) -}} +{{- $webhoppingagg := include "url-of" (list .Values.app.ingress.entries.webshoppingagg .) -}} +{{- $xamarincallback := include "url-of" (list "xamarincallback" .) -}} + + +apiVersion: v1 +kind: ConfigMap +metadata: + name: "cfg-{{ $name }}" + labels: + app: {{ template "identity-api.name" . }} + chart: {{ template "identity-api.chart" .}} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +data: + identity__ConnectionString: Server={{ $sqlsrv }};Initial Catalog={{ .Values.inf.sql.identity.db }};User Id={{ .Values.inf.sql.identity.user }};Password={{ .Values.inf.sql.identity.pwd }}; + identity__keystore: http://{{ .Values.inf.redis.keystore.constr }} + all__InstrumentationKey: http://{{ .Values.inf.appinsights.key }} + mvc_e: http://{{ $mvc_url }} + spa_e: http://{{ $spa_url }} + locations_e: http://{{ $locations_url }} + marketing_e: http://{{ $marketing_url }} + basket_e: http://{{ $basket_url }} + ordering_e: http://{{ $ordering_url }} + mobileshoppingagg_e: http://{{ $mobileshoppingagg }} + webshoppingagg_e: http://{{ $webhoppingagg }} + xamarin_callback_e: http://{{ $xamarincallback }} + diff --git a/k8s/helm/identity-api/templates/deployment.yaml b/k8s/helm/identity-api/templates/deployment.yaml new file mode 100644 index 000000000..6cd425afd --- /dev/null +++ b/k8s/helm/identity-api/templates/deployment.yaml @@ -0,0 +1,73 @@ +{{- $name := include "identity-api.fullname" . -}} +{{- $cfgname := printf "%s-%s" "cfg" $name -}} +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: {{ template "identity-api.fullname" . }} + labels: + ufo: {{ $cfgname}} + app: {{ template "identity-api.name" . }} + chart: {{ template "identity-api.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ template "identity-api.name" . }} + release: {{ .Release.Name }} + template: + metadata: + labels: + app: {{ template "identity-api.name" . }} + release: {{ .Release.Name }} + spec: + {{ if .Values.imagePullSecrets -}} + imagePullSecrets: + {{ range .Values.imagePullSecrets -}} + - name: {{ .name }} + {{- end -}} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: PATH_BASE + value: {{ include "pathBase" . }} + - name: k8sname + value: {{ .Values.clusterName }} + {{- if .Values.env.values -}} + {{- range .Values.env.values }} + - name: {{ .name }} + value: {{ .value | quote }} + {{- end -}} + {{- end -}} + {{- if .Values.env.configmap -}} + {{- range .Values.env.configmap }} + - name: {{ .name }} + valueFrom: + configMapKeyRef: + name: {{ $cfgname }} + key: {{ .key }} + {{- end -}} + {{- end }} + ports: + - name: http + containerPort: 80 + protocol: TCP + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: +{{ toYaml . | indent 8 }} + {{- end }} + diff --git a/k8s/helm/identity-api/templates/ingress.yaml b/k8s/helm/identity-api/templates/ingress.yaml new file mode 100644 index 000000000..40822737c --- /dev/null +++ b/k8s/helm/identity-api/templates/ingress.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "identity-api.fullname" . -}} +{{- $ingressPath := include "pathBase" . -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + app: {{ template "identity-api.name" . }} + chart: {{ template "identity-api.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +{{- with .Values.ingress.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . }} + http: + paths: + - path: {{ $ingressPath }} + backend: + serviceName: {{ $fullName }} + servicePort: http + {{- end }} +{{- end }} diff --git a/k8s/helm/identity-api/templates/service.yaml b/k8s/helm/identity-api/templates/service.yaml new file mode 100644 index 000000000..406bb3544 --- /dev/null +++ b/k8s/helm/identity-api/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "identity-api.fullname" . }} + labels: + app: {{ template "identity-api.name" . }} + chart: {{ template "identity-api.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app: {{ template "identity-api.name" . }} + release: {{ .Release.Name }} diff --git a/k8s/helm/identity-api/values.yaml b/k8s/helm/identity-api/values.yaml new file mode 100644 index 000000000..77609b12b --- /dev/null +++ b/k8s/helm/identity-api/values.yaml @@ -0,0 +1,64 @@ +replicaCount: 1 +clusterName: eshop-aks +pathBase: /identity + +image: + repository: eshop/ordering.backgroundtasks + tag: latest + pullPolicy: IfNotPresent + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + hosts: + - chart-example.local + tls: [] + +resources: {} + + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +env: + urls: + configmap: + - name: ConnectionString + key: identity__ConnectionString + - name: DPConnectionString + key: identity__keystore + - name: ApplicationInsights__InstrumentationKey + key: all__InstrumentationKey + - name: MvcClient + key: mvc_e + - name: SpaClient + key: spa_e + - name: LocationApiClient + key: locations_e + - name: MarketingApiClient + key: marketing_e + - name: BasketApiClient + key: basket_e + - name: OrderingApiClient + key: ordering_e + - name: MobileShoppingAggClient + key: mobileshoppingagg_e + - name: WebShoppingAggClient + key: webshoppingagg_e + - name: XamarinCallback + key: xamarin_callback_e + values: + - name: ASPNETCORE_ENVIRONMENT + value: Development + - name: OrchestratorType + value: 'K8S' + - name: IsClusterEnv + value: 'True' + diff --git a/k8s/helm/inf.yaml b/k8s/helm/inf.yaml index bc91749a1..04814a97b 100644 --- a/k8s/helm/inf.yaml +++ b/k8s/helm/inf.yaml @@ -1,5 +1,5 @@ # This heml values file defines all infrastructure used by eShopOnContainers. -# Any chart redefines its needed part, but this file allows an easy override of the whole infrastructure settings +# It is used on all charts, so ** MUST BE INCLUDED ** on every deployment inf: sql: # inf.sql defines the sql server databases & logins @@ -12,9 +12,15 @@ inf: user: sa # Ordering API SQL user pwd: Pass@word # Ordering API SQL pwd db: OrderingDb # Ordering API SQL db name + identity: + user: sa # Ordering API SQL user + pwd: Pass@word # Ordering API SQL pwd + db: IdentityDb # Ordering API SQL db name redis: # inf.redis defines the redis' connection strings basket: constr: basket-data # Connection string to Redis used by Basket API + keystore: + constr: keystore-data # Connection string to Redis used as a Keystore (by Identity API) eventbus: constr: rabbitmq # Event bus connection strin g useAzure: false # true if use Azure Service Bus. False if RabbitMQ