Kubernetes-Helm
2023-05-03 本文已影响0人
ssttIsme
Helm是一个Kubernets的包管理工具,就像Linunx下的包管理器,如yum/apt等,可以很方便的将之前打包好的yaml部署到kubernetes上。
https://helm.sh/
wget https://get.helm.sh/helm-v3.0.0-linux-amd64.tar.gz
tar -zxvf helm-v3.0.0-linux-amd64.tar.gz
mv linux-amd64/helm /usr/bin/
传统部署应用
- 编写yaml文件
-创建deployment - 暴露端口(编写serviceyaml文件)
- 使用Ingress做负载均衡
部署单一应用,少数服务的应用,比较合适
部署微服务项目可能有十几个服务,每个服务都有一套yaml文件,需要维护大量yaml文件,版本管理特别不方便
Helm优点
1使用helm可以把这些yaml作为一个整体管理
2实现yaml高效复用
3使用helm可以实现应用级别的版本管理
Helm的三个重要概念
Helm
命令行客户端工具,主要用于Kubernetes应用chart的创建、打包、发布和管理。
Chart
把yaml打包,是yaml的集合
Release
基于chart部署实体,应用级别的版本管理(基于Chart的部署实体,一个char被Helm运行后将会生成对应的一个release;将在k8s中创建出真实运行资源的对象)
Helm在2019年发布V3版本,和之前版本相比
1.V3版本删除Tiller,通过kube-config连接kube-apiserver
2.V3版本的release可以在不同命名空间重用
3.V3支持将chart推送到docker镜像仓库中
添加镜像仓库
[root@hadoop102 helm]# helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
"aliyun" has been added to your repositories
[root@hadoop102 helm]# helm repo list
NAME URL
aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
更新仓库地址
[root@hadoop102 helm]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "aliyun" chart repository
Update Complete. ⎈Happy Helming!⎈
快速部署应用
1.使用命令搜索应用
[root@hadoop102 helm]# helm search repo weave
NAME CHART VERSION APP VERSION DESCRIPTION
aliyun/weave-cloud 0.1.2 Weave Cloud is a add-on to Kubernetes which pro...
aliyun/weave-scope 0.9.2 1.6.5 A Helm chart for the Weave Scope cluster visual...
2.根据搜索到的内容进行选择安装
[root@hadoop102 helm]# helm fetch aliyun/weave-scope
[root@hadoop102 helm]# tar -zxvf weave-scope-0.9.2.tgz
修改配置

[root@hadoop102 helm]# cd weave-scope
[root@hadoop102 weave-scope]# cd charts
[root@hadoop102 charts]# cd weave-scope-agent/
[root@hadoop102 weave-scope-agent]# cd templates/
[root@hadoop102 templates]# vim daemonset.yaml
改apiVersion
apiVersion: apps/v1
[root@hadoop102 templates]# cd ../
[root@hadoop102 weave-scope-agent]# cd ..
[root@hadoop102 templates]# cd ../
[root@hadoop102 weave-scope-agent]# cd ..
[root@hadoop102 weave-scope-frontend]# cd templates/
[root@hadoop102 weave-scope-frontend]# cd templates/
[root@hadoop102 templates]# vim deployment.yaml
改apiVersion
apiVersion: apps/v1
[root@hadoop102 templates]# cd ..
[root@hadoop102 weave-scope-frontend]# cd ..
[root@hadoop102 charts]# cd ..
[root@hadoop102 weave-scope]# helm install ui ../weave-scope
NAME: ui
LAST DEPLOYED: Thu May 4 20:24:10 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
You should now be able to access the Scope frontend in your web browser, by
using kubectl port-forward:
kubectl -n default port-forward $(kubectl -n default get endpoints \
ui-weave-scope -o jsonpath='{.subsets[0].addresses[0].targetRef.name}') 8080:4040
then browsing to http://localhost:8080/.
For more details on using Weave Scope, see the Weave Scope documentation:
https://www.weave.works/docs/scope/latest/introducing/
3.查看安装后的状态
[root@hadoop102 helm]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
ui default 1 2023-05-04 20:24:10.140035835 +0800 CST deployed weave-scope-0.9.2 1.6.5
[root@hadoop102 helm]# helm status ui
NAME: ui
LAST DEPLOYED: Thu May 4 20:24:10 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
You should now be able to access the Scope frontend in your web browser, by
using kubectl port-forward:
kubectl -n default port-forward $(kubectl -n default get endpoints \
ui-weave-scope -o jsonpath='{.subsets[0].addresses[0].targetRef.name}') 8080:4040
then browsing to http://localhost:8080/.
For more details on using Weave Scope, see the Weave Scope documentation:
https://www.weave.works/docs/scope/latest/introducing
4.暴露端口访问
[root@hadoop102 weave-scope]# kubectl edit svc ui-weave-scope

type: NodePort
[root@hadoop102 weave-scope]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 52d
nginx NodePort 10.100.102.128 <none> 80:31917/TCP 52d
ui-weave-scope NodePort 10.107.89.44 <none> 80:31823/TCP 15m
5.访问
