Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Helm charts created #35

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Installing didcomm-mediator-credo on k8s with Helm
Helion55 marked this conversation as resolved.
Show resolved Hide resolved
### Three manifest files are used in Helm charts
1. Deployment.yaml
This file contains the replicaset, container image name, container port, and environment variables for the container. This will create a Deployment type object for the application.

2. Service.yaml
The service file is to create a service-type object to connect with the pods and to access the application by redirecting traffic through it without exposing the pod directly.

3. Ingress.yaml
Ingress is one layer on top of the service that will connect with the load balancer to redirect the traffic to the service. If multiple services are present, it can also redirect traffic to them by path-based routing. Similar to a service, it will redirect the traffic to the service without exposing it.

## Helm Chart Note
- The values.yaml file contains 4 sections: Common Values, Deployment Values, Service Values, and Ingress Values.
- These values will be passed inside the manifest files in the templates folder.
- Deployment env values should be replaced with your values in the values.yaml file's Deployment Values environment section.

## Helm Commands to Install the Application.
- Installing the application from the root directory with default values of the values.yaml file.
```bash
helm install YOUR_HELM_RELEASE_NAME ./helm/mediator/
```

- Changing the values as needed
```bash
helm install YOUR_HELM_RELEASE_NAME ./helm/mediator/ --set KEY=VALUE
```
- Changing multiple values
```bash
helm install YOUR_HELM_RELEASE_NAME ./helm/mediator/ --set KEY1=VALUE1,KEY2=VALUE2
```

- After installing, you can upgrade the values with the ```helm upgrade``` command.
```bash
helm upgrade YOUR_HELM_RELEASE_NAME ./helm/mediator/ --set KEY=VALUE
```
```bash
helm upgrade YOUR_HELM_RELEASE_NAME ./helm/mediator/ --set KEY1=VALUE1,KEY2=VALUE2
```
24 changes: 24 additions & 0 deletions helm/mediator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: helm
description: A Helm chart for Kubernetes
Comment on lines +2 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we give these mediator specific names?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will write the docs with the helm commands to install the application.

For the name: and description: I have left it default, but we can change that any time. Also suggest to me any note we should display after the helm deployment; I will write that too.


# 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might add an example of how a secret should be created to work with this helm chart. Not sure what to do with it. We only want it to run when a chart is installed, not updated so for now it can just live in notes unless you know a good way to do this:

---
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "mediator-agent.fullname" . }}-creds
  labels: {{- include "mediator-agent.labels" . | nindent 4}}
type: Opaque
data:
  WALLET_NAME: {{.Values.wallet_user | default "mediator" | b64enc}} 
  WALLET_KEY: {{.Values.wallet_key | default (randAlphaNum 16) | b64enc}} 

Empty file.
46 changes: 46 additions & 0 deletions helm/mediator/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.deployment_name }}
namespace: {{ .Values.namespace }}
labels:
app: {{ .Values.deployment_name }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ .Values.deployment_name }}
template:
metadata:
labels:
app: {{ .Values.deployment_name }}
spec:
containers:
- name: {{ .Values.container.name }}
image: " {{ .Values.image.name }}:{{ .Values.image.tag }} "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mediator needs a caches directory, I'm not 100% sure why but it does. Let's add that as an emptyDir:

      volumes:
        - name: cache-volume
          emptyDir:
            sizeLimit: 1Gi

and

          volumeMounts:
            - name: cache-volume
              mountPath: /.cache

imagePullPolicy: Always
Copy link
Contributor

@jleach jleach Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add the ability to control resource usage. Able to add that to the deployment?

          resources:
            {{- toYaml .Values.resources | nindent 12 }}

Then add values_dev.yml with the following:

resources:
  requests:
    memory: 256Mi
    cpu: 20m
  limits:
    memory: 256Mi
    cpu: 100m

This way we add different values for dev, test, stage, prod. Whatever different teams want to use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always is the default. The best practices is to not put in default values. Let's remove Always.

ports:
- containerPort: {{ .Values.container.port }}
env:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can add the existing health check. Something like:

          livenessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 45
            periodSeconds: 3
          readinessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 45
            timeoutSeconds: 3

- name: AGENT_PORT
value: "{{ .Values.environment.AGENT_PORT }}"
- name: AGENT_NAME
value: "{{ .Values.environment.AGENT_NAME }}"
- name: WALLET_NAME
value: "{{ .Values.environment.WALLET_NAME }}"
- name: WALLET_KEY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wallet key, postgres password, are better stored in secrets. Let's move them and reverence them accordingly:

          envFrom:
            - secretRef:
                name: {{ include "mediator-agent.fullname" . }}-postgresql-creds
            - secretRef:
                name: {{ include "mediator-agent.fullname" . }}-creds

value: "{{ .Values.environment.WALLET_KEY }}"
- name: POSTGRES_USER
value: "{{ .Values.environment.POSTGRES_USER }}"
- name: POSTGRES_PASSWORD
value: "{{ .Values.environment.POSTGRES_PASSWORD }}"
- name: POSTGRES_HOST
value: "{{ .Values.environment.POSTGRES_HOST }}"
- name: POSTGRES_ADMIN_USER
value: "{{ .Values.environment.POSTGRES_ADMIN_USER }}"
- name: POSTGRES_ADMIN_PASSWORD
value: "{{ .Values.environment.POSTGRES_ADMIN_PASSWORD }}"
- name: AGENT_ENDPOINTS
value: "{{ .Values.environment.AGENT_ENDPOINTS }}"
- name: LOG_LEVEL
value: "{{ .Values.environment.LOG_LEVEL }}"
24 changes: 24 additions & 0 deletions helm/mediator/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
cert-manager.io/cluster-issuer: {{ .Values.cluster_issuer_name }}
kubernetes.io/ingress.class: nginx
name: {{ .Values.ingress_name }}
namespace: {{ .Values.namespace }}
spec:
rules:
- host: {{ .Values.host_name }}
http:
paths:
- backend:
service:
name: {{ .Values.service_name }}
port:
number: {{ .Values.container.port }}
path: /
pathType: Prefix
tls:
- hosts:
- {{ .Values.host_name }}
secretName: {{ .Values.certificate_secret_name }}
10 changes: 10 additions & 0 deletions helm/mediator/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.service_name }}
namespace: {{ .Values.namespace }}
spec:
selector:
app: {{ .Values.deployment_name }}
ports:
- port: {{ .Values.container.port }}
39 changes: 39 additions & 0 deletions helm/mediator/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## Common Values
namespace: mediator


## Deployment Values
deployment_name: mediator
replicas: 1

image:
name: ghcr.io/openwallet-foundation/didcomm-mediator-credo
tag: latest

container:
name: mediator
port: 3000

environment:
AGENT_PORT: 3000
AGENT_NAME: Mediator
WALLET_NAME: mediator
WALLET_KEY: ${WALLET_KEY}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_HOST: ${POSTGRES_HOST}
POSTGRES_ADMIN_USER: ${POSTGRES_ADMIN_USER}
POSTGRES_ADMIN_PASSWORD: ${POSTGRES_ADMIN_PASSWORD}
AGENT_ENDPOINTS: "https://my-mediator.com,wss://my-mediator.com"
LOG_LEVEL: 2
Comment on lines +19 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to be able to override all values. (Also wallet_name)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have written the values from the docker-compose.yaml file, it should be left with only "{}" this.
Like,
AGENT_NAME: {}
WALLET_NAME: {}
...
...

For reference I have done that. You can override the values as needed or can set the values with helm --set flag during helm install. You can refer to this https://helm.sh/docs/helm/helm_install/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want these to be overridable also:

  AGENT_ENDPOINTS: "https://my-mediator.com,wss://my-mediator.com"



## Service Values
service_name: mediator


## Ingress Values
ingress_name: mediator_ingress
cluster_issuer_name: CLUSTER_ISSUER-NAME
host_name: HOST_NAME
certificate_secret_name: CERTIFICATE_SECRET_NAME