Skip to content

Commit

Permalink
helm chart書きかけ
Browse files Browse the repository at this point in the history
  • Loading branch information
na2na-p committed Nov 27, 2023
1 parent 185e799 commit d464835
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ built/
.env
.idea
configmap.yml
values.yaml
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.yaml
23 changes: 23 additions & 0 deletions infra/k8s/helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions infra/k8s/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: jetdisc
description: A Helm chart for Kubernetes

# 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: 3.0.0-beta1

# 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: "1.16.0"
27 changes: 27 additions & 0 deletions infra/k8s/helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
1. `jetdisc` アプリケーションがKubernetesクラスターにデプロイされました。

2. アプリケーションは、指定された設定に基づいて起動しています。設定の詳細は `values.yaml` ファイルを参照してください。

3. アプリケーションは、PythonとNode.js環境で構築されており、Dockerfileに定義された手順に従ってコンテナイメージがビルドされています。

4. このデプロイメントには、Kubernetes APIへのアクセスが必要な場合に使用するための `ServiceAccount` が含まれているかもしれません。APIとの直接のやり取りが必要ない場合は、このアカウントは使用されません。

5. アプリケーションのスケーリングにはHPA(Horizontal Pod Autoscaler)が設定されており、CPU使用率やメモリ使用率に基づいて自動的にポッドの数が調整されます。HPAの設定は `values.yaml` で確認および変更が可能です。

6. デプロイメントの状況を確認するには、以下のコマンドを実行してください:

```
kubectl get deployment {{ include "jetdisc.fullname" . }}
```

7. リリースの削除には、以下のコマンドを実行してください:

```
helm delete {{ include "jetdisc.fullname" . }}
```

8. アプリケーションのログを確認するには、以下のコマンドを実行してください:

```
kubectl logs -f deployment/{{ include "jetdisc.fullname" . }}
```
62 changes: 62 additions & 0 deletions infra/k8s/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "jetdisc.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | 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 "jetdisc.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | 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 }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "jetdisc.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "jetdisc.labels" -}}
helm.sh/chart: {{ include "jetdisc.chart" . }}
{{ include "jetdisc.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "jetdisc.selectorLabels" -}}
app.kubernetes.io/name: {{ include "jetdisc.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "jetdisc.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "jetdisc.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
31 changes: 31 additions & 0 deletions infra/k8s/helm/templates/jetdisc/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "jetdisc.fullname" . }}
labels: {{- include "jetdisc.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ include "jetdisc.name" . }}
strategy:
type: Recreate
template:
metadata:
labels:
app: {{ include "jetdisc.name" . }}
version: '{{ .Values.image.tag }}'
spec:
containers:
- name: {{ .Chart.Name }}
image: '{{ .Values.image.repository }}:{{ .Values.image.tag }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: DISCORD_APP_TOKEN
value: {{ .Values.secret.DISCORD_APP_TOKEN }}
- name: BOT_NAME
value: {{ .Values.secret.BOT_NAME }}
- name: SET_COMMANDS_TARGET_SERVERS
value: {{ .Values.secret.SET_COMMANDS_TARGET_SERVERS }}
resources: {{- toYaml .Values.resources | nindent 12 }}
restartPolicy: Always
28 changes: 28 additions & 0 deletions infra/k8s/helm/templates/jetdisc/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.hpa.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "jetdisc.fullname" . }}
labels:
{{- include "jetdisc.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "jetdisc.fullname" . }}
minReplicas: {{ .Values.hpa.minReplicas }}
maxReplicas: {{ .Values.hpa.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
# - type: Resource
# resource:
# name: memory
# target:
# type: Utilization
# averageUtilization: {{ .Values.hpa.targetMemoryUtilizationPercentage }}
{{- end }}
Empty file.
27 changes: 27 additions & 0 deletions infra/k8s/helm/values.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
replicaCount: 1

image:
repository: na2na/jetdisc
tag: "preview"
pullPolicy: IfNotPresent

secret:
name: jetdisc-secret
DISCORD_APP_TOKEN: ""
BOT_NAME: "2na2"
SET_COMMANDS_TARGET_SERVERS: ""

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

hpa:
enabled: true
minReplicas: 1
maxReplicas: 1
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80

0 comments on commit d464835

Please sign in to comment.