Skip to content

mandacode-lab/mc-helm-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mc-helm-lib

Reusable Helm library chart providing standard Kubernetes resource templates.

Templates

  • mc-helm-lib.deployment - Deployment with config injection support
  • mc-helm-lib.service - Service
  • mc-helm-lib.hpa - HorizontalPodAutoscaler
  • mc-helm-lib.httproute - Gateway API HTTPRoute

Installation

Add to your Chart.yaml:

dependencies:
  - name: mc-helm-lib
    version: 0.1.0
    repository: "file://../mc-helm-lib"

Run: helm dependency update

Usage

Deployment

# templates/deployment.yaml
{{ include "mc-helm-lib.deployment" (dict
  "component" "api"
  "config" .Values.api
  "root" $
) }}

Deployment with ConfigMap/Secret Injection

# templates/configs.yaml
{{- define "myapp.config" -}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "myapp.fullname" . }}-config
data:
  HTTP_PORT: "8080"
{{- end -}}

{{ include "myapp.config" . }}

---
# templates/deployment.yaml
{{ include "mc-helm-lib.deployment" (dict
  "component" "api"
  "config" .Values.api
  "configRefs" (list
    (dict
      "type" "configMap"
      "name" (printf "%s-config" (include "myapp.fullname" $))
      "template" "myapp.config"
      "params" $
    )
  )
  "root" $
) }}

How it works:

  • type: "configMap" or "secret"
  • name: Resource name for envFrom injection
  • template: Template name for checksum calculation
  • params: Parameters passed to template for checksum

Config changes trigger automatic pod restarts via checksum annotations.

Service

{{ include "mc-helm-lib.service" (dict
  "component" "api"
  "config" .Values.api
  "root" $
) }}

HPA

{{ include "mc-helm-lib.hpa" (dict
  "component" "api"
  "config" .Values.api
  "root" $
) }}

HTTPRoute

{{ include "mc-helm-lib.httproute" (dict
  "component" "api"
  "config" .Values.api
  "root" $
) }}

Values Structure

api:
  enabled: true
  replicaCount: 2

  image:
    repository: myregistry/myapp
    tag: "1.0.0"
    pullPolicy: IfNotPresent

  service:
    type: ClusterIP
    port: 80
    targetPort: 8080

  autoscaling:
    enabled: false
    minReplicas: 2
    maxReplicas: 10
    targetCPUUtilizationPercentage: 80

  httpRoute:
    enabled: false
    parentRefs:
      - name: gateway
    hostnames:
      - api.example.com
    rules:
      - matches:
          - path:
              type: PathPrefix
              value: /

  resources:
    limits:
      cpu: 500m
      memory: 512Mi
    requests:
      cpu: 250m
      memory: 256Mi

  livenessProbe:
    httpGet:
      path: /health
      port: http

  readinessProbe:
    httpGet:
      path: /ready
      port: http

  podSecurityContext: {}
  securityContext: {}
  podAnnotations: {}
  podLabels: {}

Helper Functions

  • mc-helm-lib.name
  • mc-helm-lib.fullname
  • mc-helm-lib.chart
  • mc-helm-lib.labels (supports component)
  • mc-helm-lib.selectorLabels (supports component)
  • mc-helm-lib.serviceAccountName

About

Mandacode Helm Chart Library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages