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

Shikha #195

Closed
wants to merge 14 commits into from
57 changes: 57 additions & 0 deletions charts/microservice/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#{{- define "microservice.fullname" -}}
#{{- printf "%s-%s" (default .Chart.Name .Values.env.microservice.fullname) .Release.Name | trunc 63 | trimSuffix "-" }}
#{{- end -}}

#{{- define "microservice.labels" -}}
#app.kubernetes.io/name: {{ .Chart.Name | quote }}
#helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | replace ":" "-" | quote }}
#app.kubernetes.io/instance: {{ .Release.Name | quote }}
#app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" | replace ":" "-" | quote }}
#app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
#{{- end -}}

#{{- define "microservice.selectorLabels" -}}
#app: {{ default .Values.env.microservice.selectorLabels .Chart.Name | quote }}
#{{- end -}}

#{{- define "microservice.matchLabels" -}}
#app: {{ default .Values.env.microservice.selectorLabels .Chart.Name | quote }}
#{{- end -}}

{{/* Define the "microservice.fullname" template */}}
{{- define "microservice.fullname" -}}
{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/* Define the "microservice.name" template (if needed) */}}
{{- define "microservice.name" -}}
{{- .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/* Define the "microservice.chart" template (if needed) */}}
{{- define "microservice.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/* Define other templates as necessary */}}
{{/* Define the "microservice.labels" template */}}
{{- define "microservice.labels" -}}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}

{{/* Define the "microservice.matchLabels" template */}}
{{- define "microservice.matchLabels" -}}
{{- with .Values.app.name }}
app: {{ . }}
{{- end }}
{{- end }}

{{/* Define the "microservice.selectorLabels" template */}}
{{- define "microservice.selectorLabels" -}}
{{- with .Values.app.name }}
app: {{ . }}
{{- end }}
{{- end }}

9 changes: 9 additions & 0 deletions charts/microservice/templates/config-map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "microservice.fullname" . }}
namespace: {{ .Release.Namespace }}
data:
{{- range $key, $value := .Values.configMap.data }}
{{ $key }}: {{ $value | quote }}
{{- end }}
63 changes: 54 additions & 9 deletions charts/microservice/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,69 @@
apiVersion: apps/v1
#apiVersion: apps/v1
#kind: Deployment
#metadata:
# name: {{ include "microservice.fullname" . }}
#labels:
# {{- include "microservice.labels" . | nindent 4 }}
#spec:
# replicas: {{ .Values.replicaCount }}
#selector:
# matchLabels:
# {{- include "microservice.matchLabels" . | nindent 6 }}
#template:
# metadata:
# labels:
# {{- include "microservice.selectorLabels" . | nindent 8 }}
#spec:
# containers:
# - name: {{ .Chart.Name }}
# image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
# imagePullPolicy: {{ .Values.image.pullPolicy }}

# ports:
# - name: http
# containerPort: 80
# protocol: TCP

apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "microservice.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "microservice.labels" . | nindent 4 }}
app: {{ .Values.app.name }}
spec:
replicas: {{ .Values.replicaCount }}
replicas: {{ .Values.deployment.replicas }}
selector:
matchLabels:
{{- include "microservice.selectorLabels" . | nindent 6 }}
app: {{ .Values.app.name }}
template:
metadata:
labels:
{{- include "microservice.selectorLabels" . | nindent 8 }}
app: {{ .Values.app.name }}
spec:
serviceAccountName: {{ include "microservice.fullname" . }}
containers:
- name: {{ .Chart.Name }}
- name: {{ .Values.app.name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
- containerPort: {{ .Values.service.targetPort }}
env:
- name: CONFIG_FILE
valueFrom:
configMapKeyRef:
name: {{ include "microservice.fullname" . }}
key: {{ .Values.configMap.key }}
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: {{ include "microservice.fullname" . }}
key: {{ .Values.secret.key }}

- name: PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.secret.name }}
key: {{ .Values.secret.passwordKey }}


9 changes: 9 additions & 0 deletions charts/microservice/templates/secret-manager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "microservice.fullname" . }}
name: {{ .Values.secret.name }}
namespace: {{ .Release.Namespace }}
type: Opaque
data:
{{ .Values.secret.key }}: {{ .Values.secret.value | b64enc }}
6 changes: 6 additions & 0 deletions charts/microservice/templates/service-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "microservice.fullname" . }}
labels:
app: {{ include "microservice.name" . }}
29 changes: 22 additions & 7 deletions charts/microservice/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
apiVersion: v1
#apiVersion: v1
#kind: Service
#metadata:
# name: {{ include "microservice.fullname" . }}
#labels:
# {{- include "microservice.labels" . | nindent 4 }}
#spec:
# type: {{ .Values.service.type }}
#ports:
# - port: {{ .Values.service.port }}
# targetPort: http
# protocol: TCP
#name: http
#selector:
# {{- include "microservice.selectorLabels" . | nindent 4 }}

apiVersion: v1
kind: Service
metadata:
name: {{ include "microservice.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "microservice.labels" . | nindent 4 }}
{{ include "microservice.labels" . }} # Include microservice.labels template
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
targetPort: {{ .Values.service.targetPort }}
selector:
{{- include "microservice.selectorLabels" . | nindent 4 }}
app: {{ .Values.app.name }}

48 changes: 42 additions & 6 deletions charts/microservice/values.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
replicaCount: 1
#replicaCount: 3

#image:
# repository: nginx # Replace with your microservice image name
#pullPolicy: IfNotPresent
#tags:
# - "latest"
#- "stable"
#- "alpine" # Replace with your microservice image tag
#env:
# microservice:
# selectorLabels: "micro"
# fullname: "k8s"

#service:
#type: ClusterIP
#port: 80




app:
name: my-microservice

deployment:
replicas: 2 # Example number of replicas for your deployment

image:
repository: nginx # your microservice image name
pullPolicy: IfNotPresent
tag: "latest" # your microservice image tag
repository: nginx # Replace with your Docker image repository URL/name
tag: latest # Replace with your Docker image tag

service:
type: ClusterIP
port: 80
port: 80 # Example service port
targetPort: 8080 # Example target port

configMap:
name: my-microservice-config
key: configKey

secret:
name: new-microservice-secret
key: secretKey
value: my-secret-value
passwordKey: password
password: my-secret-password

Loading