k8s helm

helm

  • CNCF: Cloud Native Computing Foundation (云原生计算基金会)
  • YAML: Yet Another Markup Language (仍是一种标记语言)
  • RPM: Red-Hat Package Manager (红帽软件包管理器)
  • DPKG: Debian Packager (Debian包管理器)
  • Yum: Yellow dog Updater, Modified (Shell前端软件包管理器)
  • DEB: Debian(Debian软件包格式的文件扩展名)
  • APT: Advanced Packaging Tool (Linux下的一款安装包管理工具)
  • VPC: Virtual Private Cloud (私有云)
  • VPN: Virtual Private Network (专有网络)

introduction

Helm 是Kubernetes的包管理器,Helm帮助您管理Kubernetes应用程序-Helm图表帮助您定义、安装和升级最复杂的Kubernetes应用程序。Chart 的创建、版本、共享和发布都很容易,所以请开始使用Helm并停止复制和粘贴。

特点:

  • 复杂性管理
  • 易于升级
  • 分发简单
  • 轻松回滚

对于Helm,有三个重要的概念:

  1. chart 创建Kubernetes应用程序所必需的一组信息。
  2. config 包含了可以合并到打包的chart中的配置信息,用于创建一个可发布的对象。
  3. release 是一个与特定配置相结合的chart的运行实例。

architecture

安装

  1. macos
brew install helm
  1. windows

使用

1. helm search

从 Artifact Hub 中搜索所有的mysql.

$ helm search hub mysql
URL                                               	CHART VERSION	APP VERSION 	DESCRIPTION                                       
https://artifacthub.io/packages/helm/bitnami-ak...	8.8.18       	8.0.27      	Chart to create a Highly available MySQL cluster  
https://artifacthub.io/packages/helm/bitnami/mysql	8.8.19       	8.0.27      	Chart to create a Highly available MySQL cluster  
https://artifacthub.io/packages/helm/cloudnativ...	5.0.1        	8.0.16      	Chart to create a Highly available MySQL cluster  
https://artifacthub.io/packages/helm/choerodon/...	8.5.1        	8.5.1       	Chart to create a Highly available MySQL cluster  
https://artifacthub.io/packages/helm/stakater/m...	1.0.6        	            	mysql chart that runs on kubernetes               
https://artifacthub.io/packages/helm/t3n/mysql    	1.0.0        	5.7.32      	Fast, reliable, scalable, and easy to use open-...
https://artifacthub.io/packages/helm/kubesphere...	1.6.8        	5.7.31      	Fast, reliable, scalable, and easy to use open-...
https://artifacthub.io/packages/helm/homeenterp...	0.1.0        	8.0.26      	MySQL Database Server                             
https://artifacthub.io/packages/helm/someblackm...	1.7.1        	5.7.33      	Fast, reliable, scalable, and easy to use open-...
https://artifacthub.io/packages/helm/wso2/mysql   	1.6.9        	5.7.30      	Fast, reliable, scalable, and easy to use open-...
https://artifacthub.io/packages/helm/devopspilo...	1.0.0        	1.0.0       	Helm chart for running mysql database             
https://artifacthub.io/packages/helm/anvibo/mysql 	0.1.0        	1.16.0      	A Helm chart for Kubernetes                       
https://artifacthub.io/packages/helm/mysql-oper...	8.0.26-2.0.2 	8.0.26      	MySQL InnoDB Cluster Helm Chart for deploying M...
https://artifacthub.io/packages/helm/mysql-oper...	8.0.26-2.0.2 	8.0.26-2.0.2	MySQL Operator Helm Chart for deploying MySQL I...
https://artifacthub.io/packages/helm/softonic/m...	2.2.0        	0.3.0       	Take mysql backups from any mysql instance to A...
https://artifacthub.io/packages/helm/kfirfer/my...	0.0.3        	8.0.20      	A Helm chart for MySQL Cluster                    
https://artifacthub.io/packages/helm/kanister/k...	0.32.0       	5.7.14      	MySQL w/ Kanister support based on stable/mysql   
https://artifacthub.io/packages/helm/bitpoke/my...	0.6.2        	v0.6.2      	A Helm chart for easy deployment of a MySQL clu...
https://artifacthub.io/packages/helm/presslabs/...	0.3.1        	1.0         	A Helm chart for easy deployment of a MySQL clu...
https://artifacthub.io/packages/helm/bitpoke/my...	0.6.2        	v0.6.2      	A helm chart for Bitpoke Operator for MySQL       
https://artifacthub.io/packages/helm/presslabs/...	0.5.0-rc.3   	v0.5.0-rc.3 	A Helm chart for mysql operator                   

可以从已添加的仓库中查找chart的名字。

$ helm search repo mysql
NAME                              	CHART VERSION	APP VERSION	DESCRIPTION                                       
aliyuncs/mysql                    	6.8.0        	8.0.19     	Chart to create a Highly available MySQL cluster  
aliyuncs/mysqldump                	2.6.0        	2.4.1      	A Helm chart to help backup MySQL databases usi...
aliyuncs/mysqlha                  	1.0.0        	5.7.13     	MySQL cluster with a single master and zero or ...
aliyuncs/prometheus-mysql-exporter	0.5.2        	v0.11.0    	A Helm chart for prometheus mysql exporter with...
bitnami/mysql                     	8.8.19       	8.0.27     	Chart to create a Highly available MySQL cluster  
aliyuncs/percona                  	1.2.0        	5.7.17     	free, fully compatible, enhanced, open source d...
aliyuncs/percona-xtradb-cluster   	1.0.3        	5.7.19     	free, fully compatible, enhanced, open source d...
aliyuncs/phpmyadmin               	4.2.12       	5.0.1      	phpMyAdmin is an mysql administration frontend    
bitnami/phpmyadmin                	8.3.2        	5.1.1      	phpMyAdmin is an mysql administration frontend    
aliyuncs/mariadb                  	7.3.9        	10.3.22    	Fast, reliable, scalable, and easy to use open-...
aliyuncs/mariadb-galera           	0.8.1        	10.4.12    	MariaDB Galera is a multi-master database clust...
bitnami/mariadb                   	10.2.0       	10.5.13    	Fast, reliable, scalable, and easy to use open-...
bitnami/mariadb-cluster           	1.0.2        	10.2.14    	DEPRECATED Chart to create a Highly available M...
bitnami/mariadb-galera            	6.1.1        	10.6.5     	MariaDB Galera is a multi-master database clust...
## 添加常用的chart源
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm repo add aliyuncs https://apphub.aliyuncs.com
## 查看chart列表
$ helm repo list
NAME    	URL                               
bitnami 	https://charts.bitnami.com/bitnami
aliyuncs	https://apphub.aliyuncs.com 

我们选择aliyuncs/mysql 的chart包 先下载看看包有什么内容

## 拉取包
$ helm pull aliyuncs/mysql  --untar 
## 查看包内容
$ tree mysql/

mysql
├── Chart.yaml
├── README.md
├── ci
│   └── values-production.yaml
├── files
│   └── docker-entrypoint-initdb.d
│       └── README.md
├── templates
│   ├── NOTES.txt
│   ├── _helpers.tpl
│   ├── initialization-configmap.yaml
│   ├── master-configmap.yaml
│   ├── master-statefulset.yaml
│   ├── master-svc.yaml
│   ├── secrets.yaml
│   ├── servicemonitor.yaml
│   ├── slave-configmap.yaml
│   ├── slave-statefulset.yaml
│   └── slave-svc.yaml
├── values-production.yaml
└── values.yaml

4 directories, 17 files 

2. helm install

Helm按照以下顺序安装资源:

  1. Namespace
  2. NetworkPolicy
  3. ResourceQuota
  4. LimitRange
  5. PodSecurityPolicy
  6. PodDisruptionBudget
  7. ServiceAccount
  8. Secret
  9. SecretList
  10. ConfigMap
  11. StorageClass
  12. PersistentVolume
  13. PersistentVolumeClaim
  14. CustomResourceDefinition
  15. ClusterRole
  16. ClusterRoleList
  17. ClusterRoleBinding
  18. ClusterRoleBindingList
  19. Role
  20. RoleList
  21. RoleBinding
  22. RoleBindingList
  23. Service
  24. DaemonSet
  25. Pod
  26. ReplicationController
  27. ReplicaSet
  28. Deployment
  29. HorizontalPodAutoscaler
  30. StatefulSet
  31. Job
  32. CronJob
  33. Ingress
  34. APIService
helm install my-nginx aliyuncs/nginx --set service.type=NodePort --set persistence.enabled=false
NAME: my-nginx
LAST DEPLOYED: Wed Jan  5 09:00:22 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Get the NGINX URL:

  export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services my-nginx)
  export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
  echo "NGINX URL: http://$NODE_IP:$NODE_PORT/"

查看是否安装成功

% kubectl get all
NAME                            READY   STATUS    RESTARTS   AGE
pod/my-nginx-5c4ccb468f-j5g77   1/1     Running   0          89s

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
service/kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP                      70d
service/my-nginx     NodePort    10.104.115.235   <none>        80:31631/TCP,443:32392/TCP   89s

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/my-nginx   1/1     1            1           89s

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/my-nginx-5c4ccb468f   1         1         1       89s

访问Nginx
http://localhost:31631/

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.

安装成功!

3. helm status

查看chart的状体啊

% helm status my-nginx
NAME: my-nginx
LAST DEPLOYED: Wed Jan  5 09:00:22 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Get the NGINX URL:

  export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services my-nginx)
  export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
  echo "NGINX URL: http://$NODE_IP:$NODE_PORT/"

4. 安装前自定义图表

使用helm show values 查看chart的配置选项

% helm show values aliyuncs/nginx 
## Global Docker image parameters
## Please, note that this will override the image parameters, including dependencies, configured to use the global value
## Current available global Docker image parameters: imageRegistry and imagePullSecrets
##
# global:
#   imageRegistry: myRegistryName
#   imagePullSecrets:
#     - myRegistryKeySecretName

## Bitnami NGINX image version
## ref: https://hub.docker.com/r/bitnami/nginx/tags/
##
image:
  registry: docker.io
  repository: bitnami/nginx
  tag: 1.16.1-debian-10-r0
  ## Specify a imagePullPolicy
  ## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
  ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
  ##
  pullPolicy: IfNotPresent
  ## Optionally specify an array of imagePullSecrets.
  ## Secrets must be manually created in the namespace.
  ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
  ##
  # pullSecrets:
  #   - myRegistryKeySecretName

## String to partially override nginx.fullname template (will maintain the release name)
##
# nameOverride:

您可以任何覆盖设置,用一个YAML格式文件,然后在安装过程中传递该文件。

$ echo '{metrics.enabled: false}' > values.yaml
$ helm install -f values.yaml aliyuncs/nginx --generate-name

安装过程中有两种方式传递配置数据:

  • –values (或 -f):使用 YAML 文件覆盖配置。可以指定多次,优先使用最右边的文件。
  • –set:通过命令行的方式对指定项进行覆盖。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

robin-cloud

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值