Helm部署与使用
1 概况及其部署1.1 概念Helm是一个kubernetes的包管理工具,就像Linux下的包管理器,如yum、apt等,可以很方便的将之前打包好的yaml文件部署到kubernetes上。Helm有3个重要概念:helm:一个命令行客户端工具,主要用于kubernetes应用chart的创建、打包、发布和管理。chart:应用描述,一系列用于描述kubernetes资源相关文件的集合。rele
目录
1 概况及其部署
1.1 概念
- Helm是一个kubernetes的包管理工具,就像Linux下的包管理器,如yum、apt等,可以很方便的将之前打包好的yaml文件部署到kubernetes上。
- Helm有3个重要概念:
-
- helm:一个命令行客户端工具,主要用于kubernetes应用chart的创建、打包、发布和管理。
- chart:应用描述,一系列用于描述kubernetes资源相关文件的集合。
- release:基于chart的部署实体,一个chart被Helm运行后将会生成对应的一个release,将在kubernetes中创建出真实运行的资源对象。
1.2 示意图
- 2019年11月13日,Helm团队发布Helm v3的第一个稳定版本。
- 该版本主要变化如下:
-
- ①最明显的变化是Tiller删除。
-
- ②release名称可以在不同的命名空间重用。
- ③支持将chart推动到Docker镜像仓库中。
- ④使用JSONSchema验证chart values。
- ⑤其他。
1.3 安装部署
下载Helm,最新版本请到Releases · helm/helm · GitHub查看:
wget https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz
解压Helm到/usr/bin目录:
tar -zxvf helm-v3.2.1-linux-amd64.tar.gz
cd linux-amd64/ && mv helm /usr/bin/
2 配置使用
2.1 镜像仓库
- 阿里云仓库:https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
- 官方仓库:https://hub.kubeapps.com/charts/incubator(国外资源,强烈不推荐)
2.2 添加仓库
添加仓库
helm repo add 仓库名 仓库地址
更新仓库
helm repo update
例子:添加阿里云仓库,并更新
helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo update
2.3 helm的常用命令
命令 |
描述 |
create |
创建一个chart并指定名字 |
dependency |
管理chart依赖 |
get |
下载一个release。可用的子命令:all、hooks、manifest、notes、values。 |
history |
获取release历史。 |
install |
安装一个chart。 |
list |
列出release。 |
package |
将chart目录打包到chart存档文件中。 |
pull |
从远程仓库中下载chart并解压到本地。比如:helm install stable/mysql --untar。 |
repo |
添加、列出、移除、更新和索引chart仓库。可用的子命令:add、index、list、remove、update。 |
rollback |
从之前的版本回退。 |
search |
根据关键字搜索chart。可用的子命令:all、chart、readme、values。 |
show |
查看chart的详细信息。可用的子命令:all、chart、readme、values。 |
status |
显示已命名版本的状态。 |
template |
本地呈现模板。 |
uninstall |
卸载一个release。 |
upgrade |
更新一个release。 |
version |
查看Helm客户端版本。 |
3 Helm Chart
3.1 结构目录
examples/
Chart.yaml # Yaml文件,用于描述Chart的基本信息,包括名称版本等
LICENSE # [可选] 协议
README.md # [可选] 当前Chart的介绍
values.yaml # Chart的默认配置文件
requirements.yaml # [可选] 用于存放当前Chart依赖的其它Chart的说明文件
charts/ # [可选]: 该目录中放置当前Chart依赖的其它Chart
templates/ # [可选]: 部署文件模版目录,模版使用的值来自values.yaml和由Tiller提供的值
templates/NOTES.txt # [可选]: 放置Chart的使用指南
3.2 部署应用
以MySQL为部署例子,用helm部署MySQL-8.0.23
3.2.1 设置镜像仓库
清楚默认stable源,添加其他的源,并更新
helm repo remove stable
helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add stable https://charts.helm.sh/stable
helm repo update
helm repo list
3.2.2 下载镜像
查找相应的MySQL镜像版本
helm search repo -l mysql |grep 8.0.23
拉取指定版本chart文件到本地
helm pull bitnami/mysql --version 8.5.3
3.2.3 修改配置
解压并到本地,并修改配置
tar xf mysql-8.5.3.tgz && cd mysql/
vim values.yaml
values.yaml内容如下
###设置root密码为123
64 ## MySQL Authentication parameters
65 ##
66 auth:
67 ## MySQL root password
68 ## ref: https://github.com/bitnami/bitnami-docker-mysql#setting-the-root-password-on-first-run
69 ##
70 rootPassword: "123"
###size默认8Gi,根据自己实际情况调整MySQL储存空间大小
335 ## Persistent Volume size
336 ##
337 size: 10Gi
###默认是 ClusterIP模式,改成NodePort,并添加“targetPort: 3306”
366 #type: ClusterIP
367 type: NodePort
368 ## Service port
369 ##
370 port: 3306
371 ## Specify the nodePort value for the LoadBalancer and NodePort service types.
372 ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
373 ##
374 targetPort: 3306
375 nodePort: 30036
###false改成true,开启Prometheus监控
751 ## Mysqld Prometheus exporter parameters
752 ##
753 metrics:
754 enabled: true
3.2.4 部署安装
部署安装MySQL到dev命名空间下,应用名字为mysql8
helm install mysql8 ./mysql -n dev
NAME: mysql8
LAST DEPLOYED: Fri Sep 24 16:12:08 2021
NAMESPACE: dev
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
** Please be patient while the chart is being deployed **
Tip:
Watch the deployment status using the command: kubectl get pods -w --namespace dev
Services:
echo Primary: mysql8.dev.svc.cluster.local:3306
Administrator credentials:
echo Username: root
echo Password : $(kubectl get secret --namespace dev mysql8 -o jsonpath="{.data.mysql-root-password}" | base64 --decode)
To connect to your database:
1. Run a pod that you can use as a client:
kubectl run mysql8-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mysql:8.0.23-debian-10-r84 --namespace dev --command -- bash
2. To connect to primary service (read/write):
mysql -h mysql8.dev.svc.cluster.local -uroot -p my_database
To access the MySQL Prometheus metrics from outside the cluster execute the following commands:
kubectl port-forward --namespace dev svc/mysql8-metrics 9104:9104 &
curl http://127.0.0.1:9104/metrics
To upgrade this helm chart:
1. Obtain the password as described on the 'Administrator credentials' section and set the 'root.password' parameter as shown below:
ROOT_PASSWORD=$(kubectl get secret --namespace dev mysql8 -o jsonpath="{.data.mysql-root-password}" | base64 --decode)
helm upgrade mysql8 bitnami/mysql --set auth.rootPassword=$ROOT_PASSWORD
更多推荐
所有评论(0)