k8s学习笔记--helm安装
初识helm helm本质就是让k8s的应用管理(Deployment,Service等)可配置,能动态生成。通过动态生成k8s资源清单文件(deployment.yaml, service.yaml)。然后调用kubectl自动执行k8s资源部署。是由官方提供的类似于yum的包管理器,是部署环境的流程封装。Helm有两个重要概念:chart和release:chart是创建一个应用的信息集合,
初识helm
helm本质就是让k8s的应用管理(Deployment,Service等)可配置,能动态生成。通过动态生成k8s资源清单文件(deployment.yaml, service.yaml)。然后调用kubectl自动执行k8s资源部署。是由官方提供的类似于yum的包管理器,是部署环境的流程封装。Helm有两个重要概念:chart和release:
- chart是创建一个应用的信息集合,包括各种kubernetes对象的配置模板,参数定义,依赖关系,文档说明等,chart是应用部署的自包含逻辑单元。可以将chart想象成apt、yum中的软件安装包;
- release是chart的运行实例,代表一个正在运行的应用,当chart被安装到kubernetes集群,就生成一个release,chart能够多次安装到同一个集群,每次安装都是一个release。
Helm包含两个组件:Helm客户端和Tiller服务器,如下如所示:
Helm 客户端负责 chart 和 release 的创建和管理以及和 Tiller 的交互。Tiller 服务器运行在 Kubernetes 集群中,它会处理 Helm 客户端的请求,与 Kubernetes API Server 交互。
Helm部署
安装客户端helm
首先下载helm包
wget https://storage.googleapis.com/kubernetes-helm/helm-v2.13.1-linux-amd64.tar.gz
并解压缩到helm文件夹下,把其中helm可执行文件拷贝到/usr/local/bin目录下,并赋予执行权限:
tar -zxvf helm-v2.13.1-linux-amd64.tar.gz
cp helm /usr/lcoal/bin
安装服务端tiller
安装服务端tiller时,由于kubernetes APIserver开启了RBAC访问控制,所以需要创建tiller使用的service account:tiller并分配合适的角色给他。可参考helm文档中helm-doc,这里直接分配cluster-admin这个集群内置的ClusterRole给他,创建rbac-config.yaml文件:
apiVersion: v1
kind: ServiceAccount
metadata:
name: tiller
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: tiller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: tiller
namespace: kube-system
执行kubectl create -f rbac.yaml创建sac;
在集群中部署tiller:
helm init --service-account tiller --skip-refresh
但在执行过程中报如下错误:
Creating /root/.helm
Creating /root/.helm/repository
Creating /root/.helm/repository/cache
Creating /root/.helm/repository/local
Creating /root/.helm/plugins
Creating /root/.helm/starters
Creating /root/.helm/cache/archive
Creating /root/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /root/.helm.
Error: error installing: the server could not find the requested resource
应该是版本匹配问题,在kubernetes1.16版本之后的deployment的apiversion的endpoint发生了变化需要做如下处理:
输出tiller的定义文件
> helm init --output yaml > tiller.yaml
#修改定义文件 apiVersion改为apps/v1,并新增selector信息 如下:
> vim tiller.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: helm
name: tiller
name: tiller-deploy
namespace: kube-system
spec:
replicas: 1
strategy: {}
selector:
matchLabels:
app: helm
name: tiller
...
#修改后执行定义文件
> kubectl apply -f tiller.yaml
注意:由于镜像为谷歌镜像,所以需要科学上网,笔者实验用的下载好的镜像helm-2.13.1,提取码:vrwc ,所以导入的时候最好在每个节点都导入,否则可能提示pull镜像失败,因为我们也无法确定tiller的pod会部署在哪个节点。
执行helm version,显示helm客户端和服务器的版本,表明部署成功!
参考:
https://blog.csdn.net/weixin_44723434/article/details/103260500
更多推荐
所有评论(0)