实战
准备
创建namespace
kubectl create ns study-ns创建Chart
helm create study所需文件
tree ./study/
./study/
├── charts
├── Chart.yaml
├── templates
│ ├── NOTES.txt
│ ├── web-deployment.yaml
│ └── web-svc.yaml
├── values-2.yaml
└── values.yamlstudy/templates/NOTES.txt
# ----------- Welcome to Helm's World ------------- #
Congratulation:
{{ .Values.study_apps.image }}:{{ .Values.study_apps.tags }}
Deploy succeed!study/templates/web-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
namespace: {{ .Values.study_apps.namespace }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ .Values.labels.app }}
template:
metadata:
labels:
app: {{ .Values.labels.app }}
spec:
containers:
- name: nginx
image: {{ .Values.study_apps.image }}:{{ .Values.study_apps.tags }}
imagePullPolicy: {{ .Values.study_apps.imagePullPolicy }}
ports:
- containerPort: 80study/templates/web-svc.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: {{ .Values.labels.app }}
name: web-svc
namespace: {{ .Values.study_apps.namespace }}
spec:
type: NodePort
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
nodePort: 30080
selector:
app: webstudy/values.yaml
study_apps:
namespace: study-ns
image: nginx
tags: 1.16.0
imagePullPolicy: IfNotPresent
replicas: 2
labels:
app: webstudy/values-v2.yaml
study_apps:
namespace: study-ns
image: nginx
tags: latest
imagePullPolicy: IfNotPresent
replicas: 2
labels:
app: webstudy/Chart.yaml
...
version: 1.0
appVersion: "1.16.0"部署
helm install web study -n study-ns查看
helm list -n study-ns
helm -n study-ns history webcurl -I 127.0.0.1:30080
HTTP/1.1 200 OK
Server: nginx/1.16.0
Date: Fri, 21 Mar 2025 15:12:19 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 23 Apr 2019 10:18:21 GMT
Connection: keep-alive
ETag: "5cbee66d-264"
Accept-Ranges: bytes升级
# 在升级时,确保 Chart 目录中包含更新后的 Chart.yaml 文件,
...
version: 2.0
appVersion: "latest"
...
# 然后运行
helm -n study-ns upgrade web study -f study/values-v2.yaml查看
helm list -n study-ns
helm -n study-ns history web
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Fri Mar 21 23:24:35 2025 superseded study-1 1.16.0 Install complete
2 Fri Mar 21 23:29:03 2025 deployed study-2 latest Upgrade completecurl -I 127.0.0.1:30080
HTTP/1.1 200 OK
Server: nginx/1.27.4
Date: Fri, 21 Mar 2025 15:14:11 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Wed, 05 Feb 2025 11:06:32 GMT
Connection: keep-alive
ETag: "67a34638-267"
Accept-Ranges: bytes回滚
helm -n study-ns rollback web 1查看
helm -n study-ns history web
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Fri Mar 21 23:24:35 2025 superseded study-1 1.16.0 Install complete
2 Fri Mar 21 23:29:03 2025 superseded study-2 latest Upgrade complete
3 Fri Mar 21 23:29:50 2025 deployed study-1 1.16.0 Rollback to 1curl -I 127.0.0.1:30080
HTTP/1.1 200 OK
Server: nginx/1.16.0
Date: Fri, 21 Mar 2025 15:17:36 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 23 Apr 2019 10:18:21 GMT
Connection: keep-alive
ETag: "5cbee66d-264"
Accept-Ranges: bytesLast updated