helm-proxy

helm3使用

  • 查询helm repo list
    helm repo list

  • 添加helm repo
    helm repo add stable https://kubernetes-charts.storage.googleapis.com/

  • 更新helm repo
    helm repo update

  • 在hub上搜索,相当于helm提供的一个公共仓库,类似docker hub
    helm search hub mysql

  • 在repo上搜索,共有仓库之外,用户自己添加的helm仓库
    helm search repo mysql

  • 部署stable/mysql
    helm install -name mysql stable/mysql -n default

  • 部署应用列表
    helm list

  • 查看应用当前状态
    helm status mysql

  • 删除部署应用
    helm uninstall mysql

  • 从hub拉取chart
    helm pull https://hub.helm.sh/charts/incubator/mysqlha

  • 从hub拉取chart
    helm pull stable/mysql

  • 转化chart为k8s的yaml文件
    helm template stable/mysql

helm2 迁移到 helm3

Helm V2 到 V3 的变化

  • 删除tiller服务
  • release不再是全局资源,而是存储在各自的命名空间中
  • 把chart中的requirements.yaml内容合并到Chart.yaml中
  • helm install 时需要提供名称,如果需要自动生成则需要使用 - g 参数
  • helm delete 时,默认带上–purge(不保留历史),如果需要保留历史则需要带上–keep-history命令
  • Values支持Json Schema校验器

由于我们不想整个推翻Helm v2命令行工具,我们需要执行一个额外的操作来确保Helm v2和v3版本的命令行工具可以同时工作,直到我们准备好移除Helm v2命令行工具和所有相关的数据
重命名helm v3版本为helm3

安装helm-2to3插件 迁移插件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ helm3 plugin install https://github.com/helm/helm-2to3
Downloading and installing helm-2to3 v0.1.0 ...
https://github.com/helm/helm-2to3/releases/download/v0.1.0/helm-2to3_0.1.0_darwin_amd64.tar.gz
Installed plugin: 2to3

$ helm3 plugin list
NAME VERSION DESCRIPTION
2to3 0.1.0 migrate Helm v2 configuration and releases in-place to Helm v3

$ helm3 2to3
Migrate Helm v2 configuration and releases in-place to Helm v3

Usage:
2to3 [command]

Available Commands:
convert migrate Helm v2 release in-place to Helm v3
help Help about any command
move migrate Helm v2 configuration in-place to Helm v3

Flags:
-h, --help help for 2to3

Use "2to3 [command] --help" for more information about a command.

迁移Helm v2的配置

helm3 2to3 move config

验证
helm3 repo list

迁移Helm v2 releases

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 查询已经存在helm2中的release
helm list
# 选择一个release测试迁移
$ helm3 2to3 convert --dry-run postgres
NOTE: This is in dry-run mode, the following actions will not be executed.
Run without --dry-run to take the actions described below:

Release "postgres" will be converted from Helm 2 to Helm 3.
[Helm 3] Release "postgres" will be created.
[Helm 3] ReleaseVersion "postgres.v1" will be created.
# 测试通过后进行正式迁移
$ helm3 2to3 convert postgres
Release "postgres" will be converted from Helm 2 to Helm 3.
[Helm 3] Release "postgres" will be created.
[Helm 3] ReleaseVersion "postgres.v1" will be created.
[Helm 3] ReleaseVersion "postgres.v1" created.
[Helm 3] Release "postgres" created.
Release "postgres" was converted successfully from Helm 2 to Helm 3. Note: the v2 releases still remain and should be removed to avoid conflicts with the migrated v3 releases.
# 检测迁移是否成功
helm3 list

注意:由于我们并没有指定 –delete-vw-releases 标志,所以Helm v2 的postgres release仍然保留了下来,以后我们可以使用kubectl命令来删除它。

kind

  • 创建额外暴露端口集群
    kind create cluster –name kind –config kind-example-config.yaml
1
2
3
4
5
6
7
8
9
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 80
listenAddress: "0.0.0.0" # Optional, defaults to "0.0.0.0"
protocol: udp # Optional, defaults to tcp
  • 删除集群

    kind delete clusters kind

  • 加载docker镜像进入kind集群

    kind load docker-image image:tag

helm-wrapper

swagger 接口文档
http://localhost:8080/swagger/index.html

最小化go镜像发布

1
2
3
4
5
6
7
8
9
FROM scratch
#FROM centos:7

COPY config-example.yaml /config.yaml
COPY helm-wrapper /helm-wrapper

EXPOSE 8080

CMD [ "/helm-wrapper" ]

因为采取的是scratch做基础镜像不包含静态链接库,所以需要在构建go程序时使用静态构建(参数参考)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -ldflags ‘-s -w -extldflags “-static”‘ -o ${BINARY_NAME}

最后由scratch构建出的应用镜像大小为37.6MB,而centos7构建的镜像则为244MB
注意:scratch镜像精简了很多内容,包括bash等;在容器运行中可能无法直接打开shell界面