Helm同时部署多个域名
啥也不说,直接上代码
helm create nginx-dev
[root@kp nginx-dev]# tree (删除了没用的 test 文件夹)
.
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ └── service.yaml
└── values.yaml
[root@kp nginx-dev]# cat Chart.yaml
# 添加了 icon, 规范参考:https://v3-0.docs.kubesphere.io/zh/docs/application-store/app-developer-guide/helm-specification/
apiVersion: v2
name: nginx-dev
description: A Helm chart for Kubernetes
icon: https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Nginx_logo.svg/500px-Nginx_logo.svg.png
type: application
version: 0.1.0
appVersion: 1.16.0
[root@kp nginx-dev]# cat values.yaml
''' 其他无修改,开启了ingress,并添加了一些内容 '''
ingress:
enabled: true
annotations:
# kubernetes.io/tls-acme: "true"
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: "http://www.baidu.com"
nginx.ingress.kubernetes.io/limit-rps: "100"
nginx.ingress.kubernetes.io/limit-rpm: "1000"
nginx.ingress.kubernetes.io/limit-connections: "200"
paths:
- /
hosts:
- host: chart-example1.local
- host: chart-example2.local
- host: chart-example3.local
- host: chart-example4.local
'''
[root@kp nginx-dev]# cat templates/ingress.yaml # 修改两个地方
''' 略
{{- $ingressPaths := .Values.ingress.paths -}} # 这里定义了一个变量
''' 略
{{- range $ingressPaths }} # 继承上面变量
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
''' 略
helm package nginx-dev/ # 会生成一个压缩包
上传到你的 helm-charts 仓库,我这里使用的 github (略);如果是github,需要生成参考url:
# helm repo index --url https://helmchars.github.io/helm-charts/ . 下面会多一个 index.yaml 文件
[root@kp ~]# helm repo list
Error: no repositories to show
[root@kp ~]# helm repo add myrepo https://helmchars.github.io/helm-charts
"myrepo" has been added to your repositories
[root@kp ~]# helm repo list
NAME URL
myrepo https://helmchars.github.io/helm-charts
[root@kp ~]# helm search repo nginx
NAME CHART VERSION APP VERSION DESCRIPTION
myrepo/nginx-dev 0.1.0 1.16.0 A Helm chart for Kubernetes
Last updated