Helm介绍
001 Helm是一个Kubernetes的包管理工具
002 就像Linux下的包管理器,如yum/apt等
003 可以很方便的将之前打包好的yaml文件部署到kubernetes上
-----------------------------------------------------------------------------
Helm有3个重要概念:
• helm:一个命令行客户端工具,主要用于Kubernetes应用chart的创建、打包、发布和管理。
• Chart:应用描述,一系列用于描述 k8s 资源相关文件的集合。
• Release:基于Chart的部署实体,一个 chart 被 Helm 运行后将会生成对应的一个 release;将在
k8s中创建出真实运行的资源对象
Helm的安装
[root@k8s-m1 helm]# tar -xzvf helm-v3.4.2-linux-amd64.tar.gz
[root@k8s-m1 helm]# cd linux-amd64/
[root@k8s-m1 linux-amd64]# ls
helm LICENSE README.md
[root@k8s-m1 linux-amd64]# mv helm /usr/bin/
Helm基本使用
Helm的创建与部署
[root@k8s-m1 helm]# helm create mychart
Creating mychart
[root@k8s-m1 helm]# cd mychart/
[root@k8s-m1 mychart]# ls
charts Chart.yaml templates values.yaml
----------------------------------------------------------------------------------
#values.yaml用于存储 templates 目录中模板文件中用到变量的值。
vi values.yaml
image:
repository: nginx
tag: "1.16"
----------------------------------------------------------------------------------
#安装一个chart
[root@k8s-m1 helm]# helm install web mychart
#列出release
[root@k8s-m1 helm]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
web default 1 2021-12-18 deployed mychart-0.1.0 1.16.0
----------------------------------------------------------------------------------
#显示已命名版本的状态
[root@k8s-m1 helm]# helm status web
LAST DEPLOYED: Sat Dec 18 15:15:25 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
----------------------------------------------------------------------------------
#查看相关资源
[root@k8s-m1 helm]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/web-mychart-68cb98d9d8-vwlft 1/1 Running 0 6m38s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.0.0.1 443/TCP 6d1h
service/web-mychart ClusterIP 10.0.0.123 80/TCP 6m38s
[root@k8s-m1 helm]# curl -I 10.0.0.123
HTTP/1.1 200 OK
Server: nginx/1.16.1
----------------------------------------------------------------------------------
#下载一个release。可用子命令:all、hooks、manifest、notes、values
[root@k8s-m1 helm]# helm get all web
......
#查看所有的ymal
[root@k8s-m1 helm]# helm get manifest web
......
Helm的升级
#values,-f:指定YAML文件覆盖值
[root@k8s-m1 helm]# vi values.yaml
image:
repository: nginx
tag: "1.17"
[root@k8s-m1 helm]# helm upgrade -f values.yaml web mychart
Release "web" has been upgraded. Happy Helming!
NAME: web
LAST DEPLOYED: Sat Dec 18 15:35:12 2021
NAMESPACE: default
STATUS: deployed
REVISION: 2
[root@k8s-m1 helm]# curl -I 10.0.0.123
HTTP/1.1 200 OK
Server: nginx/1.17.10
----------------------------------------------------------------------------
#set:在命令行上指定覆盖值
[root@k8s-m1 helm]# helm upgrade --set image.tag=1.18 web mychart
Release "web" has been upgraded. Happy Helming!
NAME: web
LAST DEPLOYED: Sat Dec 18 15:38:16 2021
NAMESPACE: default
STATUS: deployed
REVISION: 3
[root@k8s-m1 helm]# curl -I 10.0.0.123
HTTP/1.1 200 OK
Server: nginx/1.18.0
Helm的回滚卸载
#回滚
[root@k8s-m1 helm]# helm history web
REVISION UPDATED STATUS CHART APP VERSION
1 Sat Dec 18 superseded mychart-0.1.0 1.16.0 Install complete
2 Sat Dec 18 superseded mychart-0.1.0 1.16.0 Upgrade complete
3 Sat Dec 18 deployed mychart-0.1.0 1.16.0 Upgrade complete
[root@k8s-m1 helm]# helm rollback web 2
Rollback was a success! Happy Helming!
[root@k8s-m1 helm]# curl -I 10.0.0.123
HTTP/1.1 200 OK
Server: nginx/1.17.10
----------------------------------------------------------------------------
#卸载
[root@k8s-m1 helm]# helm uninstall web
release "web" uninstalled
自制chart
创建chart
[root@k8s-m1 helm]# mkdir -p chart
[root@k8s-m1 helm]# cd chart
[root@k8s-m1 chart]# mkdir -p templates
Chart.yaml
[root@k8s-m1 chart]# vi Chart.yaml
apiVersion: v2
name: mychart
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.16.0
values.yaml
[root@k8s-m1 chart]# vi values.yaml
replicaCount: 1
image:
repository: nginx
tag: "1.16"
selectorLabels: "nginx"
deployment.yaml
[root@k8s-m1 templates]# vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Values.selectorLabels }}
strategy: {}
template:
metadata:
labels:
app: {{ .Values.selectorLabels }}
spec:
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: nginx
service.yaml
[root@k8s-m1 templates]# vi service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: web
name: {{ .Release.Name }}
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: {{ .Values.selectorLabels }}
添加相关文件
[root@k8s-m1 templates]# touch _helpers.tpl
[root@k8s-m1 templates]# touch NOTES.txt
[root@k8s-m1 templates]# vi NOTES.txt
hello
调试
[root@k8s-m1 helm]# helm install web3 --dry-run chart
MANIFEST:
---
# Source: mychart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: web
name: web3
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: web3
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:1.16
name: nginx
NOTES:
hello
安装部署
[root@k8s-m1 helm]# helm install web3 chart
NAME: web3
LAST DEPLOYED: Sat Dec 18 16:07:25 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
hello
[root@k8s-m1 helm]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/web3-6d4cf56db6-zsp22 1/1 Running 0 36s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.0.0.1 443/TCP 6d2h
service/web3 ClusterIP 10.0.0.6 80/TCP 36s
[root@k8s-m1 helm]# curl -I 10.0.0.6
HTTP/1.1 200 OK
Server: nginx/1.16.1
卸载
[root@k8s-m1 helm]# helm uninstall web3
release "web3" uninstalled
Chart模板
函数与管道
quote:将值转换为字符串
#gpu是boolean,直接取会报错
[root@k8s-m1 chart]# vi values.yaml
replicaCount: 1
image:
repository: nginx
tag: "1.16"
selectorLabels: "nginx"
nodeSelector:
gpu: true
--------------------------------------------------------------------------------
#quote .Values.nodeSelector.gpu
[root@k8s-m1 chart]# vi templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Values.selectorLabels }}
strategy: {}
template:
metadata:
labels:
app: {{ .Values.selectorLabels }}
spec:
nodeSelector:
gpu: {{ quote .Values.nodeSelector.gpu }}
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: nginx
----------------------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web1 --dry-run ../chart
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: web1
spec:
replicas:
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
gpu: "true"
containers:
- image: nginx:1.16
name: nginx
default:设置默认值,如果获取的值为空则为默认值
[root@k8s-m1 chart]# vi values.yaml
replicaCount: 1
image:
repository: nginx
tag: "1.16"
selectorLabels: "nginx"
nodeSelector:
gpu: true
labels:
app: ""
--------------------------------------------------------------------------------
[root@k8s-m1 chart]# vi templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: {{ .Values.labels.app | default "nginx" }}
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Values.selectorLabels }}
strategy: {}
template:
metadata:
labels:
app: {{ .Values.selectorLabels }}
spec:
nodeSelector:
gpu: {{ quote .Values.nodeSelector.gpu }}
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: nginx
--------------------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web2 --dry-run ../chart
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: web2
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
gpu: "true"
containers:
- image: nginx:1.16
name: nginx
--------------------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web2 --set labels.app=abc --dry-run ../chart
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: abc
name: web2
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
gpu: "true"
containers:
- image: nginx:1.16
name: nginx
toYaml引用一块YAML内容
#resources
[root@k8s-m1 chart]# vi values.yaml
replicaCount: 1
image:
repository: nginx
tag: "1.16"
selectorLabels: "nginx"
nodeSelector:
gpu: true
labels:
app: nginx
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
----------------------------------------------------------------------------
#{{ toYaml .Values.resources | nindent 10 }}
[root@k8s-m1 templates]# vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: {{ .Values.labels.app | default "nginx" }}
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Values.selectorLabels }}
strategy: {}
template:
metadata:
labels:
app: {{ .Values.selectorLabels }}
spec:
nodeSelector:
gpu: {{ quote .Values.nodeSelector.gpu }}
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: nginx
resources:
{{- toYaml .Values.resources | nindent 10 }}
---------------------------------------------------------------------------------
#运行
[root@k8s-m1 chart]# helm install web1 --dry-run ../chart
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: web1
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
gpu: "true"
containers:
- image: nginx:1.16
name: nginx
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
流程控制
if/else
[root@k8s-m1 chart]# vi values.yaml
replicaCount: 1
image:
repository: nginx
tag: "1.16"
selectorLabels: "nginx"
nodeSelector:
gpu: true
labels:
app: nginx
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
ingress:
enabled: true
-----------------------------------------------------------------------------
[root@k8s-m1 templates]# vi ingress.yaml
{{ if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
{{ end }}
-----------------------------------------------------------------------------------
#运行
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
# Source: mychart/templates/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
------------------------------------------------------------------------------
#判断是否是空的集合
[root@k8s-m1 chart]# vi values.yaml
replicaCount: 1
image:
repository: nginx
tag: "1.16"
selectorLabels: "nginx"
nodeSelector:
gpu: true
labels:
app: nginx
resources: {}
ingress:
enabled: true
-------------------------------------------------------------------------
[root@k8s-m1 chart]# vi templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: {{ .Values.labels.app | default "nginx" }}
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Values.selectorLabels }}
strategy: {}
template:
metadata:
labels:
app: {{ .Values.selectorLabels }}
spec:
nodeSelector:
gpu: {{ quote .Values.nodeSelector.gpu }}
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: nginx
{{- if .Values.image.resources }}
resources:
{{ toYaml .Values.resources | nindent 10 }}
{{- end }}
-------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: web
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
gpu: "true"
containers:
- image: nginx:1.16
name: nginx
range循环
#遍历数据test
[root@k8s-m1 chart]# vi values.yaml
replicaCount: 1
image:
repository: nginx
tag: "1.16"
selectorLabels: "nginx"
nodeSelector:
gpu: true
labels:
app: nginx
resources: {}
ingress:
enabled: true
test:
- 1
- 2
- 3
-------------------------------------------------------------------------------
[root@k8s-m1 chart]# vi templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}
data:
test: |
{{- range .Values.test }}
{{ . }}
{{- end }}
-------------------------------------------------------------------
#运行效果
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
apiVersion: v1
kind: ConfigMap
metadata:
name: web
data:
test: |
1
2
3
with
#labels
[root@k8s-master mychart]# vi values.yaml
replicaCount: 1
image:
repository: nginx
tag: "1.16"
selectorLabels: "nginx"
nodeSelector:
gpu: true
labels:
app: nginx
resources: {}
ingress:
enabled: true
test:
- 1
- 2
- 3
labels:
project: "ms"
app: "gateway"
-------------------------------------------------------------------------------
[root@k8s-m1 chart]# vi templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
{{- with .Values.labels }}
project: {{ .project }}
app: {{ .app }}
{{- end }}
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Values.selectorLabels }}
strategy: {}
template:
metadata:
labels:
app: {{ .Values.selectorLabels }}
spec:
nodeSelector:
gpu: {{ quote .Values.nodeSelector.gpu }}
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: nginx
{{- if .Values.image.resources }}
resources:
{{ toYaml .Values.resources | nindent 10 }}
{{- end }}
-------------------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
project: ms
app: gateway
name: web
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
gpu: "true"
containers:
- image: nginx:1.16
name: nginx
-------------------------------------------------------------------------------
#with块限制了变量作用域,也就是无法直接引用模板对象,例如.Values、.Release
#如果还想使用,可以定义变量来解决该问题
[root@k8s-master templates]# vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
{{- $rs:= .Values.replicaCount -}}
{{- with .Values.labels }}
project: {{ .project }}
app: {{ .app }}{{ $rs }}
{{- end }}
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Values.selectorLabels }}
strategy: {}
template:
metadata:
labels:
app: {{ .Values.selectorLabels }}
spec:
nodeSelector:
gpu: {{ quote .Values.nodeSelector.gpu }}
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: nginx
{{- if .Values.image.resources }}
resources:
{{ toYaml .Values.resources | nindent 10 }}
{{- end }}
-------------------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
project: ms
app: gateway1
name: web
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
gpu: "true"
containers:
- image: nginx:1.16
name: nginx
变量
with、range结合使用
[root@k8s-m1 chart]# vi values.yaml
replicaCount: 1
image:
repository: nginx
tag: "1.16"
selectorLabels: "nginx"
nodeSelector:
gpu: true
labels:
app: nginx
resources: {}
ingress:
enabled: true
test:
- 1
- 2
- 3
labels:
project: "ms"
app: "gateway"
env:
NAME: "gateway"
JAVA_OPTS: "-Xmx1G"
-----------------------------------------------------------------------
[root@k8s-master templates]# vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
{{- $rs:= .Values.replicaCount -}}
{{- with .Values.labels }}
project: {{ .project }}
app: {{ .app }}{{ $rs }}
{{- end }}
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Values.selectorLabels }}
strategy: {}
template:
metadata:
labels:
app: {{ .Values.selectorLabels }}
spec:
nodeSelector:
gpu: {{ quote .Values.nodeSelector.gpu }}
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: nginx
{{- if .Values.image.resources }}
resources:
{{ toYaml .Values.resources | nindent 10 }}
{{- end }}
env:
{{- range $k,$v:= .Values.env }}
- name: {{ $k }}
value: {{ $v | quote }}
{{- end }}
----------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web --dry-run ../chart/
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
project: ms
app: gateway1
name: web
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
gpu: "true"
containers:
- image: nginx:1.16
name: nginx
env:
- name: JAVA_OPTS
value: "-Xmx1G"
- name: NAME
value: "gateway"
#之所以不用toYaml,是因为env是数组方式表示
命名模板
#template指令是将一个模板包含在另一个模板中的方法。
#但是,template函数不能用于Go模板管道。
#为了解决该问题,引入include指令。
[root@k8s-m1 chart]# vi templates/_helpers.tpl
{{- define "fullname" -}}
{{- .Release.Name }}-{{ .Chart.Name }}
{{- end -}}
{{- define "labels" -}}
app: "gateway"
project: "ms"
{{- end}}
------------------------------------------------------------------------
[root@k8s-m1 chart]# vi templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
{{- include "labels" .| nindent 4}}
name: {{ template "fullname" . }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Values.selectorLabels }}
strategy: {}
template:
metadata:
labels:
app: {{ .Values.selectorLabels }}
spec:
nodeSelector:
gpu: {{ quote .Values.nodeSelector.gpu }}
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: nginx
{{- if .Values.image.resources }}
resources:
{{ toYaml .Values.resources | nindent 10 }}
{{- end }}
env:
{{- range $k,$v:= .Values.env }}
- name: {{ $k }}
value: {{ $v | quote }}
{{- end }}
-------------------------------------------------------------------------------
[root@k8s-m1 chart]# helm install web --dry-run ../chart
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: "gateway"
project: "ms"
name: web-mychart
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
gpu: "true"
containers:
- image: nginx:1.16
name: nginx
env:
- name: JAVA_OPTS
value: "-Xmx1G"
- name: NAME
value: "gateway"
chart的通用
#打包chart
[root@k8s-m1 helm]# helm package chart
Successfully packaged chart and saved it to: /root/helm/mychart-0.1.0.tgz
[root@k8s-m1 demo]# vi values.yaml
replicaCount: 1
image:
repository: nginx
tag: "latest"
service:
type: ClusterIP
port: 80
nodeport: 300001
[root@k8s-m1 demo]# helm install web --set image.tag=1.18 --set service.type=NodePort --set service.nodeport=30010 ../demo
[root@k8s-m1 demo]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/demo-web-7bbfdb894f-6bpfl 1/1 Running 0 10s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/demo-web NodePort 10.0.0.173 80:30010/TCP 10s
service/kubernetes ClusterIP 10.0.0.1 443/TCP 6d5h
http://192.168.153.25:30010/
----------------------------------------------------------------------------------
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
使用Harbor作为Chart仓库
启用Harbor的Chart仓库服务
[root@harbor harbor]# ./install.sh --with-chartmuseum
安装push插件
[root@k8s-m1 helm]# tar xzvf helm-push_0.9.0_linux_amd64.tar.gz
[root@k8s-m1 helm]# cd bin/
[root@k8s-m1 bin]# ls
helmpush
[root@k8s-m1 helm]# mkdir -p /root/.local/share/helm/plugins/helm-push
[root@k8s-m1 helm]# mv bin/ plugin.yaml /root/.local/share/helm/plugins/helm-push/
推送
[root@k8s-m1 helm]# helm push demo-0.1.0.tgz --username admin --password Harbor12345 http://192.168.153.20/chartrepo/library
Pushing demo-0.1.0.tgz to http://192.168.153.20/chartrepo/library...
Done.
添加repo
[root@k8s-m1 helm]# helm repo add myrepo http://192.168.153.20/chartrepo/library
"myrepo" has been added to your repositories
[root@k8s-m1 helm]# helm repo list
NAME URL
myrepo http://192.168.153.20/chartrepo/library
[root@k8s-m1 helm]# helm repo remove myrepo
"myrepo" has been removed from your repositories
部署
[root@k8s-m1 helm]# helm install web3 --version 0.1.0 myrepo/demo
[root@k8s-m1 helm]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
web3 default 1 2021-12-18 19:35:28.887231627 +0800 CST deployed demo-0.1.0 1.16.0
[root@k8s-m1 demo]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/demo-web3-75cc95bdc4-pt5sk 1/1 Running 0 2m5s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/demo-web3 ClusterIP 10.0.0.133 80/TCP 2m6s
service/kubernetes ClusterIP 10.0.0.1 443/TCP 6d5h
[root@k8s-m1 demo]# curl -I 10.0.0.133
HTTP/1.1 200 OK
Server: nginx/1.21.4