Skip to content

Commit

Permalink
Feature/Add OpenTelemetry Collector & DevOps Sales Portal (#18)
Browse files Browse the repository at this point in the history
* Add docs/operations.md

* Add Devpro Sales Portal Helm chart

* Minor changes in docs

* Add OpenTelemetry Collector chart

* Enable Opentelemetry in SalesPortal

* Bump HobbyFarm chart & fix lint issue
  • Loading branch information
devpro committed Apr 19, 2023
1 parent 97b9c32 commit aefeb57
Show file tree
Hide file tree
Showing 19 changed files with 505 additions and 8 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Helm charts to ease the deployment of containers on Kubernetes clusters and get
* [Cow Demo](charts/cow-demo/README.md) 🗸
* [Drupal](charts/drupal/README.md)
* [E Corp Demo](charts/ecorp-demo/README.md) 🗸
* [Devpro Sales Portal](charts/devpro-salesportal/README.md) 🗸
* [WordPress](charts/wordpress/README.md) 🗸
* Authentication / Identity
* [Keycloak](charts/keycloak/README.md) 🗸
Expand Down Expand Up @@ -49,7 +50,7 @@ Helm charts to ease the deployment of containers on Kubernetes clusters and get
* [Rancher](charts/rancher/README.md) 🗸
* Observability
* [Elastic Stack](charts/elastic-stack/README.md)
* [OpenTelemetry Collector](charts/opentelemetry/README.md)
* [OpenTelemetry Collector](charts/opentelemetry-collector/README.md) 🗸
* [Prometheus](charts/prometheus/README.md)
* [Grafana](charts/grafana/README.md)
* Secrets
Expand Down Expand Up @@ -84,6 +85,10 @@ Helm charts to ease the deployment of containers on Kubernetes clusters and get

Limitation: [Helm Chart Releaser](https://github.com/helm/chart-releaser) doesn't support multiple chart directories ou multiple levels so all charts must be in `charts` repository

## Best pratices

* [Operations](docs/operations.md)

## Samples

* [SUSE Exchange Paris 2023](samples/suse-exchange-paris-2023/README.md)
Expand Down
23 changes: 23 additions & 0 deletions charts/devpro-salesportal/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
6 changes: 6 additions & 0 deletions charts/devpro-salesportal/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: mongodb
repository: https://charts.bitnami.com/bitnami
version: 13.9.4
digest: sha256:40f660c388f3965695fbf9ad9f5b36b59f7a7c1ff166cf15cae957c5988d5c72
generated: "2023-04-18T15:32:14.627874569+02:00"
15 changes: 15 additions & 0 deletions charts/devpro-salesportal/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v2
name: devpro-salesportal
description: Helm chart for Devpro Sales Portal
type: application
version: 0.1.0
appVersion: "1.0.0"
dependencies:
- name: mongodb
version: 13.9.4 # MongoDB 6.0.5
repository: https://charts.bitnami.com/bitnami
alias: mongodb
condition: mongodb.enabled
maintainers:
- name: devpro
email: bertrand@devpro.fr
87 changes: 87 additions & 0 deletions charts/devpro-salesportal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Helm chart for Devpro Sales Portal

This Helm chart will install [Devpro Sales Portal](https://github.com/devpro/sales-portal) on a Kubernetes cluster.

## Usage

[Helm](https://helm.sh) must be installed to use the charts. Once correctly setup, add the repository:

```bash
helm repo add devpro https://devpro.github.io/helm-charts
```

If you had already added this repo earlier, run `helm repo update` to retrieve the latest versions of the packages. You can then run `helm search repo sales-portal` to see the charts.

To install the chart:

```bash
helm upgrade --install sales-portal devpro/sales-portal --create-namespace --namespace sales-portal
```

To uninstall the chart and clean-up the cluster:

```bash
helm delete sales-portal
kubectl delete ns sales-portal
```

## Development

### Update chart dependencies

Make sure to run `../../scripts/add_helm_repos.sh` and look at available version with with `helm search repo -l mongodb --versions`.

Every time you update `Chart.yaml`, run `helm dependency update` to update `Chart.lock`.

### Linting

Run `helm lint` to check the chart.

### Reviewing generated chart

Run `helm template sales-portal . -f values.yaml > temp.yaml` to look at what is generated.

## Examples

### Installation with MongoDB

```bash
# installs or updates the Helm release
helm upgrade --install sales-portal-beta . -f values.yaml --create-namespace \
--set mongodb.enabled=true,mongodb.auth.rootPassword=admin \
--set data.db.connectionString=mongodb://root:admin@sales-portal-beta-mongodb:27017/sales-portal-beta?authSource=admin \
--set data.db.databaseName=sales-portal-beta \
--namespace sales-portal-beta

# (optional) forwards MongoDB port for local access
kubectl port-forward service/sales-portal-beta-mongodb 27017:27017 -n sales-portal-beta

# forwards port for local access
kubectl port-forward service/salesportal-wasmapp-svc 3001:80 -n sales-portal-beta

# accesses with http://localhost:3001/
curl http://localhost:3001/

# cleans up
helm delete sales-portal-beta -n sales-portal-beta
kubectl delete ns sales-portal-beta
```

### Installation with MongoDB, cert-manager, Let's Encrypt & NGINX Ingress Controller

```bash
# retrieves public IP
NGINX_PUBLIC_IP=`kubectl get service -n ingress-nginx ingress-nginx-controller --output jsonpath='{.status.loadBalancer.ingress[0].ip}'`

# applies the manifest (add "--debug > output.yaml" in case of issue)
helm upgrade --install sales-portal-beta . -f values.yaml --create-namespace \
--set mongodb.enabled=true,mongodb.auth.rootPassword=admin \
--set data.db.connectionString=mongodb://root:admin@sales-portal-beta-mongodb:27017/sales-portal-beta?authSource=admin \
--set data.db.databaseName=sales-portal-beta \
--set ingress.enabled=true,ingress.className=nginx,ingress.annotations.'cert-manager\.io/cluster-issuer'=letsencrypt-prod \
--set front.host=sales-portal.${NGINX_PUBLIC_IP}.sslip.io,front.tls.secretName=sales-portal-tls \
--set adapter.host=crm-adapter.${NGINX_PUBLIC_IP}.sslip.io,adapter.tls.secretName=crm-adapter-tls \
--set data.host=crm-data.${NGINX_PUBLIC_IP}.sslip.io,data.tls.secretName=crm-data-tls \
--set dotnet.environment=Development,dotnet.enableSwagger=true,dotnet.enableOpenTelemetry=true \
--namespace sales-portal-beta
```
File renamed without changes.
Empty file.
93 changes: 93 additions & 0 deletions charts/devpro-salesportal/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{{- $applications := list .Values.front .Values.adapter .Values.data -}}
{{ range $applications }}
{{- $name := .name -}}
{{- if .enabled -}}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .name }}
labels:
app: {{ .name }}
app.kubernetes.io/name: {{ .name }}
spec:
replicas: {{ .replicaCount }}
selector:
matchLabels:
app: {{ .name }}
app.kubernetes.io/name: {{ .name }}
template:
metadata:
labels:
app: {{ $name }}
app.kubernetes.io/name: {{ $name }}
{{- if .additionalPodLabels }}
{{- toYaml .additionalPodLabels | nindent 8 }}
{{- end }}
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "kubernetes.io/arch"
operator: In
values: ["amd64"]
containers:
- name: {{ .name }}
image: {{ .image }}:{{ .tag }}
imagePullPolicy: Always
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: {{ .healthEndpoint }}
port: http
readinessProbe:
httpGet:
path: {{ .healthEndpoint }}
port: http
resources:
{{- toYaml .resources | nindent 12 }}
{{- $api := .api -}}
{{- $db := .db -}}
{{- with .env }}
env:
- name: HOST_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
# TODO: only add this variables when needed and manage http calls
- name: ASPNETCORE_ENVIRONMENT
value: "{{ $.Values.dotnet.environment }}"
- name: AllowedOrigins__0
value: "https://{{ $.Values.front.host }}"
- name: AllowedOrigins__1
value: "https://{{ $.Values.adapter.host }}"
- name: CrmDataWebApi__Url
value: "https://{{ $.Values.data.host }}"
{{- if $.Values.dotnet.enableSwagger }}
- name: Application__IsSwaggerEnabled
value: "true"
{{- end }}
{{- if $.Values.dotnet.enableOpenTelemetry }}
- name: Application__IsOpenTelemetryEnabled
value: "true"
- name: OpenTelemetry__CollectorEndpoint
value: "http://$(HOST_IP):4317"
{{- end }}
{{- if $db }}
- name: ConnectionStrings__MongoDb
value: {{ $db.connectionString }}
- name: MongoDb__ConnectionStringName
value: "MongoDb"
- name: MongoDb__DatabaseName
value: {{ $db.databaseName }}
{{- end }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{ end }}
50 changes: 50 additions & 0 deletions charts/devpro-salesportal/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{- $applications := list .Values.front .Values.adapter .Values.data -}}
{{ range $applications }}
{{- $name := .name -}}
{{- if and $.Values.ingress.enabled .enabled -}}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $name }}-ingress
{{- with $.Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if $.Values.ingress.className }}
ingressClassName: {{ $.Values.ingress.className }}
{{- end }}
rules:
- host: {{ .host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ $name }}-svc
port:
number: 80
{{- range .ingressExtraHosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: {{ .pathType }}
backend:
service:
name: {{ $name }}-svc
port:
number: 80
{{- end }}
{{- end }}
{{- if .tls }}
tls:
- hosts:
- {{ .host | quote }}
secretName: {{ .tls.secretName }}
{{- end }}
{{- end }}
{{ end }}
23 changes: 23 additions & 0 deletions charts/devpro-salesportal/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- $applications := list .Values.front .Values.adapter .Values.data -}}
{{ range $applications }}
{{- if .enabled -}}
---
apiVersion: v1
kind: Service
metadata:
labels:
app: {{ .name }}
app.kubernetes.io/name: {{ .name }}
name: {{ .name }}-svc
spec:
type: ClusterIP
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: {{ .name }}
app.kubernetes.io/name: {{ .name }}
{{- end }}
{{ end }}
Loading

0 comments on commit aefeb57

Please sign in to comment.