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

Fix helm chart #206

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
6 changes: 4 additions & 2 deletions charts/microservice/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
apiVersion: v2
name: microservice
description: A Helm chart for a microservice in Kubernetes

description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "1.0"
maintainers:
- name: Shikha Tripathi
email: [email protected]
53 changes: 53 additions & 0 deletions charts/microservice/templates/_helpers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{/* vim: set filetype=mustache: */}}

{{/*
Create a defautl fully qualified app name
It will use the release name to give the app name
*/}}

{{- define "app.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 60 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "app.tempname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 60 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{- define "app.fullname" -}}
{{- printf "%s-%s" ( include "app.tempname" . ) "app" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "app.labels" -}}
app: {{ include "app.tempname" . }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "app.selectorLabels" -}}
app: {{ include "app.tempname" . }}
{{- end }}%

{{/*
service name
*/}}
{{- define "app.servicename" -}}
{{- printf "%s-%s" ( include "app.tempname" . ) "svc" | trunc 63 | trimSuffix "-" }}
{{- end }}%
42 changes: 36 additions & 6 deletions charts/microservice/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "microservice.fullname" . }}
name: {{ include "app.fullname" . }}
labels:
{{- include "microservice.labels" . | nindent 4 }}
{{- include "app.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "microservice.selectorLabels" . | nindent 6 }}
{{- include "app.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "microservice.selectorLabels" . | nindent 8 }}
{{- include "app.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
- containerPort: {{ .Values.containerPorts.http }}
name: http
protocol: TCP
- containerPort: {{ .Values.containerPorts.https }}
name: https
protocol: TCP
- containerPort: {{ .Values.containerPorts.custom }}
name: custom-port
protocol: TCP
resources:
requests:
memory: "{{ .Values.resources.requests.memory }}"
cpu: "{{ .Values.resources.requests.cpu }}"
limits:
memory: "{{ .Values.resources.limits.memory }}"
cpu: "{{ .Values.resources.limits.cpu }}"
{{- if .Values.liveness.enabled }}
livenessProbe:
httpGet:
path: {{ .Values.liveness.path }}
port: {{ .Values.liveness.port }}
initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
periodSeconds: {{ .Values.liveness.periodSeconds }}
{{- end}}
{{- if .Values.readiness.enabled }}
readinessProbe:
httpGet:
path: {{ .Values.readiness.path }}
port: {{ .Values.readiness.port }}
initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
periodSeconds: {{ .Values.readiness.periodSeconds }}
failureThreshold: {{ .Values.readiness.failureThreshold }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/microservice/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.hpa.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "app.fullname" . }}
labels:
{{- include "app.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "app.fullname" . }}
minReplicas: {{ .Values.hpa.minReplicas }}
maxReplicas: {{ .Values.hpa.maxReplicas }}
averageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
{{- end }}
22 changes: 15 additions & 7 deletions charts/microservice/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "microservice.fullname" . }}
name: {{ include "app.fullname" . }}-svc
labels:
{{- include "microservice.labels" . | nindent 4 }}
{{- include "app.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
selector:
{{- include "app.selectorLabels" . | nindent 4 }}
ports:
- port: {{ .Values.service.port }}
- name: http
port: {{ .Values.servicePorts.http }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "microservice.selectorLabels" . | nindent 4 }}
- name: https
port: {{ .Values.servicePorts.https }}
targetPort: https
protocol: TCP
- name: custom-port
port: {{ .Values.servicePorts.custom }}
targetPort: custom-port
protocol: TCP
type: {{ .Values.service.type }}
43 changes: 40 additions & 3 deletions charts/microservice/values.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
replicaCount: 1

fullnameOverride: "nginx"
nameOverride: ""
image:
repository: nginx # your microservice image name
repository: nginx
pullPolicy: IfNotPresent
tag: "latest" # your microservice image tag
tag: "latest"
containerPorts:
http: 80
https: 443
custom: 8080

servicePorts:
http: 80
https: 443
custom: 8080

service:
type: ClusterIP
type: ClusterIP

resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
hpa:
enabled: true
minReplicas: 1
maxReplicas: 5
targetCPUUtilizationPercentage: 50

liveness:
enabled: false
path: /alive
port: 80
initialDelaySeconds: 3
periodSeconds: 3
readiness:
enabled: false
path: /ready
port: 80
initialDelaySeconds: 5
periodSeconds: 5
failureThreshold: 3
13 changes: 5 additions & 8 deletions ct.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
remote: origin
target-branch: main
chart-dirs:
chart_dirs:
- charts
chart-repos:
- ot-helm=https://ot-container-kit.github.io/helm-charts
excluded-charts:
- mysql
validate_chart_schema: true
validate-maintainers: true
helm-extra-args: --strict
target_branch: main # or the appropriate branch name