helm常用命令
(1)release相关的:
helm create mychart //创建个chart,可以配置里面的信息
helm install chart-test mychart/ //用mychart模板,创建chart-test实例
helm install . 创建一个release实例
helm upgrade [RELEASE] [CHART] [flags] 升级一个版本
helm rollback [flags] [RELEASE] [REVISION] 回滚一个版本
helm delete release 删除创建的release
helm history 查看历史
helm status 获取release的状态信息
(2)chart相关的
helm serach
helm inspect 查看chart的详细信息
helm fetch 把chart下载下来
helm package 把chart打包
(2)release相关的
helm upgrade --set imageTag=1.17 web nginx #更改发布的配置
helm upgrade -f values.yaml web nginx #更改发布的配置
helm rollback test 1 #将应用回滚到第一个版本
helm uninstall test #卸载发行版
helm get all --revision 1 test #查看历史版本配置信息
(3)调试命令,确认信息
helm install chart-test --debug --dry-run mychart/
创建自己的chart
[root@master ~]# helm create mychart
Creating mychart
[root@master ~]# tree mychart
mychart
├── charts
├── Chart.yaml #当前chart的属性配置信息
├── templates #书写资源文件
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml #全局变量配置(templates能够使用)
[root@master ~]# egrep -v '^#|^$' mychart/Chart.yaml
apiVersion: v2
name: mychart
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.16.0
[root@master ~]# egrep -v '^#|^$|#' mychart/values.yaml
#######pod的信息
replicaCount: 1
image:
repository: nginx
pullPolicy: IfNotPresent
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
serviceAccount:
create: true
name:
podSecurityContext: {}
securityContext: {}
####service的信息
service:
type: ClusterIP
port: 80
####ingress的信息
ingress:
enabled: false
annotations: {}
hosts:
- host: chart-example.local
paths: []
tls: []
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}
安装自己的chart准备
书写资源文件deployment
[root@master ~]# kubectl create deployment test1 --image=nginx --dry-run='client' -o yaml > deployment.yaml
// kubectl create deployment test1 --image=nginx 将直接创建,我们需要yaml文件。
[root@master ~]# cat deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: test1
name: test1
spec:
replicas: 1
selector:
matchLabels:
app: test1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: test1
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
书写资源文件service
[root@master ~]# kubectl apply -f deployment.yaml
[root@master ~]# kubectl expose deployment test1 --port=80 --target-port=80 --type=NodePort --dry-run=client -oyaml >service.yaml
[root@master ~]# cat service.yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: test1
name: test1
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: test1
type: NodePort
[root@master ~]# kubectl delete -f deployment.yaml
[root@master ~]# rm -rf mychart/templates/*
[root@master ~]# mv *.yaml mychart/templates/
[root@master ~]# ls mychart/templates/
deployment.yaml service.yaml
安装
[root@master ~]# helm install chart-test mychart/
NAME: chart-test
LAST DEPLOYED: Mon May 2 03:41:51 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
[root@master ~]# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/test1-857949f6d6-wtsnn 1/1 Running 0 56s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/test1 NodePort 10.99.28.57 <none> 80:32287/TCP 56s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/test1 1/1 1 1 56s
NAME DESIRED CURRENT READY AGE
replicaset.apps/test1-857949f6d6 1 1 1 56s
升级
[root@master ~]# helm upgrade chart-test mychart/
Release "chart-test" has been upgraded. Happy Helming!
NAME: chart-test
LAST DEPLOYED: Mon May 2 03:46:08 2022
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None
打包
[root@master ~]# helm package mychart/
Successfully packaged chart and saved it to: /root/mychart-0.1.0.tgz