Merge pull request '[DO-1377] start project' (#1) from feature/DO-1377/start into master

Reviewed-on: https://git.avroid.tech/Helm/openresty/pulls/1
Reviewed-by: Stanislav Gabenov <stanislav.gabenov@avroid.team>
Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team>
This commit is contained in:
Rustam Tagaev
2024-12-09 16:55:14 +03:00
13 changed files with 92 additions and 49 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
custom_values.yaml
*.tgz

View File

@@ -1,6 +1,6 @@
apiVersion: v2 apiVersion: v2
name: myHelmChart name: openresty
description: A Helm chart for Kubernetes description: OpenResty API gateway
# A chart can be either an 'application' or a 'library' chart. # A chart can be either an 'application' or a 'library' chart.
# #
@@ -21,4 +21,4 @@ version: 0.1.0
# incremented each time you make changes to the application. Versions are not expected to # 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. # follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes. # It is recommended to use it with quotes.
appVersion: "1.16.0" appVersion: "1.21.4.1"

View File

@@ -1,13 +1,25 @@
# template-helm-chart-repository # OpenResty
Template for helm chart repositories Создание пакета для Helm чарта
# How-to-use
Create repository from template
Replace all names of chart
```bash
helm package ./
``` ```
sed -i "s/myHelmChart/container-test-validation-server-chart/g"
Добавление репозитория
```bash
helm repo add avroid https://nexus.avroid.tech/repository/devops-helm-release
```
Установка репозитория
```bash
helm install -n api-gateway -f custom_values.yaml openresty ./
```
Обновления приложения
```bash
helm upgrade -n api-gateway -f custom_values.yaml openresty ./
``` ```

View File

@@ -6,16 +6,16 @@
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- else if contains "NodePort" .Values.service.type }} {{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "myHelmChart.fullname" . }}) export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "openresty.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }} {{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available. NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "myHelmChart.fullname" . }}' You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "openresty.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "myHelmChart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "openresty.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }} echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }} {{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "myHelmChart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "openresty.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application" echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT

View File

@@ -1,7 +1,7 @@
{{/* {{/*
Expand the name of the chart. Expand the name of the chart.
*/}} */}}
{{- define "myHelmChart.name" -}} {{- define "openresty.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }} {{- end }}
@@ -10,7 +10,7 @@ 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). 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. If release name contains chart name it will be used as a full name.
*/}} */}}
{{- define "myHelmChart.fullname" -}} {{- define "openresty.fullname" -}}
{{- if .Values.fullnameOverride }} {{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }} {{- else }}
@@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name.
{{/* {{/*
Create chart name and version as used by the chart label. Create chart name and version as used by the chart label.
*/}} */}}
{{- define "myHelmChart.chart" -}} {{- define "openresty.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }} {{- end }}
{{/* {{/*
Common labels Common labels
*/}} */}}
{{- define "myHelmChart.labels" -}} {{- define "openresty.labels" -}}
helm.sh/chart: {{ include "myHelmChart.chart" . }} helm.sh/chart: {{ include "openresty.chart" . }}
{{ include "myHelmChart.selectorLabels" . }} {{ include "openresty.selectorLabels" . }}
{{- if .Chart.AppVersion }} {{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }} {{- end }}
@@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/* {{/*
Selector labels Selector labels
*/}} */}}
{{- define "myHelmChart.selectorLabels" -}} {{- define "openresty.selectorLabels" -}}
app.kubernetes.io/name: {{ include "myHelmChart.name" . }} app.kubernetes.io/name: {{ include "openresty.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }} {{- end }}
{{/* {{/*
Create the name of the service account to use Create the name of the service account to use
*/}} */}}
{{- define "myHelmChart.serviceAccountName" -}} {{- define "openresty.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }} {{- if .Values.serviceAccount.create }}
{{- default (include "myHelmChart.fullname" .) .Values.serviceAccount.name }} {{- default (include "openresty.fullname" .) .Values.serviceAccount.name }}
{{- else }} {{- else }}
{{- default "default" .Values.serviceAccount.name }} {{- default "default" .Values.serviceAccount.name }}
{{- end }} {{- end }}

22
templates/configmap.yaml Normal file
View File

@@ -0,0 +1,22 @@
{{ if .Values.configMap.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: "{{ template "openresty.fullname" . }}"
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: "{{ .Release.Service }}"
release: "{{ .Release.Name }}"
{{- with .Values.configMap.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
name: "{{ .Release.Name }}-config"
data:
{{- with .Values.configMap.apiConfig }}
api-gw.conf: {{ toYaml . | indent 4 }}
{{- end }}
{{- with .Values.configMap.luaScript }}
script.lua: {{ toYaml . | indent 4 }}
{{- end }}
{{- end }}

View File

@@ -1,24 +1,25 @@
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: {{ include "myHelmChart.fullname" . }} name: {{ include "openresty.fullname" . }}
labels: labels:
{{- include "myHelmChart.labels" . | nindent 4 }} {{- include "openresty.labels" . | nindent 4 }}
spec: spec:
{{- if not .Values.autoscaling.enabled }} {{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }} replicas: {{ .Values.replicaCount }}
{{- end }} {{- end }}
selector: selector:
matchLabels: matchLabels:
{{- include "myHelmChart.selectorLabels" . | nindent 6 }} {{- include "openresty.selectorLabels" . | nindent 6 }}
template: template:
metadata: metadata:
{{- with .Values.podAnnotations }}
annotations: annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml" ) . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
labels: labels:
{{- include "myHelmChart.labels" . | nindent 8 }} {{- include "openresty.labels" . | nindent 8 }}
{{- with .Values.podLabels }} {{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
@@ -27,7 +28,7 @@ spec:
imagePullSecrets: imagePullSecrets:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
serviceAccountName: {{ include "myHelmChart.serviceAccountName" . }} serviceAccountName: {{ include "openresty.serviceAccountName" . }}
securityContext: securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }} {{- toYaml .Values.podSecurityContext | nindent 8 }}
containers: containers:

View File

@@ -2,14 +2,14 @@
apiVersion: autoscaling/v2 apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler kind: HorizontalPodAutoscaler
metadata: metadata:
name: {{ include "myHelmChart.fullname" . }} name: {{ include "openresty.fullname" . }}
labels: labels:
{{- include "myHelmChart.labels" . | nindent 4 }} {{- include "openresty.labels" . | nindent 4 }}
spec: spec:
scaleTargetRef: scaleTargetRef:
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
name: {{ include "myHelmChart.fullname" . }} name: {{ include "openresty.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }} minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }} maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics: metrics:

View File

@@ -1,5 +1,5 @@
{{- if .Values.ingress.enabled -}} {{- if .Values.ingress.enabled -}}
{{- $fullName := include "myHelmChart.fullname" . -}} {{- $fullName := include "openresty.fullname" . -}}
{{- $svcPort := .Values.service.port -}} {{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} {{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
@@ -17,7 +17,7 @@ kind: Ingress
metadata: metadata:
name: {{ $fullName }} name: {{ $fullName }}
labels: labels:
{{- include "myHelmChart.labels" . | nindent 4 }} {{- include "openresty.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }} {{- with .Values.ingress.annotations }}
annotations: annotations:
{{- toYaml . | nindent 4 }} {{- toYaml . | nindent 4 }}

View File

@@ -1,9 +1,9 @@
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: {{ include "myHelmChart.fullname" . }} name: {{ include "openresty.fullname" . }}
labels: labels:
{{- include "myHelmChart.labels" . | nindent 4 }} {{- include "openresty.labels" . | nindent 4 }}
spec: spec:
type: {{ .Values.service.type }} type: {{ .Values.service.type }}
ports: ports:
@@ -12,4 +12,4 @@ spec:
protocol: TCP protocol: TCP
name: http name: http
selector: selector:
{{- include "myHelmChart.selectorLabels" . | nindent 4 }} {{- include "openresty.selectorLabels" . | nindent 4 }}

View File

@@ -2,9 +2,9 @@
apiVersion: v1 apiVersion: v1
kind: ServiceAccount kind: ServiceAccount
metadata: metadata:
name: {{ include "myHelmChart.serviceAccountName" . }} name: {{ include "openresty.serviceAccountName" . }}
labels: labels:
{{- include "myHelmChart.labels" . | nindent 4 }} {{- include "openresty.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }} {{- with .Values.serviceAccount.annotations }}
annotations: annotations:
{{- toYaml . | nindent 4 }} {{- toYaml . | nindent 4 }}

View File

@@ -1,9 +1,9 @@
apiVersion: v1 apiVersion: v1
kind: Pod kind: Pod
metadata: metadata:
name: "{{ include "myHelmChart.fullname" . }}-test-connection" name: "{{ include "openresty.fullname" . }}-test-connection"
labels: labels:
{{- include "myHelmChart.labels" . | nindent 4 }} {{- include "openresty.labels" . | nindent 4 }}
annotations: annotations:
"helm.sh/hook": test "helm.sh/hook": test
spec: spec:
@@ -11,5 +11,5 @@ spec:
- name: wget - name: wget
image: busybox image: busybox
command: ['wget'] command: ['wget']
args: ['{{ include "myHelmChart.fullname" . }}:{{ .Values.service.port }}'] args: ['{{ include "openresty.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never restartPolicy: Never

View File

@@ -1,14 +1,20 @@
# Default values for myHelmChart. # Default values for openresty.
# This is a YAML-formatted file. # This is a YAML-formatted file.
# Declare variables to be passed into your templates. # Declare variables to be passed into your templates.
replicaCount: 1 replicaCount: 1
image: image:
repository: nginx repository: harbor.avroid.tech/devops/openresty
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion. # Overrides the image tag whose default is the chart appVersion.
tag: "" tag: "1.21.4.1-0-alpine"
configMap:
enabled: false
annotations: {}
apiConfig: ""
luaScript: ""
imagePullSecrets: [] imagePullSecrets: []
nameOverride: "" nameOverride: ""
@@ -16,7 +22,7 @@ fullnameOverride: ""
serviceAccount: serviceAccount:
# Specifies whether a service account should be created # Specifies whether a service account should be created
create: true create: false
# Automatically mount a ServiceAccount's API credentials? # Automatically mount a ServiceAccount's API credentials?
automount: true automount: true
# Annotations to add to the service account # Annotations to add to the service account