diff --git a/README.md b/README.md index 85c6069..7f41447 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,14 @@ docker build \ . ``` +## Using Helm +### To deploy the application on Kubernetes using Helm, follow this [installation guide](/helm/README.md) containing + +- Helm Chart structure +- Quick Note +- Helm Commands + + ## Roadmap The contents in this repository started out as a simple mediator built using Credo that can be used for development. Over time we've added some features, but there's still a lot we want to add to this repository over time. Some things on the roadmap: diff --git a/helm/README.md b/helm/README.md new file mode 100644 index 0000000..4b5d4a0 --- /dev/null +++ b/helm/README.md @@ -0,0 +1,39 @@ +# Installing DIDComm Mediator Credo on k8s with Helm + +### 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 +``` \ No newline at end of file diff --git a/helm/mediator/Chart.yaml b/helm/mediator/Chart.yaml new file mode 100644 index 0000000..b0f5de4 --- /dev/null +++ b/helm/mediator/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: Mediator +description: A Helm chart for DIDComm Mediator Credo + +# 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: "0.1.0" diff --git a/helm/mediator/templates/NOTES.txt b/helm/mediator/templates/NOTES.txt new file mode 100644 index 0000000..e69de29 diff --git a/helm/mediator/templates/deployment.yaml b/helm/mediator/templates/deployment.yaml new file mode 100644 index 0000000..eb53419 --- /dev/null +++ b/helm/mediator/templates/deployment.yaml @@ -0,0 +1,72 @@ +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 }}" + imagePullPolicy: {{ .Values.container.imagePullPolicy }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + ports: + - containerPort: {{ .Values.container.port }} + livenessProbe: + httpGet: + path: /health + port: http + initialDelaySeconds: 45 + periodSeconds: 3 + readinessProbe: + httpGet: + path: /health + port: http + initialDelaySeconds: 45 + timeoutSeconds: 3 + env: + - 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 + envFrom: + - secretRef: + name: {{ include "mediator-agent.fullname" . }}-creds + - name: POSTGRES_USER + value: {{ .Values.environment.POSTGRES_USER }} + - name: POSTGRES_PASSWORD + envFrom: + - secretRef: + name: {{ include "mediator-agent.fullname" . }}-postgresql-creds + - 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 }} + volumeMounts: + - name: cache-volume + mountPath: /.cache + + volumes: + - name: cache-volume + emptyDir: + sizeLimit: 1Gi diff --git a/helm/mediator/templates/ingress.yaml b/helm/mediator/templates/ingress.yaml new file mode 100644 index 0000000..abbd131 --- /dev/null +++ b/helm/mediator/templates/ingress.yaml @@ -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 }} \ No newline at end of file diff --git a/helm/mediator/templates/service.yaml b/helm/mediator/templates/service.yaml new file mode 100644 index 0000000..11b3e4d --- /dev/null +++ b/helm/mediator/templates/service.yaml @@ -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 }} \ No newline at end of file diff --git a/helm/mediator/values.yaml b/helm/mediator/values.yaml new file mode 100644 index 0000000..0508d10 --- /dev/null +++ b/helm/mediator/values.yaml @@ -0,0 +1,45 @@ +## 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 + imagePullPolicy: Always + +environment: + AGENT_PORT: 3000 + AGENT_NAME: Mediator + WALLET_NAME: mediator + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_HOST: ${POSTGRES_HOST} + POSTGRES_ADMIN_USER: ${POSTGRES_ADMIN_USER} + POSTGRES_ADMIN_PASSWORD: {} + AGENT_ENDPOINTS: {} + LOG_LEVEL: 2 + +resources: + requests: + memory: 256Mi + cpu: 20m + limits: + memory: 256Mi + cpu: 100m + +## Service Values +service_name: mediator + + +## Ingress Values +ingress_name: mediator_ingress +cluster_issuer_name: nginx +host_name: example.com +certificate_secret_name: my-cert