1.helm版本
- helm v2 版本
包含两个组件,分别是 helm client客户端 和 Tiller 服务器,
helm 是一个命令行工具,用于本地开发及管理chart,chart仓库管理等
Tiller 负责接收 Helm 的请求,与 k8s 的 apiserver 交互
helm v3 版本(安装简单,本文以helm3安装为例)
移除了Tiller helm直接和K8s交互
SA通过 kuberconfig 配置认证
- 设计原理
它是一个线程的方式运行
- Helm-cotroller 运行在master节点并list/walch HelmChart CRD对象
- CRD onChange时执行Job更新
- Job Container使用rancherklilpper-helm为entrypoint
- Killper-helm内 thelm cli,可以安装/升级/删除对应的chart
2.helm安装
- git下载 helm安装包 (Git地址)
下载不了的可以这个网盘提取 (helm-v3.2.0-rc.1-linux-amd64.tar.gz 提取码:ij5m )
登录k8s master节点后台,上传安装包并解压(tar -zxvf helm-v3.2.0-rc.1-linux-amd64.tar.gz)
复制 helm 二进制 到bin目录下(cp linux-amd64/helm /usr/local/bin/)
设置环境变量KUBECONFIG来指定存有ApiServre的地址与token的配置文件地址,默认为~/.kube/config(如k8s集群自定义安装修改了该路径请换成修改后)(export KUBECONFIG=/root/.kube/config)
验证安装结果:(如下安装正常)
[root@k8s-node1 CImges]# helm version
version.BuildInfo{Version:"v3.2.0-rc.1", GitCommit:"7bffac813db894e06d17bac91d14ea819b5c2310", GitTreeState:"clean", GoVersion:"go1.13.10"}
[root@k8s-node1 CImges]#
3.helm配置
- 配置helm3仓库
helm repo add repo_name1 https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/
- 配置helm3仓库(忽略:此处就想试试能否加多个仓库)
helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
- upadte更新,list查看仓库配置
helm repo update
helm repo list
[root@k8s-node1 CImges]# helm repo list
NAME URL
repo_name1 https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/
stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
4.helm使用
# 创建nginx chart
[root@k8s-node1 helm]# helm create nginx
Creating nginx
# 查看nginx chart目录树
[root@k8s-node1 helm]# tree nginx
nginx
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
3 directories, 10 files
# 修改 values.yaml文件service的type为NodePort
[root@k8s-node1 helm]# cd nginx
[root@k8s-node1 helm]# vi values.yaml
# helm安装nginx(注意最后的 . 表示当前目录)
[root@k8s-node1 nginx]# helm install -f values.yaml nginx .
NAME: nginx
LAST DEPLOYED: Wed May 12 15:02:58 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services nginx)
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
# 查看nginx release
[root@k8s-node1 nginx]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
nginx default 1 2021-05-12 15:02:58.737161199 +0800 CST deployed nginx-0.1.0 1.16.0
5.验证服务
# 查看服务是否正常启动Running
[root@k8s-node1 nginx]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-5c96c8f58b-2zfqz 1/1 Running 0 63s
# 查看服务暴露端口(该处为32619)
[root@k8s-node1 nginx]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.1.0.1 <none> 443/TCP 378d
nginx NodePort 10.1.92.227 <none> 80:32619/TCP 69s
helm3安装完成!!!