Skip to content

Commit e6628f1

Browse files
committed
marketing api chart helm
1 parent 68d753d commit e6628f1

10 files changed

Lines changed: 329 additions & 0 deletions

File tree

k8s/helm/marketing-api/.helmignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj

k8s/helm/marketing-api/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
appVersion: "1.0"
3+
description: A Helm chart for Kubernetes
4+
name: marketing-api
5+
version: 0.1.0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range .Values.ingress.hosts }}
4+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }}
5+
{{- end }}
6+
{{- else if contains "NodePort" .Values.service.type }}
7+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "marketing-api.fullname" . }})
8+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
9+
echo http://$NODE_IP:$NODE_PORT
10+
{{- else if contains "LoadBalancer" .Values.service.type }}
11+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
12+
You can watch the status of by running 'kubectl get svc -w {{ template "marketing-api.fullname" . }}'
13+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "marketing-api.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
14+
echo http://$SERVICE_IP:{{ .Values.service.port }}
15+
{{- else if contains "ClusterIP" .Values.service.type }}
16+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "marketing-api.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
17+
echo "Visit http://127.0.0.1:8080 to use your application"
18+
kubectl port-forward $POD_NAME 8080:80
19+
{{- end }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "marketing-api.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "marketing-api.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "marketing-api.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{{- define "suffix-name" -}}
2+
{{- if .Values.app.name -}}
3+
{{- .Values.app.name -}}
4+
{{- else -}}
5+
{{- .Release.Name -}}
6+
{{- end -}}
7+
{{- end -}}
8+
9+
{{- define "sql-name" -}}
10+
{{- if .Values.inf.sql.host -}}
11+
{{- .Values.inf.sql.host -}}
12+
{{- else -}}
13+
{{- printf "%s" "sql-data" -}}
14+
{{- end -}}
15+
{{- end -}}
16+
17+
{{- define "mongo-name" -}}
18+
{{- if .Values.inf.mongo.host -}}
19+
{{- .Values.inf.mongo.host -}}
20+
{{- else -}}
21+
{{- printf "%s" "nosql-data" -}}
22+
{{- end -}}
23+
{{- end -}}
24+
25+
{{- define "url-of" -}}
26+
{{- $name := first .}}
27+
{{- $ctx := last .}}
28+
{{- $suffix := include "suffix-name" $ctx -}}
29+
{{- if $ctx.Values.inf.k8s.dnsprefix -}}
30+
{{- printf "%s.%s/%s" $suffix $ctx.Values.inf.k8s.dns $name -}} # Value is <prefix>.<dns>/<name>
31+
{{- else -}}
32+
{{- if $ctx.Values.inf.k8s.suffix -}}
33+
{{- printf "%s/%s-%s" $ctx.Values.inf.k8s.dns $name $suffix -}} # Value is <dns>/<name>-<sufix>
34+
{{- else -}}
35+
{{- printf "%s/%s" $ctx.Values.inf.k8s.dns $name -}} # Value is just <dns>/<name>
36+
{{- end -}}
37+
{{- end -}}
38+
{{- end -}}
39+
40+
41+
42+
{{ define "pathBase" -}}
43+
{{- if .Values.inf.k8s.suffix -}}
44+
{{- $suffix := include "suffix-name" . -}}
45+
{{- printf "%s-%s" .Values.pathBase $suffix -}}
46+
{{- else -}}
47+
{{- .Values.pathBase -}}
48+
{{- end -}}
49+
{{- end -}}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{- $name := include "marketing-api.fullname" . -}}
2+
{{- $identity := include "url-of" (list .Values.app.ingress.entries.identity .) -}}
3+
{{- $mongo := include "mongo-name" . -}}
4+
5+
apiVersion: v1
6+
kind: ConfigMap
7+
metadata:
8+
name: "cfg-{{ $name }}"
9+
labels:
10+
app: {{ template "marketing-api.name" . }}
11+
chart: {{ template "marketing-api.chart" .}}
12+
release: {{ .Release.Name }}
13+
heritage: {{ .Release.Service }}
14+
data:
15+
all__EventBusConnection: {{ .Values.inf.eventbus.constr }}
16+
all__InstrumentationKey: {{ .Values.inf.appinsights.key }}
17+
all__UseAzureServiceBus: "{{ .Values.inf.eventbus.useAzure }}"
18+
all_EnableLoadTest: "{{ .Values.inf.misc.useLoadTest }}"
19+
internalurls__IdentityUrl: http://{{ .Values.app.svc.identity }}
20+
urls__IdentityUrl: {{ $identity }}
21+
marketing__ConnectionString: mongodb://{{ $mongo }}
22+
marketing__Database: {{ .Values.inf.mongo.marketing.database }}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{{- $name := include "marketing-api.fullname" . -}}
2+
{{- $cfgname := printf "%s-%s" "cfg" $name -}}
3+
apiVersion: apps/v1beta2
4+
kind: Deployment
5+
metadata:
6+
name: {{ template "marketing-api.fullname" . }}
7+
labels:
8+
ufo: {{ $cfgname}}
9+
app: {{ template "marketing-api.name" . }}
10+
chart: {{ template "marketing-api.chart" . }}
11+
release: {{ .Release.Name }}
12+
heritage: {{ .Release.Service }}
13+
spec:
14+
replicas: {{ .Values.replicaCount }}
15+
selector:
16+
matchLabels:
17+
app: {{ template "marketing-api.name" . }}
18+
release: {{ .Release.Name }}
19+
template:
20+
metadata:
21+
labels:
22+
app: {{ template "marketing-api.name" . }}
23+
release: {{ .Release.Name }}
24+
spec:
25+
{{ if .Values.imagePullSecrets -}}
26+
imagePullSecrets:
27+
{{ range .Values.imagePullSecrets -}}
28+
- name: {{ .name }}
29+
{{- end -}}
30+
{{- end }}
31+
containers:
32+
- name: {{ .Chart.Name }}
33+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
34+
imagePullPolicy: {{ .Values.image.pullPolicy }}
35+
env:
36+
- name: PATH_BASE
37+
value: {{ include "pathBase" . }}
38+
- name: k8sname
39+
value: {{ .Values.clusterName }}
40+
{{- if .Values.env.values -}}
41+
{{- range .Values.env.values }}
42+
- name: {{ .name }}
43+
value: {{ .value | quote }}
44+
{{- end -}}
45+
{{- end -}}
46+
{{- if .Values.env.configmap -}}
47+
{{- range .Values.env.configmap }}
48+
- name: {{ .name }}
49+
valueFrom:
50+
configMapKeyRef:
51+
name: {{ $cfgname }}
52+
key: {{ .key }}
53+
{{- end -}}
54+
{{- end }}
55+
ports:
56+
- name: http
57+
containerPort: 80
58+
protocol: TCP
59+
resources:
60+
{{ toYaml .Values.resources | indent 12 }}
61+
{{- with .Values.nodeSelector }}
62+
nodeSelector:
63+
{{ toYaml . | indent 8 }}
64+
{{- end }}
65+
{{- with .Values.affinity }}
66+
affinity:
67+
{{ toYaml . | indent 8 }}
68+
{{- end }}
69+
{{- with .Values.tolerations }}
70+
tolerations:
71+
{{ toYaml . | indent 8 }}
72+
{{- end }}
73+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- if .Values.ingress.enabled -}}
2+
{{- $fullName := include "marketing-api.fullname" . -}}
3+
{{- $ingressPath := include "pathBase" . -}}
4+
apiVersion: extensions/v1beta1
5+
kind: Ingress
6+
metadata:
7+
name: {{ $fullName }}
8+
labels:
9+
app: {{ template "marketing-api.name" . }}
10+
chart: {{ template "marketing-api.chart" . }}
11+
release: {{ .Release.Name }}
12+
heritage: {{ .Release.Service }}
13+
{{- with .Values.ingress.annotations }}
14+
annotations:
15+
{{ toYaml . | indent 4 }}
16+
{{- end }}
17+
spec:
18+
{{- if .Values.ingress.tls }}
19+
tls:
20+
{{- range .Values.ingress.tls }}
21+
- hosts:
22+
- {{ .Values.inf.k8s.dns }}
23+
secretName: {{ .secretName }}
24+
{{- end }}
25+
{{- end }}
26+
rules:
27+
- host: {{ .Values.inf.k8s.dns }}
28+
http:
29+
paths:
30+
- path: {{ $ingressPath }}
31+
backend:
32+
serviceName: {{ $fullName }}
33+
servicePort: http
34+
{{- end }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ .Values.app.svc.marketing }}
5+
labels:
6+
app: {{ template "marketing-api.name" . }}
7+
chart: {{ template "marketing-api.chart" . }}
8+
release: {{ .Release.Name }}
9+
heritage: {{ .Release.Service }}
10+
spec:
11+
type: {{ .Values.service.type }}
12+
ports:
13+
- port: {{ .Values.service.port }}
14+
targetPort: http
15+
protocol: TCP
16+
name: http
17+
selector:
18+
app: {{ template "marketing-api.name" . }}
19+
release: {{ .Release.Name }}

k8s/helm/marketing-api/values.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
replicaCount: 1
2+
clusterName: eshop-aks
3+
pathBase: /marketing-api
4+
5+
image:
6+
repository: eshop/marketing.api
7+
tag: latest
8+
pullPolicy: IfNotPresent
9+
10+
service:
11+
type: ClusterIP
12+
port: 80
13+
14+
ingress:
15+
enabled: false
16+
annotations: {}
17+
tls: []
18+
19+
resources: {}
20+
21+
22+
nodeSelector: {}
23+
24+
tolerations: []
25+
26+
affinity: {}
27+
28+
# env defines the environment variables that will be declared in the pod
29+
env:
30+
urls:
31+
# configmap declares variables which value is taken from the config map defined in template configmap.yaml (name is name of var and key the key in configmap).
32+
configmap:
33+
- name: ApplicationInsights__InstrumentationKey
34+
key: all__InstrumentationKey
35+
- name: EventBusConnection
36+
key: all__EventBusConnection
37+
- name: AzureServiceBusEnabled
38+
key: all__UseAzureServiceBus
39+
- name: UseLoadTest
40+
key: all_EnableLoadTest
41+
- name: IdentityUrl
42+
key: internalurls__IdentityUrl
43+
- name: IdentityUrlExternal
44+
key: urls__IdentityUrl
45+
- name: ConnectionString
46+
key: marketing__ConnectionString
47+
- name: Database
48+
key: marketing__Database
49+
# values define environment variables with a fixed value (no configmap involved) (name is name of var, and value is its value)
50+
values:
51+
- name: ASPNETCORE_ENVIRONMENT
52+
value: Development
53+
- name: OrchestratorType
54+
value: 'K8S'
55+

0 commit comments

Comments
 (0)