[Helm] helm workthrough

参考文档:

What is Helm?

Helm helps you manage Kubernetes applications — Helm Charts help you define, install, and upgrade even the most complex Kubernetes application.
Charts are easy to create, version, share, and publish — so start using Helm and stop the copy-and-paste.

Helm 可以帮助你管理k8s app, helm charts 可以帮助你定义,安装 和 升级 哪怕是最复杂的k8s app.
Charts 很容易创建,版本管理,分享和发布,所以开始使用Helm,停止复制粘贴吧。

Why Teams ❤️ Helm?

  • Manage Complexity
  • Easy Updates
  • Simple Sharing
  • Rollbacks

Get Helm

Helm 项目可以在Github 上找到:helm
Helm 文档:docs.helm.sh

Get Charts

Visit the Helm Hub to explore charts from numerous public Helm repositories.

Installing Helm

doc: quickstart-guide -> 搜索:Installing Helm

There are two parts to Helm: The Helm client (helm) and the Helm server (Tiller). This guide shows how to install the client, and then proceeds to show two ways to install the server.
IMPORTANT: If you are responsible for ensuring your cluster is a controlled environment, especially when resources are shared, it is strongly recommended installing Tiller using a secured configuration. For guidance, see Securing your Helm Installation.

Helm 有两个部分:

  • Helm client (helm)
  • Helm server (Tiller)

将展示如何安装Helm Client以及两种方式安装Helm Server.

IMPORTANT:如果你负责确保你的集群是可控环境,尤其是在共享资源时,强烈建议你使用安全配置安装Tiller。参考文档: Securing your Helm Installation.

由此可见,安装Helm需要根据自己的集群的实际情况,选择是简单的安装还是要使用安全配置进行安装.

Installing The Helm Client

Helm客户端既可以从源代码安装,也可以从预构建的二进制版本安装。

示例一:From the Binary Release

  1. 下载期望的helm 版本
  2. 解压 (tar -zxvf helm-v2.0.0-linux-amd64.tgz)
  3. 找到 helm 二进制文件,把它移到你本地期望的位置 (mv linux-amd64/helm /usr/local/bin/helm)

现在你可以使用helm client了: helm help.

示例二:从Snap获取(Linux)
sudo snap install helm --classic

示例三:从Homebrew获取(MacOS)
brew install kubernetes-helm

等等....,如:

  • windows安装helm client
  • 一个安装script安装helm client
  • 直接从源码安装

Installing Tiller

Tiller 是Helm server,运行在你的k8s 集群中。
但是对于开发,它也可以在本地运行,并配置与远程Kubernetes集群通信。

Check the Kubernetes Distribution Guide to see if there’s any further points of interest on using Helm with your cloud provider. Also check out the guide on Tiller and Role-Based Access Control for more information on how to run Tiller in an RBAC-enabled Kubernetes cluster.

现在很多云提供商提供了RBAC的权限控制,如果你的集群所在的云提供商提供了RBAC功能,你需要为Tiller
创建一个service account,并且设置正确的role 和 访问资源的权限。参考文档:special-note-for-rbac-users

安装Tiller简单方法
直接运行helm init,该命令会先验证是否正确设置了helm本地环境,如果需要,将会设置helm 本地环境。然后会链接cluster kubectl 链接的默认的集群上。如果一定helm链接到集群成功,那么它就是安装tiller到kube-system namespace。

使用helm init后,可以运行kubectl get pods --namespace kube-system 查看tiller的运行状态。

你可以 explicitly 告诉 helm init

  • Install the canary build with the --canary-image flag
  • Install a particular image (version) with --tiller-image
  • Install to a particular cluster with --kube-context
  • Install into a particular namespace with --tiller-namespace
  • Install Tiller with a Service Account with --service-account (for RBAC enabled clusters)
  • Install Tiller without mounting a service account with --automount-service-account false

安装完成后,可以运行helm version查看helm client 和 server的版本信息。

helm version.png

其他安装Tiller的方法:

running-tiller-locally 是为了开发使用的,你可以在本地安装tiller,然后配置它可以连接到远端的k8s cluster。

Upgrading Tiller

Helm 2.2.0 版本之后,可以使用 helm init --upgrade进行Tiller的升级。

Deleting Or Reinstalling Tiller

Tiller的数据是存储在k8s的configmap里,为了不删除数据,可以使用kubectl delete deployment tiller-deploy --namespace kube-system 或者 helm reset.
如果想重新安装Tiller,运行helm init命令。

Advanced Usage

  • --node-selectors 指定安装tiller pod 安装到带有指定标签的node上,如helm init --node-selectors "beta.kubernetes.io/os"="linux",然后在tiller的deployment文件里可以看到node selector的label.
    nodeSelector: object //节点选择,表示将该Pod调度到包含这些label的Node上,以key:value格式指定
...
spec:
  template:
    spec:
      nodeSelector:
        beta.kubernetes.io/os: linux
...
  • --override, 可以override annotation如:helm init --override metadata.annotations."deployment\.kubernetes\.io/revision"="1"可以修改deployment里面的信息。
#output
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
...

也可以override affinity,如:helm init --override "spec.template.spec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].weight"="1" --override "spec.template.spec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].preference.matchExpressions[0].key"="e2e-az-name"

#output
spec:
  strategy: {}
  template:
    ...
    spec:
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - preference:
              matchExpressions:
              - key: e2e-az-name
                operator: ""
            weight: 1
...

NodeAffinity意为Node亲和性调度策略,较NodeSelector更为精确匹配。NodeAffinity是条件范围匹配,通过In(属于)、NotIn(不属于)、Exists(存在一个条件)、DoesNotExist(不存在)、Gt(大于)、Lt(小于)等操作符来选择Node,使调度更加灵活。

NodeAffinity目前有两种节点亲和性表达式:
RequiredDuringSchedulingIgnoredDuringExecution:必须满足指定的规则才可以调度Pod到Node上,功能上与nodeSelector很像,相当于硬限制。
PreferredDuringSchedulingIgnoredDuringExecution:强调优先满足指定规则,调度器会尝试调度Pod到Node上,但并不强求,相当于软限制。多个优先级规则还可以设置权重(weight)值,以定义执行的先后顺序。

NodeAffinity规则设置注意事项:
如果同时设置了nodeSelectornodeAffinity,则系统将需要同时满足两者的设置才能进行调度。
如果nodeAffinity指定了多个nodeSelectorTerms,那么只需要其中一个能够匹配成功即可。
如果nodeSelectorTerms中有多个matchExpressions,则一个节点必须满足所有matchExpressions才能运行该Pod。

  • --output, 如:helm init --output json
    --output 参数允许我们跳过安装 Tiller 的 deployment manifest,并以 JSON 或 YAML 格式简单地将 deployment manifest 输出到标准输出 stdout。然后可以使用 jq 类似工具修改输出,并使用 kubectl 手动安装。

常见问题 - FAQ

已经使用过的解决方案:
如果不想将helm client install到默认的 ~/.helm文件夹,可以设置 $HELM_HOME 环境变量,然后运行helm init

export HELM_HOME=/some/path
helm init --client-only

注意,如果此时你有已经存在的repo,需要re-add这些repo,通过运行helm repo add命令。

Q: How do I configure Helm, but not install Tiller?
A: By default, helm init will ensure that the local $HELM_HOME is configured, and then install Tiller on your cluster. To locally configure, but not install Tiller, use helm init --client-only

Q: How do I manually install Tiller on the cluster?
A: Tiller is installed as a Kubernetes deployment. You can get the manifest by running helm init --dry-run --debug, and then manually install it with kubectl. It is suggested that you do not remove or change the labels on that deployment, as they are sometimes used by supporting scripts and tools.

Helm Xmind

Helm.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,670评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,928评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,926评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,238评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,112评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,138评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,545评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,232评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,496评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,596评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,369评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,226评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,600评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,906评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,185评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,516评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,721评论 2 335