- 一、创建一个chart模板
helm create nginx
- 二、helm的目录结构
- 三、修改value.yaml文件
# Default values for nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
name: web-nginx
image:
repository: acr-sit-sh-registry-vpc.cn-shanghai-finance-1.cr.aliyuncs.com/architect/nginx
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "v0.1"
``
deployment
```bash
kind: Deployment
apiVersion: apps/v1
metadata:
name: {{ .Values.name }}
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: web-nginx
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
ports:
- name: http
containerPort: 80
---
kind: Service
apiVersion: v1
metadata:
name: svc-nginx
spec:
ports:
- name: http
port: 80
targetPort: 80
selector:
app: nginx
type: NodePort
2 使用helm install 创建release
helm install test-nginx ../nginx/
3 检查服务:helm list
4 查看deployment和pod
kubectl get deploy,pod
5,检查服务后,可访问 nginx服务
http://10.136.209.214:32291/
10.136.209.214为node的IP。
32291为部署的服务的端口
若想能通过浏览器访问,需要关闭istio-injection,即istio-injection=disabled 。然后,重启nginx服务。
6、helm upgrade升级release
当我们想给我们的服务升级版本时,就需要使用到helm upgrade 命令非常简便快捷
修改values.yaml文件切换版本
helm upgrade web-nginx ../nginx/
若想能够在浏览器访问,需要做两个操作:
如果在这个状态,需要进行下面两种操作:
1)将对应的命名空间关闭istio自动注入。
2)重启pod服务,结果如下:
这种情况下,表名没有sidecar注入,访问浏览器即可
- 四、helm rollback回滚
假如在一次发布过程中,发生了不符合预期的事情,就需要使用 helm rollback 命令回滚到之前的发布版本。
查看test-nginx历史版本:
helm history web-nginx
回滚到版本1:
helm rollback web-nginx 1
回滚到版本2
用浏览器访问:
- 五、卸载一个版本
新版helm3卸载后不会保留历史版本,如果您在执行 helm uninstall 的时候提供 --keep-history 选项, Helm将会保存版本历史
helm uninstall web-nginx
release “test-nginx” uninstalled