Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions charts/arnor/.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/
26 changes: 26 additions & 0 deletions charts/arnor/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v2
name: arnor
description: A Helm chart for standard web application
maintainers:
- name: douban

# 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: 0.1.0

# 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"
145 changes: 145 additions & 0 deletions charts/arnor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Arnor

Arnor 并不是一个具体的 app, 本 Chart 用于一些简单的项目部署, 使用者在填写了镜像及域名配置后, 即可快速拉起一个 HTTP 应用。

## 使用步骤

1. `helm repo add douban https://douban.github.io/charts/`
2. `helm install my-app douban/arnor -f my-values.yaml`

## 镜像

- `image.repository`: 业务镜像仓库 (如 `registry.example.com/my-app`)
- `image.tag`: 镜像版本号 (如 `v1.0.0`)

## 主机名/域名路由

Arnor 可分别启用 Ingress 或 Envoy Gateway HTTPRoute, 两者互不依赖。

### Ingress 配置

```yaml
ingress:
enabled: true
className: nginx
hosts:
- host: app.example.com
paths:
- path: /
pathType: ImplementationSpecific
tls:
- secretName: app-example-com-tls
hosts:
- app.example.com
```

### HTTPRoute 配置

```yaml
httpRoute:
enabled: true
parentRefs:
- name: envoy-gateway-bundle
namespace: envoy-gateway-system
hostnames:
- app.example.com
extraPaths: []
```

## 挂载 Volume 与 Secret

1. 在 `volumes` 中定义所需卷 (ConfigMap、Secret、PVC 等)。
2. 在 `volumeMounts` 中将卷挂载到容器路径。

示例:

```yaml
volumes:
- name: app-config
configMap:
name: my-config
- name: extra-secret
secret:
secretName: my-app-secret
volumeMounts:
- name: app-config
mountPath: /etc/app
- name: extra-secret
mountPath: /var/run/secret
readOnly: true
```

## Vault 静态密钥注入

启用 `vaultStaticSecret.enabled` 后, Chart 会负责拉取 Vault 中的静态密钥并注入到 Kubernetes Secret 中; 需要在 `volumes` 与 `volumeMounts` 手动引用该 Secret 才能在容器内使用。

如果没有设置 `vaultStaticSecret.secretNameOverride`, secret 名字会与 fullname 完全相同, 也就是:

```bash
# release name 和 chart 同名时, 为 release name
arnor
# release name 和 chart 不同时, 为 release name - chart name
my-app-arnor
# 填写了 fullnameOverride 的情况下, 以 fullnameOverride 为准
my-fullname
# 详细逻辑请参考 _helpers.tpl 内的代码
```

```yaml
vaultStaticSecret:
enabled: true
mount: kv-v2
path: secret/data
secretNameOverride: my-secret

volumes:
- name: vault-secret
secret:
secretName: my-secret
volumeMounts:
- name: vault-secret
mountPath: /vault/secrets
readOnly: true
```

> 最终路径与 `path` 完全一致, 请确认 Vault 中已存在该路径。

## 完整示例

```yaml
image:
repository: registry.example.com/frontend
tag: v1.2.3

ingress:
enabled: true
className: nginx
hosts:
- host: frontend.example.com
paths:
- path: /
pathType: ImplementationSpecific

httpRoute:
enabled: false

volumes:
- name: env-secret
secret:
secretName: frontend-env
- name: vault-secret
secret:
secretName: frontend
volumeMounts:
- name: env-secret
mountPath: /app/.env
readOnly: true
- name: vault-secret
mountPath: /vault/data
readOnly: true

vaultStaticSecret:
enabled: true
secretNameOverride: frontend
```

22 changes: 22 additions & 0 deletions charts/arnor/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "arnor.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "arnor.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "arnor.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "arnor.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}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
73 changes: 73 additions & 0 deletions charts/arnor/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "arnor.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 "arnor.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 "arnor.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "arnor.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "arnor.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
VaultStaticSecret secretName
*/}}
{{- define "arnor.vaultStaticSecretDestination" -}}
{{- if .Values.vaultStaticSecret.secretNameOverride }}
{{- .Values.vaultStaticSecret.secretNameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- include "arnor.fullname" . }}
{{- end }}
{{- end }}
77 changes: 77 additions & 0 deletions charts/arnor/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "arnor.fullname" . }}
labels:
{{- include "arnor.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "arnor.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "arnor.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "arnor.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.args }}
args:
{{- toYaml . | nindent 12 }}
{{- end}}
{{- with .Values.env }}
env:
{{- toYaml . | nindent 12 }}
{{- end}}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.containerPort }}
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
Loading
Loading