kubernetes helm

在这里插入图片描述

术语

  • Chart:一个helm程序包
  • Repository:Charts仓库,https/http服务器
  • Release:特定的Chart部署于目标集群上的一个实例
  • Config: values.yaml

Chart -> Config -> Release

程序架构

helm:客户端,管理本地的Chart仓库,管理Chart, 与Tiller服务器交互,发送Chart,实例安装、查询、卸载等操作

Tiller:服务端,接收helm发来的Charts与Config,合并生成relase;

RBAC配置文件示例:
https://github.com/helm/helm/blob/master/docs/rbac.md

官方可用的Chart列表:
https://hub.kubeapps.com/

helm

https://helm.sh/

https://github.com/helm/helm

https://github.com/helm/helm/releases

wget https://storage.googleapis.com/kubernetes-helm/helm-v2.12.3-linux-amd64.tar.gz

tar xf helm-v2.12.3-linux-amd64.tar.gz
cd linux-amd64/
mv helm tiller /usr/bin/

vim /etc/profile
source <(helm completion bash)

安装tiller

yum install socat

创建rbac角色

helm-rbac.yaml

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

添加国内源(备用)

helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

下载镜像

docker pull registry.cn-beijing.aliyuncs.com/minminmsn/tiller:v2.12.3
docker tag registry.cn-beijing.aliyuncs.com/minminmsn/tiller:v2.12.3 gcr.io/kubernetes-helm/tiller:v2.12.3
helm init
helm version
helm list

报错:

[root@k8s-master1 helm]# helm list
Error: configmaps is forbidden: User "system:serviceaccount:kube-system:default" cannot list resource "configmaps" in API group "" in the namespace "kube-system"

重启tiller即可

helm init --upgrade --service-account tiller

仓库操作

更新仓库

helm repo update

查看仓库

helm repo list

添加仓库

helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator

删除仓库

helm repo remove incubator

helm常用命令

release管理

install
delete
upgrade/rollback
list
history:release的历史信息;
status:获取release状态信息;
helm install \
  --set image=redis \
  --set tag=5.0.5-alpine \
    stable/redis-ha


helm install --name redis1 stable/redis

helm install --name redis1 -f values.yaml stable/redis

helm install --values=myvals.yaml wordpress
helm search redis

helm inspect stable/redis

查看release状态

helm status redis1

chart管理

https://v2.helm.sh/docs/developing_charts/

create
fetch    download a chart from a repository and (optionally) unpack it in local directory
get
inspect
package
verify
helm fetch stable/redis
/root/.helm/cache/archive
tree redis
redis
├── Chart.yaml
├── ci
│   ├── default-values.yaml
│   ├── dev-values.yaml
│   ├── extra-flags-values.yaml
│   ├── insecure-sentinel-values.yaml
│   ├── production-sentinel-values.yaml
│   ├── production-values.yaml
│   ├── redisgraph-module-values.yaml
│   └── redis-lib-values.yaml
├── README.md
├── templates
│   ├── configmap.yaml
│   ├── headless-svc.yaml
│   ├── health-configmap.yaml
│   ├── _helpers.tpl
│   ├── metrics-prometheus.yaml
│   ├── metrics-svc.yaml
│   ├── networkpolicy.yaml
│   ├── NOTES.txt
│   ├── psp.yaml
│   ├── redis-master-statefulset.yaml
│   ├── redis-master-svc.yaml
│   ├── redis-rolebinding.yaml
│   ├── redis-role.yaml
│   ├── redis-serviceaccount.yaml
│   ├── redis-slave-statefulset.yaml
│   ├── redis-slave-svc.yaml
│   ├── redis-with-sentinel-svc.yaml
│   └── secret.yaml
├── values-production.yaml
├── values.schema.json
└── values.yaml

chart结构

wordpress/
  Chart.yaml          # A YAML file containing information about the chart
  LICENSE             # OPTIONAL: A plain text file containing the license for the chart
  README.md           # OPTIONAL: A human-readable README file
  requirements.yaml   # OPTIONAL: A YAML file listing dependencies for the chart
  values.yaml         # The default configuration values for this chart
  charts/             # A directory containing any charts upon which this chart depends.
  templates/          # A directory of templates that, when combined with values,
                      # will generate valid Kubernetes manifest files.
  templates/NOTES.txt # OPTIONAL: A plain text file containing short usage notes

Chart.yaml

apiVersion: The chart API version, always "v1" (required)
name: The name of the chart (required)
version: A SemVer 2 version (required)
kubeVersion: A SemVer range of compatible Kubernetes versions (optional)
description: A single-sentence description of this project (optional)
keywords:
  - A list of keywords about this project (optional)
home: The URL of this project's home page (optional)
sources:
  - A list of URLs to source code for this project (optional)
maintainers: # (optional)
  - name: The maintainer's name (required for each maintainer)
    email: The maintainer's email (optional for each maintainer)
    url: A URL for the maintainer (optional for each maintainer)
engine: gotpl # The name of the template engine (optional, defaults to gotpl)
icon: A URL to an SVG or PNG image to be used as an icon (optional).
appVersion: The version of the app that this contains (optional). This needn't be SemVer.
deprecated: Whether this chart is deprecated (optional, boolean)
tillerVersion: The version of Tiller that this chart requires. This should be expressed as a SemVer range: ">2.0.0" (optional)

Dependencies with requirements.yaml

dependencies:
  - name: apache
    version: 1.2.3
    repository: http://example.com/charts
  - name: mysql
    version: 3.2.1
    repository: http://another.example.com/charts
helm dep up foochart
charts/
  apache-1.2.3.tgz
  mysql-3.2.1.tgz

templates/

https://golang.org/pkg/text/template/

apiVersion: v1
kind: ReplicationController
metadata:
  name: deis-database
  namespace: deis
  labels:
    app.kubernetes.io/managed-by: deis
spec:
  replicas: 1
  selector:
    app.kubernetes.io/name: deis-database
  template:
    metadata:
      labels:
        app.kubernetes.io/name: deis-database
    spec:
      serviceAccount: deis-database
      containers:
        - name: deis-database
          image: {{.Values.imageRegistry}}/postgres:{{.Values.dockerTag}}
          imagePullPolicy: {{.Values.pullPolicy}}
          ports:
            - containerPort: 5432
          env:
            - name: DATABASE_STORAGE
              value: {{default "minio" .Values.storage}}

通常在 values.yaml 文件中定义

values.yaml

imageRegistry: "quay.io/deis"
dockerTag: "latest"
pullPolicy: "Always"
storage: "s3"
helm install --values=myvals.yaml wordpress

自定义chart

创建chart

helm create myapp
tree myapp/
myapp/
├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

myapp/Chart.yaml

apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes myapp chart
name: myapp
version: 0.0.1
maintainer:
- name: wuxingge
  email: wuxingge@wuxingge.com
  url: http://www.wuxingge.com/

语法检查

helm lint myapp

打包chart

helm package myapp/

helm仓库服务器

[root@k8s-master1 ~]# helm serve
Regenerating index. This may take a moment.
Now serving you on 127.0.0.1:8879

搜索chart

helm search myapp

部署本地chart

helm install --name myapp3 local/myapp

删除

helm delete --purge myapp3
#查看chart
root@localhost:/path/to/dev-kibana# ls
Chart.yaml  Makefile  README.md  examples  templates  values.yaml

#helm部署
root@localhost:/path/to/dev-kibana# helm --kubeconfig /path/to/kubeconfig.yaml install  dev-kibana -n kibana -f values.yaml .

ELFK

E: elasticsearch
L: logstash
F: Filebeat, Fluentd
K: Kibana

helm fetch incubator/elasticsearch
docker pull registry.cn-hangzhou.aliyuncs.com/wuxingge/elasticsearch-oss:6.4.2
docker tag registry.cn-hangzhou.aliyuncs.com/wuxingge/elasticsearch-oss:6.4.2 docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.2

helm install --name els1 --namespace=efk -f values.yaml incubator/elasticsearch
helm fetch stable/fluentd-elasticsearch
helm fetch stable/kibana
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Kubernetes HelmKubernetes 中最流行的包管理工具,它能够帮助开发者在 Kubernetes 集群中部署、升级和管理应用程序。使用 Helm 可以方便地管理 Kubernetes 资源的模板文件,并且可以将这些模板与配置值结合起来,生成可复用的软件包。本文将提供 Helm 的一些基本命令和示例操作。 一、安装 Helm 要安装 Helm,需要下面的几项: 1. 安装 Helm 客户端 ``` brew install helm # Mac choco install kubernetes-helm # Windows apt-get update && apt-get install -y helm # Ubuntu/Debian yum update && yum install -y helm # Centos/RedHat ``` 2. 创建并加入 Helm 仓库 Helm 软件仓库中存储了 Helm Charts,用户从仓库中获取 Charts 以及创建 Charts 进行分发。使用以下命令将官方仓库添加到 Helm。 ``` helm repo add stable https://kubernetes-charts.storage.googleapis.com/ ``` 二、Helm 常用命令 以下是 Helm 中的一些常用命令: 1. helm install 使用 helm install 安装一个 Chart。 ``` helm install [RELEASE NAME] [CHART] [FLAGS] ``` RELEASE NAME:定义一个 Chart 使用的名称。 CHART:定义要使用的 Chart 名称。 FLAGS:一些额外的自定义参数。 例如,安装 Redis 的 Chart。 ``` helm install redis stable/redis ``` 2. helm upgrade 使用 helm upgrade 命令来更新已部署的 Charts。 ``` helm upgrade [RELEASE NAME] [CHART] [FLAGS] ``` RELEASE NAME:定义一个 Chart 使用的名称。 CHART:定义要使用的 Chart 名称。 FLAGS:一些额外的自定义参数。 例如,更新已经安装的 Redis Chart。 ``` helm upgrade redis stable/redis ``` 3. helm list 使用 helm list 命令列出运行在 Kubernetes 集群中的 Charts。 ``` helm list ``` 4. helm delete 删除指定的 Chart。 ``` helm delete [RELEASE NAME] ``` RELEASE NAME:定义一个 Chart 使用的名称。 例如,删除 Redis Chart。 ``` helm delete redis ``` 三、Helm 示例 假设我们要使用 HelmKubernetes 集群中部署 WordPress 应用程序。 1. 安装 MySQL 首先需要安装 MySQL。使用 helm install 命令安装 MySQL。 ``` helm install my-mysql stable/mysql ``` 可以使用以下命令检查 my-mysql 是否安装成功。 ``` helm list ``` 2. 应用程序的 Chart 编写 WordPress 应用程序的 Chart,名称为 wordpress。 ``` apiVersion: v1 kind: Service metadata: name: wordpress spec: type: LoadBalancer ports: - name: http port: 80 targetPort: 80 selector: app: wordpress --- apiVersion: apps/v1 kind: Deployment metadata: name: wordpress spec: selector: matchLabels: app: wordpress replicas: 1 template: metadata: labels: app: wordpress spec: containers: - name: wordpress image: wordpress:4.9.4-php7.0-apache ports: - containerPort: 80 env: - name: WORDPRESS_DB_HOST value: my-mysql - name: WORDPRESS_DB_PASSWORD value: my-mysql-password - name: WORDPRESS_DB_USER value: root --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: wp-pv-claim spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi ``` 3. 安装 WordPress 使用以下命令安装 WordPress。 ``` helm install my-wordpress ./wordpress \ --set service.type=LoadBalancer \ --set ingress.enabled=true \ --set ingress.hosts[0].name=my-wordpress.local \ --set ingress.hosts[0].path=/ \ --set persistence.enabled=true \ --set persistence.existingClaim=wp-pv-claim \ --set db.host=my-mysql \ --set db.user=root \ --set db.password=my-mysql-password \ --set db.name=wordpress ``` 这个命令在指定了一些参数之后使用 helm install 安装 WordPress。 4. 连接 连接到 my-wordpress.local 并访问 WordPress。 ``` kubectl get ingress ``` 可以使用以下命令查看 Ingress 的 IP 地址。 ``` kubectl get services -o wide -n ingress-nginx ``` 打开浏览器并输入 my-wordpress.local 的 IP 地址,可以查看 WordPress 页面。 以上就是 Helm 的一些基本操作和示例。虽然 Helm 看起来比较复杂,但是一旦熟悉了基本命令,其实用起来非常方便。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

wuxingge

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

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

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

打赏作者

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

抵扣说明:

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

余额充值