helm部署和使用

时间:2022-09-16 21:39:28

Helm是Kubernetes的一个包管理工具,用来简化Kubernetes应用的部署和管理。可以把Helm比作CentOS的yum工具。 Helm有如下几个基本概念:
- Chart: 是Helm管理的安装包,里面包含需要部署的安装包资源。可以把Chart比作CentOS yum使用的rpm文件。每个Chart包含下面两部分:
- 包的基本描述文件Chart.yaml
放在templates目录中的一个或多个Kubernetes manifest文件模板
- Release:是chart的部署实例,一个chart在一个Kubernetes集群上可以有多个release,即这个chart可以被安装多次
- Repository:chart的仓库,用于发布和存储chart

helm的安装方式:
首先,运行命令

$ curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
$ chmod 755 get_helm.sh
$ ./get_helm.sh 
$ helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.8.2 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
$ #注意上面一条命令的版本号需要和“helm version”命令下看到的client版本号一致

执行后即可完成安装,若需要更换版本,可以从https://github.com/kubernetes/helm/releases中下载对应版本的二进制文件,替换到/usr/local/bin/helm文件,然后将 helm init后面的版本号更换,即可安装对应版本的server端

问题排查:

当运行 helm ls 产生报错

[root@zk1 ~]# helm ls
Error: Get http://localhost:8080/api/v1/namespaces/kube-system/configmaps?labelSelector=OWNER%!D(MISSING)TILLER: dial tcp [::1]:8080: connect: connection refused

该报错是由于helm未将KUBERNETES_MASTER环境变量从kubectl config中带入tiller的容器中,可以通过编辑deployment的环境变量强行写入

命令:

 kubectl edit deploy tiller-deploy -n kube-system

在container-env中加入master即可

      containers:
      - env:         - name: TILLER_NAMESPACE           value: kube-system
        - name: TILLER_HISTORY_MAX           value: "0"
        - name: KUBERNETES_MASTER           value: 172.16.7.45:8080

helm使用:
由于初步学习,涉及不深,介绍以下常用命令
- helm ls -a 查看全部的release
- helm status my-release 查看状态
- helm upgrade my-release -f mysql/values.yaml –set resources.requests.memory=1024Mi my-release 更行版本
- helm rollback mysql 1 //1为版本号,可以添加 –debug打印调试信息 回滚版本

部署有的其他方式:
- 指定chart: helm install stable/mariadb
- 指定打包的chart: helm install ./nginx-1.2.3.tgz
- 指定打包目录: helm install ./nginx
- 指定chart包URL: helm install https://example.com/charts/nginx-1.2.3.tgz

安装效果:

[root@zk1 mysql-operator]# helm install ./mysql-operator/
NAME:   stultified-olm
LAST DEPLOYED: Tue Apr 17 04:33:34 2018
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1beta1/Deployment
NAME            AGE
mysql-operator  0s

==> v1/ServiceAccount
mysql-operator  0s
mysql-agent     0s

==> v1beta1/CustomResourceDefinition
mysqlbackupschedules.mysql.oracle.com  0s
mysqlclusters.mysql.oracle.com         0s
mysqlbackups.mysql.oracle.com          0s
mysqlrestores.mysql.oracle.com         0s


NOTES:
Thanks for installing the MySQL Operator.

Check if the operator is running with

kubectl get po -n mysql-operator