Kubernetes Helm 是一个管理预先配置 Kubernetes 资源包的工具,这里的资源在 Helm 中也被称作 Kubernetes charts。
使用 Helm:
Helm 有两个部分:Helm 客户端(helm)和 Helm 服务端(Tiller)。
请到官方发布地址下载自己想要的版本,我用的是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.
安装 tiller 到群集中最简单的方法就是运行 helm init
,通过以下参数设定使用国内镜像和
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
不用多问,使用国内地址就对了,注意版本号
[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
参数说明:
一旦安装了 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
[root@master helm]# helm repo add gitlab https://charts.gitlab.io
"gitlab" has been added to your repositories
[root@master helm]# helm search runner
NAME CHART VERSION APP VERSION DESCRIPTION
gitlab/gitlab-runner 0.7.0 12.1.0 GitLab Runner
[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
[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
错误信息如下
[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