经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » Kubernetes » 查看文章
KubeSphere Helm 应用仓库源码分析
来源:cnblogs  作者:kubesphere  时间:2021/6/28 9:19:45  对本文有异议

作者:蔡锡生,LStack 平台研发工程师,近期专注于基于 OAM 的应用托管平台落地。

背景介绍

KubeSphere 应用商店简介

作为一个开源的、以应用为中心的容器平台,KubeSphere 在 OpenPitrix 的基础上,为用户提供了一个基于 Helm 的应用商店,用于应用生命周期管理。OpenPitrix 是一个开源的 Web 平台,用于打包、部署和管理不同类型的应用。KubeSphere 应用商店让 ISV、开发者和用户能够在一站式服务中只需点击几下就可以上传、测试、部署和发布应用。

KubeSphere 中的 Helm 仓库功能

默认情况下,应用商店中内置了 16 个应用,但您可以通过应用模板添加更多应用。

  • KubeSphere Helm 仓库添加

  • Helm repo list

  • KubeSphere Helm 仓库中的应用模版查询

Helm 仓库简介

Helm charts 是存放 K8s 应用模版的仓库,该仓库由 index.yaml 文件和 .tgz 模版包组成。

  1. [root@ningbo stable]# ls -al
  2. 总用量 400
  3. drwxr-xr-x. 26 root root 4096 6 22 17:01 .
  4. drwxr-xr-x. 4 root root 86 6 22 16:37 ..
  5. -rw-r--r--. 1 root root 10114 6 22 17:12 index.yaml
  6. -rw-r--r--. 1 root root 3803 6 8 2020 lsh-cluster-csm-om-agent-0.1.0.tgz
  7. -rw-r--r--. 1 root root 4022 6 8 2020 lsh-mcp-cc-alert-service-0.1.0.tgz
  8. -rw-r--r--. 1 root root 4340 6 8 2020 lsh-mcp-cc-sms-service-0.1.0.tgz
  9. -rw-r--r--. 1 root root 4103 6 8 2020 lsh-mcp-cpm-metrics-exchange-0.1.0.tgz
  10. -rw-r--r--. 1 root root 4263 6 8 2020 lsh-mcp-cpm-om-service-0.1.0.tgz
  11. -rw-r--r--. 1 root root 4155 6 8 2020 lsh-mcp-csm-om-service-0.1.0.tgz
  12. -rw-r--r--. 1 root root 3541 6 8 2020 lsh-mcp-deploy-service-0.1.0.tgz
  13. -rw-r--r--. 1 root root 5549 6 8 2020 lsh-mcp-iam-apigateway-service-0.1.0.tgz
  • index.yaml 文件
  1. apiVersion: v1
  2. entries:
  3. aliyun-ccm:
  4. - apiVersion: v2
  5. appVersion: addon
  6. created: "2021-06-21T08:59:58Z"
  7. description: A Helm chart for Kubernetes
  8. digest: 6bda563c86333475255e5edfedc200ae282544e2c6e22b519a59b3c7bdef9a32
  9. name: aliyun-ccm
  10. type: application
  11. urls:
  12. - charts/aliyun-ccm-0.1.0.tgz
  13. version: 0.1.0
  14. aliyun-csi-driver:
  15. - apiVersion: v2
  16. appVersion: addon
  17. created: "2021-06-21T08:59:58Z"
  18. description: A Helm chart for Kubernetes
  19. digest: b49f128d7a49401d52173e6f58caedd3fabbe8e2827dc00e6a824ee38860fa51
  20. name: aliyun-csi-driver
  21. type: application
  22. urls:
  23. - charts/aliyun-csi-driver-0.1.0.tgz
  24. version: 0.1.0
  25. application-controller:
  26. - apiVersion: v1
  27. appVersion: addon
  28. created: "2021-06-21T08:59:58Z"
  29. description: A Helm chart for application Controller
  30. digest: 546e72ce77f865683ce0ea75f6e0203537a40744f2eb34e36a5bd378f9452bc5
  31. name: application-controller
  32. urls:
  33. - charts/application-controller-0.1.0.tgz
  34. version: 0.1.0
  • .tgz 解压缩后的文件目录
  1. [root@ningbo stable]# cd mysql/
  2. [root@ningbo mysql]# ls -al
  3. 总用量 20
  4. drwxr-xr-x. 3 root root 97 5 25 2020 .
  5. drwxr-xr-x. 26 root root 4096 6 22 17:01 ..
  6. -rwxr-xr-x. 1 root root 106 5 25 2020 Chart.yaml
  7. -rwxr-xr-x. 1 root root 364 5 25 2020 .Helmignore
  8. -rwxr-xr-x. 1 root root 76 5 25 2020 index.yaml
  9. drwxr-xr-x. 3 root root 146 5 25 2020 templates
  10. -rwxr-xr-x. 1 root root 1735 5 25 2020 values.yaml
  • Chart.yaml
  1. [root@ningbo mysql]# cat Chart.yaml
  2. apiVersion: v1
  3. appVersion: "1.0"
  4. description: A Helm chart for Kubernetes
  5. name: mysql
  6. version: 0.1.0

添加 Helm 仓库代码介绍

接口实现分析

  1. 路由注册
  2. handler,参数解析,调用 models 方面
  3. models ,调用 models 方法
  4. crd client,调用 K8s api 存储
  1. webservice.Route(webservice.POST("/repos").
  2. To(handler.CreateRepo). // 跟进
  3. Doc("Create a global repository, which is used to store package of app").
  4. Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
  5. Param(webservice.QueryParameter("validate", "Validate repository")).
  6. Returns(http.StatusOK, api.StatusOK, openpitrix.CreateRepoResponse{}).
  7. Reads(openpitrix.CreateRepoRequest{}))
  1. func (h *openpitrixHandler) CreateRepo(req *restful.Request, resp *restful.Response) {
  2. createRepoRequest := &openpitrix.CreateRepoRequest{}
  3. err := req.ReadEntity(createRepoRequest)
  4. if err != nil {
  5. klog.V(4).Infoln(err)
  6. api.HandleBadRequest(resp, nil, err)
  7. return
  8. }
  9. createRepoRequest.Workspace = new(string)
  10. *createRepoRequest.Workspace = req.PathParameter("workspace")
  11. user, _ := request.UserFrom(req.Request.Context())
  12. creator := ""
  13. if user != nil {
  14. creator = user.GetName()
  15. }
  16. parsedUrl, err := url.Parse(createRepoRequest.URL)
  17. if err != nil {
  18. api.HandleBadRequest(resp, nil, err)
  19. return
  20. }
  21. userInfo := parsedUrl.User
  22. // trim credential from url
  23. parsedUrl.User = nil
  24. repo := v1alpha1.HelmRepo{
  25. ObjectMeta: metav1.ObjectMeta{
  26. Name: idutils.GetUuid36(v1alpha1.HelmRepoIdPrefix),
  27. Annotations: map[string]string{
  28. constants.CreatorAnnotationKey: creator,
  29. },
  30. Labels: map[string]string{
  31. constants.WorkspaceLabelKey: *createRepoRequest.Workspace,
  32. },
  33. },
  34. Spec: v1alpha1.HelmRepoSpec{
  35. Name: createRepoRequest.Name,
  36. Url: parsedUrl.String(),
  37. SyncPeriod: 0,
  38. Description: stringutils.ShortenString(createRepoRequest.Description, 512),
  39. },
  40. }
  41. if strings.HasPrefix(createRepoRequest.URL, "https://") || strings.HasPrefix(createRepoRequest.URL, "http://") {
  42. if userInfo != nil {
  43. repo.Spec.Credential.Username = userInfo.Username()
  44. repo.Spec.Credential.Password, _ = userInfo.Password()
  45. }
  46. } else if strings.HasPrefix(createRepoRequest.URL, "s3://") {
  47. cfg := v1alpha1.S3Config{}
  48. err := json.Unmarshal([]byte(createRepoRequest.Credential), &cfg)
  49. if err != nil {
  50. api.HandleBadRequest(resp, nil, err)
  51. return
  52. }
  53. repo.Spec.Credential.S3Config = cfg
  54. }
  55. var result interface{}
  56. // 1. validate repo
  57. result, err = h.openpitrix.ValidateRepo(createRepoRequest.URL, &repo.Spec.Credential)
  58. if err != nil {
  59. klog.Errorf("validate repo failed, err: %s", err)
  60. api.HandleBadRequest(resp, nil, err)
  61. return
  62. }
  63. // 2. create repo
  64. validate, _ := strconv.ParseBool(req.QueryParameter("validate"))
  65. if !validate {
  66. if repo.GetTrueName() == "" {
  67. api.HandleBadRequest(resp, nil, fmt.Errorf("repo name is empty"))
  68. return
  69. }
  70. result, err = h.openpitrix.CreateRepo(&repo) //跟进
  71. }
  72. if err != nil {
  73. klog.Errorln(err)
  74. handleOpenpitrixError(resp, err)
  75. return
  76. }
  77. resp.WriteEntity(result)
  78. }
  1. func (c *repoOperator) CreateRepo(repo *v1alpha1.HelmRepo) (*CreateRepoResponse, error) {
  2. name := repo.GetTrueName()
  3. items, err := c.repoLister.List(labels.SelectorFromSet(map[string]string{constants.WorkspaceLabelKey: repo.GetWorkspace()}))
  4. if err != nil && !apierrors.IsNotFound(err) {
  5. klog.Errorf("list Helm repo failed: %s", err)
  6. return nil, err
  7. }
  8. for _, exists := range items {
  9. if exists.GetTrueName() == name {
  10. klog.Error(repoItemExists, "name: ", name)
  11. return nil, repoItemExists
  12. }
  13. }
  14. repo.Spec.Description = stringutils.ShortenString(repo.Spec.Description, DescriptionLen)
  15. _, err = c.repoClient.HelmRepos().Create(context.TODO(), repo, metav1.CreateOptions{}) // 跟进
  16. if err != nil {
  17. klog.Errorf("create Helm repo failed, repo_id: %s, error: %s", repo.GetHelmRepoId(), err)
  18. return nil, err
  19. } else {
  20. klog.V(4).Infof("create Helm repo success, repo_id: %s", repo.GetHelmRepoId())
  21. }
  22. return &CreateRepoResponse{repo.GetHelmRepoId()}, nil
  23. }
  1. // Create takes the representation of a HelmRepo and creates it. Returns the server's representation of the HelmRepo, and an error, if there is any.
  2. func (c *HelmRepos) Create(ctx context.Context, HelmRepo *v1alpha1.HelmRepo, opts v1.CreateOptions) (result *v1alpha1.HelmRepo, err error) {
  3. result = &v1alpha1.HelmRepo{}
  4. err = c.client.Post().
  5. Resource("Helmrepos").
  6. VersionedParams(&opts, scheme.ParameterCodec).
  7. Body(HelmRepo).
  8. Do(ctx).
  9. Into(result)
  10. return
  11. }

查询Helm 仓库应用模版代码介绍

接口实现

  1. 路由注册
  2. handler,参数解析,调用 models 方面
  3. models ,调用 models 方法
  4. crd client,调用 K8s api 存储
  1. webservice.Route(webservice.GET("/apps").LiHui, 6 months ago: ? openpitrix crd
  2. Deprecate().
  3. To(handler.ListApps). // 跟进
  4. Doc("List app templates").
  5. Param(webservice.QueryParameter(params.ConditionsParam, "query conditions,connect multiple conditions with commas, equal symbol for exact query, wave symbol for fuzzy query e.g. name~a").
  6. Required(false).
  7. DataFormat("key=%s,key~%s")).
  8. Param(webservice.QueryParameter(params.PagingParam, "paging query, e.g. limit=100,page=1").
  9. Required(false).
  10. DataFormat("limit=%d,page=%d").
  11. DefaultValue("limit=10,page=1")).
  12. Param(webservice.QueryParameter(params.ReverseParam, "sort parameters, e.g. reverse=true")).
  13. Param(webservice.QueryParameter(params.OrderByParam, "sort parameters, e.g. orderBy=createTime")).
  14. Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
  15. Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}))
  1. func (h *openpitrixHandler) ListApps(req *restful.Request, resp *restful.Response)
  2. limit, offset := params.ParsePaging(req)
  3. orderBy := params.GetStringValueWithDefault(req, params.OrderByParam, openpitrix.CreateTime)
  4. reverse := params.GetBoolValueWithDefault(req, params.ReverseParam, false)
  5. conditions, err := params.ParseConditions(req)
  6. if err != nil {
  7. klog.V(4).Infoln(err)
  8. api.HandleBadRequest(resp, nil, err)
  9. return
  10. }
  11. if req.PathParameter("workspace") != "" {
  12. conditions.Match[openpitrix.WorkspaceLabel] = req.PathParameter("workspace")
  13. }
  14. result, err := h.openpitrix.ListApps(conditions, orderBy, reverse, limit, offset) // 跟进
  15. if err != nil {
  16. klog.Errorln(err)
  17. handleOpenpitrixError(resp, err)
  18. return
  19. }
  20. resp.WriteEntity(result)
  21. }
  1. func (c *applicationOperator) ListApps(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
  2. apps, err := c.listApps(conditions) // 重点跟进
  3. if err != nil {
  4. klog.Error(err)
  5. return nil, err
  6. }
  7. apps = filterApps(apps, conditions)
  8. if reverse {
  9. sort.Sort(sort.Reverse(HelmApplicationList(apps)))
  10. } else {
  11. sort.Sort(HelmApplicationList(apps))
  12. }
  13. totalCount := len(apps)
  14. start, end := (&query.Pagination{Limit: limit, Offset: offset}).GetValidPagination(totalCount)
  15. apps = apps[start:end]
  16. items := make([]interface{}, 0, len(apps))
  17. for i := range apps {
  18. versions, err := c.getAppVersionsByAppId(apps[i].GetHelmApplicationId())
  19. if err != nil && !apierrors.IsNotFound(err) {
  20. return nil, err
  21. }
  22. ctg, _ := c.ctgLister.Get(apps[i].GetHelmCategoryId())
  23. items = append(items, convertApp(apps[i], versions, ctg, 0))
  24. }
  25. return &models.PageableResponse{Items: items, TotalCount: totalCount}, nil
  26. }
  27. // line 601
  28. func (c *applicationOperator) listApps(conditions *params.Conditions) (ret []*v1alpha1.HelmApplication, err error) {
  29. repoId := conditions.Match[RepoId]
  30. if repoId != "" && repoId != v1alpha1.AppStoreRepoId {
  31. // get Helm application from Helm repo
  32. if ret, exists := c.cachedRepos.ListApplicationsByRepoId(repoId); !exists {
  33. klog.Warningf("load repo failed, repo id: %s", repoId)
  34. return nil, loadRepoInfoFailed
  35. } else {
  36. return ret, nil
  37. }
  38. } else {
  39. if c.backingStoreClient == nil {
  40. return []*v1alpha1.HelmApplication{}, nil
  41. }
  42. ret, err = c.appLister.List(labels.SelectorFromSet(buildLabelSelector(conditions)))
  43. }
  44. return
  45. }
  1. func (c *cachedRepos) ListApplicationsByRepoId(repoId string) (ret []*v1alpha1.HelmApplication, exists bool) {
  2. c.RLock()
  3. defer c.RUnlock()
  4. if repo, exists := c.repos[repoId]; !exists {
  5. return nil, false
  6. } else {
  7. ret = make([]*v1alpha1.HelmApplication, 0, 10)
  8. for _, app := range c.apps {
  9. if app.GetHelmRepoId() == repo.Name { // 应用的仓库ID相同则追加
  10. ret = append(ret, app)
  11. }
  12. }
  13. }
  14. return ret, true
  15. }

既然 app template 是从缓存中获取的,那么缓存中的数据又是什么时候录入的呢?

  1. 创建全局缓存变量
  2. 添加新 Helm 仓库,K8s 中已安装 crd 控制器 HelmRepoController 发现有新的 HelmRepo 创建,更新 .Status.Data 内容
  3. informer 发现有更新,同时更新缓存

缓存更新的实现

  1. 创建全局变量,通过 init 函数初始化
  2. 通过 HelmRepo 的 informer 实现缓存同步更新
  3. 在每次调用接口的时候,hanlder 类中包换了缓存变量

创建接口类 openpitrix.Interface

  1. type openpitrixHandler struct {
  2. openpitrix openpitrix.Interface
  3. }
  4. func newOpenpitrixHandler(ksInformers informers.InformerFactory, ksClient versioned.Interface, option *openpitrixoptions.Options) *openpitrixHandler {
  5. var s3Client s3.Interface
  6. if option != nil && option.S3Options != nil && len(option.S3Options.Endpoint) != 0 {
  7. var err error
  8. s3Client, err = s3.NewS3Client(option.S3Options)
  9. if err != nil {
  10. klog.Errorf("failed to connect to storage, please check storage service status, error: %v", err)
  11. }
  12. }
  13. return &openpitrixHandler{
  14. openpitrix.NewOpenpitrixOperator(ksInformers, ksClient, s3Client),
  15. }
  16. }

NewOpenpitrixOperator

  • 通过在 informer 中添加通知函数,执行缓存更新
  • once.Do 只执行一次
  1. var cachedReposData reposcache.ReposCache
  2. var HelmReposInformer cache.SharedIndexInformer
  3. var once sync.Once
  4. func init() {
  5. cachedReposData = reposcache.NewReposCache() // 全局缓存
  6. }
  7. func NewOpenpitrixOperator(ksInformers ks_informers.InformerFactory, ksClient versioned.Interface, s3Client s3.Interface) Interface {
  8. once.Do(func() {
  9. klog.Infof("start Helm repo informer")
  10. HelmReposInformer = ksInformers.KubeSphereSharedInformerFactory().Application().V1alpha1().HelmRepos().Informer()
  11. HelmReposInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
  12. AddFunc: func(obj interface{}) {
  13. r := obj.(*v1alpha1.HelmRepo)
  14. cachedReposData.AddRepo(r) // 缓存更新, 点击跟进
  15. },
  16. UpdateFunc: func(oldObj, newObj interface{}) {
  17. oldR := oldObj.(*v1alpha1.HelmRepo)
  18. cachedReposData.DeleteRepo(oldR)
  19. r := newObj.(*v1alpha1.HelmRepo)
  20. cachedReposData.AddRepo(r)
  21. },
  22. DeleteFunc: func(obj interface{}) {
  23. r := obj.(*v1alpha1.HelmRepo)
  24. cachedReposData.DeleteRepo(r)
  25. },
  26. })
  27. go HelmReposInformer.Run(wait.NeverStop)
  28. })
  29. return &openpitrixOperator{
  30. AttachmentInterface: newAttachmentOperator(s3Client),
  31. // cachedReposData used
  32. ApplicationInterface: newApplicationOperator(cachedReposData, ksInformers.KubeSphereSharedInformerFactory(), ksClient, s3Client),
  33. // cachedReposData used
  34. RepoInterface: newRepoOperator(cachedReposData, ksInformers.KubeSphereSharedInformerFactory(), ksClient),
  35. // cachedReposData used
  36. ReleaseInterface: newReleaseOperator(cachedReposData, ksInformers.KubernetesSharedInformerFactory(), ksInformers.KubeSphereSharedInformerFactory(), ksClient),
  37. CategoryInterface: newCategoryOperator(ksInformers.KubeSphereSharedInformerFactory(), ksClient),
  38. }
  39. }

缓存更新逻辑

  1. // 缓存结构体
  2. type cachedRepos struct {
  3. sync.RWMutex
  4. chartsInRepo map[workspace]map[string]int
  5. repoCtgCounts map[string]map[string]int
  6. repos map[string]*v1alpha1.HelmRepo
  7. apps map[string]*v1alpha1.HelmApplication
  8. versions map[string]*v1alpha1.HelmApplicationVersion
  9. }
  • ByteArrayToSavedIndex:将 repo.Status.Data 转换为 SavedIndex 数组对象
  • 遍历 SavedIndex.Applications
  • 保存(app.ApplicationId:HelmApplication)到 cachedRepos.apps
  1. func (c *cachedRepos) AddRepo(repo *v1alpha1.HelmRepo) error {
  2. return c.addRepo(repo, false)
  3. }
  4. //Add new Repo to cachedRepos
  5. func (c *cachedRepos) addRepo(repo *v1alpha1.HelmRepo, builtin bool) error {
  6. if len(repo.Status.Data) == 0 {
  7. return nil
  8. }
  9. index, err := Helmrepoindex.ByteArrayToSavedIndex([]byte(repo.Status.Data))
  10. if err != nil {
  11. klog.Errorf("json unmarshal repo %s failed, error: %s", repo.Name, err)
  12. return err
  13. }
  14. ...
  15. chartsCount := 0
  16. for key, app := range index.Applications {
  17. if builtin {
  18. appName = v1alpha1.HelmApplicationIdPrefix + app.Name
  19. } else {
  20. appName = app.ApplicationId
  21. }
  22. HelmApp := v1alpha1.HelmApplication{
  23. ....
  24. }
  25. c.apps[app.ApplicationId] = &HelmApp
  26. var ctg, appVerName string
  27. var chartData []byte
  28. for _, ver := range app.Charts {
  29. chartsCount += 1
  30. if ver.Annotations != nil && ver.Annotations["category"] != "" {
  31. ctg = ver.Annotations["category"]
  32. }
  33. if builtin {
  34. appVerName = base64.StdEncoding.EncodeToString([]byte(ver.Name + ver.Version))
  35. chartData, err = loadBuiltinChartData(ver.Name, ver.Version)
  36. if err != nil {
  37. return err
  38. }
  39. } else {
  40. appVerName = ver.ApplicationVersionId
  41. }
  42. version := &v1alpha1.HelmApplicationVersion{
  43. ....
  44. }
  45. c.versions[ver.ApplicationVersionId] = version
  46. }
  47. ....
  48. }
  49. return nil
  50. }

HelmRepo 协调器

HelmRepo.Status.Data 加载流程

  1. LoadRepoIndex: convert index.yaml to IndexFile
  2. MergeRepoIndex: merge new and old IndexFile
  3. savedIndex.Bytes(): compress data with zlib.NewWriter
  4. 将 savedIndex 数据存入 CRD(HelmRepo.Status.Data)

关键结构体

  1. // HelmRepo.Status.Data == SavedIndex 压缩后的数据
  2. type SavedIndex struct {
  3. APIVersion string `json:"apiVersion"`
  4. Generated time.Time `json:"generated"`
  5. Applications map[string]*Application `json:"apps"`
  6. PublicKeys []string `json:"publicKeys,omitempty"`
  7. // Annotations are additional mappings uninterpreted by Helm. They are made available for
  8. // other applications to add information to the index file.
  9. Annotations map[string]string `json:"annotations,omitempty"`
  10. }
  11. // IndexFile represents the index file in a chart repository
  12. type IndexFile struct {
  13. APIVersion string `json:"apiVersion"`
  14. Generated time.Time `json:"generated"`
  15. Entries map[string]ChartVersions `json:"entries"`
  16. PublicKeys []string `json:"publicKeys,omitempty"`
  17. }

代码位置

  1. func (r *ReconcileHelmRepo) syncRepo(instance *v1alpha1.HelmRepo) error {
  2. // 1. load index from Helm repo
  3. index, err := Helmrepoindex.LoadRepoIndex(context.TODO(), instance.Spec.Url, &instance.Spec.Credential)
  4. if err != nil {
  5. klog.Errorf("load index failed, repo: %s, url: %s, err: %s", instance.GetTrueName(), instance.Spec.Url, err)
  6. return err
  7. }
  8. existsSavedIndex := &Helmrepoindex.SavedIndex{}
  9. if len(instance.Status.Data) != 0 {
  10. existsSavedIndex, err = Helmrepoindex.ByteArrayToSavedIndex([]byte(instance.Status.Data))
  11. if err != nil {
  12. klog.Errorf("json unmarshal failed, repo: %s, error: %s", instance.GetTrueName(), err)
  13. return err
  14. }
  15. }
  16. // 2. merge new index with old index which is stored in crd
  17. savedIndex := Helmrepoindex.MergeRepoIndex(index, existsSavedIndex)
  18. // 3. save index in crd
  19. data, err := savedIndex.Bytes()
  20. if err != nil {
  21. klog.Errorf("json marshal failed, error: %s", err)
  22. return err
  23. }
  24. instance.Status.Data = string(data)
  25. return nil
  26. }

Question:

Q1:Helm 仓库发包时如何进行 Helm release 版本控制

A:修改 Charts.yaml 中的字段 version,然后 Helm package, 等于新增一个 .tgz 包,老版本的不要删除,这时候执行 index 的时候会吧所有的 .tgz 包包含在内。

  1. $ Helm repo index stable --url=xxx.xx.xx.xxx:8081/
  2. $ cat index.yaml
  3. ....
  4. redis:
  5. - apiVersion: v1
  6. appVersion: "1.0"
  7. created: "2021-06-22T16:34:58.286583012+08:00"
  8. description: A Helm chart for Kubernetes
  9. digest: fd7c0d962155330527c0a512a74bea33302fca940b810c43ee5f461b1013dbf5
  10. name: redis
  11. urls:
  12. - xxx.xx.xx.xxx:8081/redis-0.1.1.tgz
  13. version: 0.1.1
  14. - apiVersion: v1
  15. appVersion: "1.0"
  16. created: "2021-06-22T16:34:58.286109049+08:00"
  17. description: A Helm chart for Kubernetes
  18. digest: 1a23bd6d5e45f9d323500bbe170011fb23bfccf2c1bd25814827eb8dc643d7f0
  19. name: redis
  20. urls:
  21. - xxx.xx.xx.xxx:8081/redis-0.1.0.tgz
  22. version: 0.1.0

Q2:KuberSphere 版本同步功能有缺失?用户添加完 Helm 仓库后,如果有新的应用发布,查询不到

A:解决方案:使用 3 种同步策略

  • 定时同步 Helm 仓库(HelmRepo 设置一个定时协调的事件)
  • 企业仓库,用户可以设置 hook,发布新版本的时候主动触发更新
  • 用户主动更新 charts

Q3:index.yaml 缓存位置

A:某些仓库的index.yaml 比较大,如果1000个用户,1000个charts 会太吃内存。建议常用index.yaml的放在内存中,不常用的index.yaml存储在本地磁盘。

本文由博客一文多发平台 OpenWrite 发布!

原文链接:http://www.cnblogs.com/kubesphere/p/14931543.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号