k8s安装helm包管理器

文章目录

  • 一、helm简介
  • 二、安装helm
    • 1、下载安装helm
    • 2、初始化Helm 并安装tiller
      • 2.1、RBAC设置
      • 2.2、初始化并安装tiller
  • 三、helm常用命令的使用
    • 1、helm repo:添加、列出、删除、更新和索引chart仓库
    • 2、helm search:通过关键字搜索charts
    • 3、helm list:列出发布的服务
    • 4、helm history:
  • 四、遇到的小问题
    • 1、helm init没有指定创建的ServiceAccount

一、helm简介

Kubernetes Helm 是一个管理预先配置 Kubernetes 资源包的工具,这里的资源在 Helm 中也被称作 Kubernetes charts。

使用 Helm:

  • 查找并使用已经打包为 Kubernetes charts 的流行软件
  • 分享您自己的应用作为 Kubernetes charts
  • 为 Kubernetes 应用创建可重复执行的构建
  • 为您的 Kubernetes 清单文件提供更智能化的管理
  • 管理 Helm 软件包的发布

二、安装helm

Helm 有两个部分:Helm 客户端(helm)和 Helm 服务端(Tiller)。

1、下载安装helm

请到官方发布地址下载自己想要的版本,我用的是2.9.0,官方发布版本:https://github.com/helm/helm/releases

下载官方指定版本压缩包

[root@master helm]## wget https://get.helm.sh/helm-v2.9.0-linux-amd64.tar.gz

解压缩,并将可执行文件helm移动到/usr/local/bin/目录下

[root@master helm]# tar -zxvf helm-v2.9.0-linux-amd64.tar.gz
[root@master helm]# mv linux-amd64/helm /usr/local/bin/

使用helm

[root@master helm]# helm
The Kubernetes package manager

To begin working with Helm, run the 'helm init' command:

	$ helm init

This will install Tiller to your running Kubernetes cluster.
It will also set up any necessary local configuration.

Common actions from this point include:

- helm search:    search for charts
- helm fetch:     download a chart to your local directory to view
- helm install:   upload the chart to Kubernetes
- helm list:      list releases of charts

Environment:
  $HELM_HOME          set an alternative location for Helm files. By default, these are stored in ~/.helm
  $HELM_HOST          set an alternative Tiller host. The format is host:port
  $HELM_NO_PLUGINS    disable plugins. Set HELM_NO_PLUGINS=1 to disable plugins.
  $TILLER_NAMESPACE   set an alternative Tiller namespace (default "kube-system")
  $KUBECONFIG         set an alternative Kubernetes configuration file (default "~/.kube/config")

Usage:
  helm [command]

Available Commands:
  completion  Generate autocompletions script for the specified shell (bash or zsh)
  create      create a new chart with the given name
  delete      given a release name, delete the release from Kubernetes
  dependency  manage a chart's dependencies
  fetch       download a chart from a repository and (optionally) unpack it in local directory
  get         download a named release
  history     fetch release history
  home        displays the location of HELM_HOME
  init        initialize Helm on both client and server
  inspect     inspect a chart
  install     install a chart archive
  lint        examines a chart for possible issues
  list        list releases
  package     package a chart directory into a chart archive
  plugin      add, list, or remove Helm plugins
  repo        add, list, remove, update, and index chart repositories
  reset       uninstalls Tiller from a cluster
  rollback    roll back a release to a previous revision
  search      search for a keyword in charts
  serve       start a local http web server
  status      displays the status of the named release
  template    locally render templates
  test        test a release
  upgrade     upgrade a release
  verify      verify that a chart at the given path has been signed and is valid
  version     print the client/server version information

Flags:
      --debug                           enable verbose output
  -h, --help                            help for helm
      --home string                     location of your Helm config. Overrides $HELM_HOME (default "/root/.helm")
      --host string                     address of Tiller. Overrides $HELM_HOST
      --kube-context string             name of the kubeconfig context to use
      --tiller-connection-timeout int   the duration (in seconds) Helm will wait to establish a connection to tiller (default 300)
      --tiller-namespace string         namespace of Tiller (default "kube-system")

Use "helm [command] --help" for more information about a command.

2、初始化Helm 并安装tiller

安装 tiller 到群集中最简单的方法就是运行 helm init,通过以下参数设定使用国内镜像和

2.1、RBAC设置

Tiller是helm的服务器端,一般运行于kubernetes集群之上,定义tiller的ServiceAccount,并通过ClusterRoleBinding将其绑定至集群管理员角色cluster-admin,从而使得它拥有集群级别所有的最高权限。详情见:基于角色的访问控制

apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system

部署到k8s集群

[root@k8s-master ~]# kubectl apply -f tiller-rbac.yaml 
serviceaccount/tiller created
clusterrolebinding.rbac.authorization.k8s.io/tiller created

2.2、初始化并安装tiller

不用多问,使用国内地址就对了,注意版本号

[root@master helm]# helm init --upgrade --service-account tiller  --tiller-image registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.9.0 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

参数说明:

  • –upgrade:如果已安装Tiller,则升级
  • –service-account:使用 Service Account 安装 RBAC enabled clusters)
  • –tiller-image:安装特定的镜像(版本)
  • –tiller-namespace:用一个特定的命名空间 (namespace) 安装
  • –stable-repo-url:指定仓库地址,默认是https://kubernetes-charts.storage.googleapis.com

一旦安装了 Tiller,运行 helm version 会显示客户端和服务器版本

[root@master helm]# helm version
Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}

可以在kube-system命名空间看到tiller已经部署

[root@master helm]# kubectl get pods -n kube-system | grep tiller
tiller-deploy-fb87c8876-nl5n2           1/1     Running   0          15h

三、helm常用命令的使用

1、helm repo:添加、列出、删除、更新和索引chart仓库

[root@master helm]# helm repo add gitlab https://charts.gitlab.io
"gitlab" has been added to your repositories

2、helm search:通过关键字搜索charts

[root@master helm]# helm search runner
NAME                	CHART VERSION	APP VERSION	DESCRIPTION  
gitlab/gitlab-runner	0.7.0        	12.1.0     	GitLab Runner

3、helm list:列出发布的服务

[root@master helm]# helm list
NAME         	REVISION	UPDATED                 	STATUS  	CHART              	NAMESPACE
gitlab-runner	1       	Thu Aug 15 09:27:51 2019	DEPLOYED	gitlab-runner-0.7.0	gitlab  

4、helm history:

[root@master helm]# helm history gitlab-runner
REVISION	UPDATED                 	STATUS  	CHART              	DESCRIPTION     
1       	Thu Aug 15 09:27:51 2019	DEPLOYED	gitlab-runner-0.7.0	Install complete

四、遇到的小问题

1、helm init没有指定创建的ServiceAccount

错误信息如下

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

删除tiller,重新helm init --service-account tiller ...

kubectl -n kube-system delete deploy tiller-deploy

你可能感兴趣的:(Kubernetes)