什么是heml

  • Helm是Kubernetes 应用的包管理工具,主要用来管理 Charts,类似Linux系统的yum。

  • Helm Chart 是用来封装 Kubernetes 原生应用程序的一系列 YAML 文件。可以在你部署应用的时候自定义应用程序的一些 Metadata,以便于应用程序的分发。

  • 对于应用发布者而言,可以通过 Helm 打包应用、管理应用依赖关系、管理应用版本并发布应用到软件仓库。

  • 对于使用者而言,使用 Helm 后不用需要编写复杂的应用部署文件,可以以简单的方式在 Kubernetes 上查找、安装、升级、回滚、卸载应用程序。

安装heml

  • https://helm.sh/docs/intro 官网
tar zxf helm-v3.1.1-linux-amd64.tar.gz
cd linux-amd64/
cp helm /usr/local/bin/



设置补齐
echo "source <(helm completion bash)" >> ~/.bashrc
  • 解压并上传至私有仓库 helm-push_0.9.0_linux_amd64.tar.gz
    新建项目mychart
[root@server1 heml]# helm create mychart
Creating mychart
[root@server1 heml]# tree mychart/
mychart/
├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

配置harbor仓库认证证书,harbor仓库配置时生成,存放在docker配置目录下,只需复制即可。

  • 安装helm push插件,获取插件目录 helm plugin install https://github.com/chartmuseum/helm-push
[root@server1 heml]# helm package mychart/
Successfully packaged chart and saved it to: /root/heml/mychart-0.1.0.tgz
[root@server1 heml]# cp /etc/docker/certs.d/reg.westos.org/ca.crt /etc/pki/ca-trust/source/anchors/
[root@server1 heml]# update-ca-trust 
[root@server1 heml]# helm env
HELM_BIN="helm"
HELM_CACHE_HOME="/root/.cache/helm"
HELM_CONFIG_HOME="/root/.config/helm"
HELM_DATA_HOME="/root/.local/share/helm"
HELM_DEBUG="false"
HELM_KUBEAPISERVER=""
HELM_KUBEASGROUPS=""
HELM_KUBEASUSER=""
HELM_KUBECONTEXT=""
HELM_KUBETOKEN=""
HELM_MAX_HISTORY="10"
HELM_NAMESPACE="default"
HELM_PLUGINS="/root/.local/share/helm/plugins"
HELM_REGISTRY_CONFIG="/root/.config/helm/registry.json"
HELM_REPOSITORY_CACHE="/root/.cache/helm/repository"
HELM_REPOSITORY_CONFIG="/root/.config/helm/repositories.yaml"
[root@server1 heml]# mkdir -p /root/.local/share/helm/plugins
[root@server1 heml]# cd /root/.local/share/helm/plugins
[root@server1 plugins]# mkdir push
  • tar zxf helm-push_0.9.0_linux_amd64.tar.gz -C /root/.local/share/helm/plugins/push/解压至目录中
  • helm repo westos https://reg.westos.org/chartrepo/charts为helm添加本地仓库
    在这里插入图片描述
[root@server1 heml]# helm repo list
NAME  	URL                                    
westos	https://reg.westos.org/chartrepo/charts
[root@server1 heml]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "westos" chart repository
Update Complete. ⎈Happy Helming![root@server1 heml]# helm search repo mychart
NAME          	CHART VERSION	APP VERSION	DESCRIPTION                
westos/mychart	0.1.0        	latest     	A Helm chart for Kubernetes

在这里插入图片描述
在这里插入图片描述

  • 上传chart至本地仓库helm push mychart-0.1.0.tgz westos --insecure -u admin -p westos
[root@server1 heml]# cd mychart/
[root@server1 mychart]# vim Chart.yaml 
[root@server1 mychart]# vim values.yaml 
[root@server1 mychart]# vim values.yaml 
[root@server1 mychart]# cd ..
[root@server1 heml]# helm lint mychart/
==> Linting mychart/
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed
[root@server1 heml]# helm package mychart/
Successfully packaged chart and saved it to: /root/heml/mychart-0.1.0.tgz
[root@server1 heml]# helm push mychart-0.1.0.tgz westos --insecure -u admin -p westos
Pushing mychart-0.1.0.tgz to westos...
Done.
[root@server1 heml]# helm repo update 
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "westos" chart repository
Update Complete. ⎈Happy Helming![root@server1 heml]# helm search repo mychart
NAME          	CHART VERSION	APP VERSION	DESCRIPTION                
westos/mychart	0.1.0        	v1         	A Helm chart for Kubernetes

[root@server1 heml]# helm install mychart westos/mychart 
NAME: mychart
LAST DEPLOYED: Wed Aug  4 17:59:26 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=mychart,app.kubernetes.io/instance=mychart" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
[root@server1 heml]# kubectl get svc #查看部署状态,查看部署是否成功
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)        AGE
mychart      ClusterIP      10.100.62.243    <none>         80/TCP         15s
[root@server1 heml]# curl 10.100.62.243
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>

修改升级为v2,打包
在这里插入图片描述
在这里插入图片描述

[root@server1 heml]# vim mychart/Chart.yaml 
[root@server1 heml]# vim mychart/values.yaml 
[root@server1 heml]# helm lint mychart/
==> Linting mychart/
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed
[root@server1 heml]# helm package mychart/ #打包
Successfully packaged chart and saved it to: /root/heml/mychart-0.2.0.tgz
[root@server1 heml]# helm push mychart-0.2.0.tgz westos --insecure -u admin -p westos #上传
Pushing mychart-0.2.0.tgz to westos...
Done.
[root@server1 heml]# helm repo update  # 更新
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "westos" chart repository
Update Complete. ⎈Happy Helming![root@server1 heml]# helm search repo mychart -l
NAME          	CHART VERSION	APP VERSION	DESCRIPTION                
westos/mychart	0.2.0        	v2         	A Helm chart for Kubernetes
westos/mychart	0.1.0        	v1         	A Helm chart for Kubernetes
[root@server1 heml]# helm upgrade mychart westos/mychart # 升级mychart
Release "mychart" has been upgraded. Happy Helming!
NAME: mychart
LAST DEPLOYED: Wed Aug  4 18:01:54 2021
NAMESPACE: default
STATUS: deployed
REVISION: 2
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=mychart,app.kubernetes.io/instance=mychart" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
[root@server1 heml]# curl 10.100.62.243 | mychart/
-bash: mychart/: Is a directory
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    65  100    65    0     0  15730      0 --:--:-- --:--:-- --:--:-- 21666
(23) Failed writing body
[root@server1 heml]# curl 10.100.62.243 | mychart
-bash: mychart: command not found
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    65  100    65    0     0   3042      0 --:--:-- --:--:-- --:--:--  3250
(23) Failed writing body
[root@server1 heml]# curl 10.100.62.243 | grep mychart
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    65  100    65    0     0   2227      0 --:--:-- --:--:-- --:--:--  2321
[root@server1 heml]# kubectl get svc
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)        AGE
mychart      ClusterIP      10.100.62.243    <none>         80/TCP         3m4s
[root@server1 heml]# curl 10.100.62.243 
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>

在仓库查看
在这里插入图片描述

  • 回滚helm rollback mychart 1

在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐