Helm架构node
图片来自IBM Developer Blog。linux
部署Helm
本文只展现二进制方式安装,其余方式可查看官方文档。nginx
下载安装包git
[root@K8S-PROD-M1 workspace]# wget https://get.helm.sh/helm-v3.4.1-linux-amd64.tar.gz
解压安装包
[root@K8S-PROD-M1 workspace]# tar -zxvf helm-v3.4.1-linux-amd64.tar.gz
[root@K8S-PROD-M1 workspace]# mv linux-amd64/helm /usr/local/bin/helm
与K8S 交互
采用与执行kubectl命令时的与K8S集群进行交互的配置文件:/root/.kube/config。github
Chart仓库操做
经常使用仓库:docker
gitlab:https://charts.gitlab.ioapi
harbor:https://helm.goharbor.io架构
elastic:https://helm.elastic.comide
bitnami:https://charts.bitnami.com/bitnamiwordpress
仓库操做:
[root@K8S-PROD-M1 ~]# helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
[root@K8S-PROD-M1 ~]# helm repo add brigade https://brigadecore.github.io/charts
[root@K8S-PROD-M1 ~]# helm repo add bitnami https://charts.bitnami.com/bitnami
[root@K8S-PROD-M1 ~]# helm repo add harbor https://helm.goharbor.io
[root@K8S-PROD-M1 ~]# helm repo update
[root@K8S-PROD-M1 ~]# helm repo list
[root@K8S-PROD-M1 ~]# helm search repo stable
[root@K8S-PROD-M1 ~]# helm search repo brigade
[root@K8S-PROD-M1 ~]# helm repo remove aliyun
[root@K8S-PROD-M1 ~]# helm search hub
[root@K8S-PROD-M1 ~]# helm search hub wordpress
其余命令
heml env
helm help
经常使用选项
--dry-run
-g, --generate-name
--no-hooks
测试Helm
安装应用
[root@K8S-PROD-M1 ~]# helm search repo nginx
[root@K8S-PROD-M1 ~]# helm install my-nginx bitnami/nginx
[root@K8S-PROD-M1 ~]# helm install my-nginx bitnami.nginx.tgz
[root@K8S-PROD-M1 ~]# helm install my-nginx bitnami/nginx/
[root@K8S-PROD-M1 ~]# helm install --set name=prod my-nginx bitnami/nginx/
[root@K8S-PROD-M1 ~]# helm install --set-string long_int=123 my-nginx bitnami/nginx/
[root@K8S-PROD-M1 ~]# helm install --set-file my_script=dothings.sh my-nginx bitnami/nginx/
[root@K8S-PROD-M1 ~]# helm install --set foo=bar --set bar=foo my-nginx bitnami/nginx/
[root@K8S-PROD-M1 ~]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
my-nginx default 1 2020-11-30 15:29:44.362452632 +0800 CST deployed nginx-8.2.0 1.19.5
[root@K8S-PROD-M1 ~]# helm status my-nginx
NAME: my-nginx
LAST DEPLOYED: Mon Nov 30 15:29:44 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
...
[root@K8S-PROD-M1 ~]# helm history my-nginx
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Mon Nov 30 15:29:44 2020 deployed nginx-8.2.0 1.19.5 Install complete
[root@K8S-PROD-M1 ~]# helm rollback my-nginx 1
[root@K8S-PROD-M1 ~]# helm uninstall my-nginx
[root@K8S-PROD-M1 ~]# helm list --all
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
my-nginx default 1 2020-11-30 15:29:44.362452632 +0800 CST uninstalled nginx-8.2.0 1.19.5
[root@K8S-PROD-M1 ~]# helm delete my-nginx
release "my-nginx" uninstalled
自定义参数安装应用
Helm 中支持使用自定义yaml文件和 --set命令参数对要安装的应用进行参数配置,首先查看可配置参数:
[root@K8S-PROD-M1 ~]# helm show values bitnami/nginx
使用自定义values.yaml文件安装应用
[root@K8S-PROD-M1 nginx]# cat > values.yaml << EOF
image:
registry: docker.io
repository: bitnami/nginx
resources:
limits:
cpu: 1000m
memory: 512Mi
requests:
cpu: 1000m
memory: 512Mi
EOF
helm install -f values.yaml bitnami/nginx
使用--set配置参数进行安装应用
--set参数是在使用helm命令时候添加的参数,能够在执行helm安装与更新应用时使用,多个参数间用”,“隔开。
若是配置文件和--set同时使用,则--set设置的参数会覆盖配置文件中的参数配置。
对于--set配置参数,Helm官方对于不一样的配置类型给出了不一样的写法,以下:
[root@K8S-PROD-M1 nginx]# helm install --set 'registry.registry=docker.io,registry.repository=bitnami/nginx' bitnami/nginx
升级应用
[root@K8S-PROD-M1 nginx]# cat > values.yaml << EOF
service.type: NodePort
service.nodePorts.http: 30002
EOF
[root@K8S-PROD-M1 nginx]# helm upgrade -f values.yaml my-nginx bitnami/nginx -n default
[root@K8S-PROD-M1 nginx]# helm get values my-nginx
渲染模板
查看经过指定的参数渲染的Kubernetes部署资源模板:
[root@K8S-PROD-M1 ~]# helm template bitnami/nginx
开发Chart
建立chart
[root@K8S-PROD-M1 ~]# mkdir -p /root/workspace/helm
[root@K8S-PROD-M1 ~]# cd /root/workspace/helm
[root@K8S-PROD-M1 helm]# helm create chart-demo
[root@K8S-PROD-M1 helm]# tree chart-demo/
chart-demo/
├── charts #该目录保存其余依赖的 chart(子 chart)
├── Chart.yaml
├── templates #chart配置模板,用于渲染最终的Kubernetes YAML文件
│ ├── deployment.yaml #Kubernetes deployment 配置
│ ├── _helpers.tpl #用于建立模板时的帮助类
│ ├── hpa.yaml
│ ├── ingress.yaml #Kubernetes ingress配置
│ ├── NOTES.txt #用户运行helm install时候的提示信息
│ ├── serviceaccount.yaml #Kubernetes serviceaccount配置
│ ├── service.yaml #Kubernetes service配置
│ └── tests
│ └── test-connection.yaml
└── values.yaml # 定义chart模板中的自定义配置的默认值,能够在执行helm install或helm update的时候覆盖
3 directories, 10 files
修改Chart
上一步建立的是一个标准的chart目录结构,能够编辑相应配置从而建立本身的chart。
[root@K8S-PROD-M1 helm]# helm lint chart-demo/
==> Linting chart-demo/
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed
[root@K8S-PROD-M1 helm]# helm package chart-demo/Successfully packaged chart and saved it to: /root/workspace/helm/chart-demo-0.1.0.tgz