Helm 是查找、分享和使用软件构建 Kubernetes 的最优方式。
Helm 帮助管理 Kubernetes 应用—— Helm Chart,即使是最复杂的 Kubernetes 应用程序,都可以帮助定义,安装和升级。
概念
-
chart 创建Kubernetes应用程序所必需的一组信息。
Chart 代表着 Helm 包。它包含在 Kubernetes 集群内部运行应用程序,工具或服务所需的所有资源定义。你可以把它看作是 Homebrew formula,Apt dpkg,或 Yum RPM 在Kubernetes 中的等价物。
-
config 包含了可以合并到打包的chart中的配置信息,用于创建一个可发布的对象。
-
release 是一个与特定配置相结合的chart的运行实例。
-
Repository(仓库) 是用来存放和共享 charts 的地方。
三大概念
安装
列举chart仓库
1
2
3
|
helm repo list
NAME URL
piaohua https://piaohua.github.io/helm-charts/
|
基于github搭建helm repository
配置仓库
微软仓库(http://mirror.azure.cn/kubernetes/charts/)
阿里云仓库(https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts )
推荐仓库(https://charts.bitnami.com/bitnami )
- 添加仓库
1
2
3
4
5
6
7
8
|
helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
helm repo list
NAME URL
piaohua https://piaohua.github.io/helm-charts/
bitnami https://charts.bitnami.com/bitnami
|
- 在仓库中搜索chart
1
2
3
4
5
6
|
helm search repo nginx
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/nginx 16.0.6 1.25.5 NGINX Open Source is a web server that can be a...
bitnami/nginx-ingress-controller 11.1.1 1.10.1 NGINX Ingress Controller is an Ingress controll...
bitnami/nginx-intel 2.1.15 0.4.9 DEPRECATED NGINX Open Source for Intel is a lig...
|
- 删除仓库
1
2
3
4
5
6
7
|
helm repo remove bitnami
"bitnami" has been removed from your repositories
helm repo list
NAME URL
piaohua https://piaohua.github.io/helm-charts/
|
使用部署
- 从仓库中搜索可部署安装的nginx chart
1
2
3
4
5
6
|
helm search repo nginx
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/nginx 16.0.6 1.25.5 NGINX Open Source is a web server that can be a...
bitnami/nginx-ingress-controller 11.1.1 1.10.1 NGINX Ingress Controller is an Ingress controll...
bitnami/nginx-intel 2.1.15 0.4.9 DEPRECATED NGINX Open Source for Intel is a lig...
|
- 选择 bitnami/nginx chart 安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
helm install nginx-test bitnami/nginx
NAME: nginx-test
LAST DEPLOYED: Sun May 5 22:12:35 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 16.0.6
APP VERSION: 1.25.5
** Please be patient while the chart is being deployed **
NGINX can be accessed through the following DNS name from within your cluster:
nginx-test.default.svc.cluster.local (port 80)
To access NGINX from outside the cluster, follow the steps below:
1. Get the NGINX URL by running these commands:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
Watch the status with: 'kubectl get svc --namespace default -w nginx-test'
export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services nginx-test)
export SERVICE_IP=$(kubectl get svc --namespace default nginx-test -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo "http://${SERVICE_IP}:${SERVICE_PORT}"
WARNING: There are "resources" sections in the chart not set. Using "resourcesPreset" is not recommended for production. For production installations, please set the following values according to your workload needs:
- cloneStaticSiteFromGit.gitSync.resources
- resources
+info https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
|
可以看到安装成功后的输出,默认80端口
- 根据提示可以使用如下命令监听服务状态
1
2
3
|
kubectl get svc --namespace default -w nginx-test
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-test LoadBalancer 10.43.39.30 192.168.5.3 80:30195/TCP,443:30205/TCP 8m40s
|
- 安装成功后kubectl查看状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
kubectl get pods,rs,svc,deployment -n default
NAME READY STATUS RESTARTS AGE
pod/nginx-test-54dc4fd9d4-skj25 1/1 Running 0 26m
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-test-54dc4fd9d4 1 1 1 26m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 47m
service/nginx-test LoadBalancer 10.43.39.30 192.168.5.3 80:30195/TCP,443:30205/TCP 26m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx-test 1/1 1 1 26m
|
可以看到nginx-test svc的类型为LoadBalancer, 且已经绑定宿主主机端口.
- 安装成功后helm查看Chart列表
1
2
3
|
helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
nginx-test default 1 2024-05-05 22:12:35.906912 +0800 CST deployed nginx-16.0.6 1.25.5
|
- 安装成功后helm查看Chart状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
helm status nginx-test
NAME: nginx-test
LAST DEPLOYED: Sun May 5 22:12:35 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 16.0.6
APP VERSION: 1.25.5
** Please be patient while the chart is being deployed **
NGINX can be accessed through the following DNS name from within your cluster:
nginx-test.default.svc.cluster.local (port 80)
To access NGINX from outside the cluster, follow the steps below:
1. Get the NGINX URL by running these commands:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
Watch the status with: 'kubectl get svc --namespace default -w nginx-test'
export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services nginx-test)
export SERVICE_IP=$(kubectl get svc --namespace default nginx-test -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo "http://${SERVICE_IP}:${SERVICE_PORT}"
WARNING: There are "resources" sections in the chart not set. Using "resourcesPreset" is not recommended for production. For production installations, please set the following values according to your workload needs:
- cloneStaticSiteFromGit.gitSync.resources
- resources
+info https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
|
输出状态结果和安装成功结果一样
- 访问nginx服务
1
2
3
4
5
6
7
8
9
10
11
|
curl -I http://localhost:80
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 05 May 2024 14:16:49 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 16 Apr 2024 18:30:46 GMT
Connection: keep-alive
ETag: "661ec3d6-267"
X-Frame-Options: SAMEORIGIN
Accept-Ranges: bytes
|
或者在浏览器中打开: http://localhost
- 查看dokcer镜像和容器列表
1
2
3
4
5
6
7
8
|
docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
bitnami/nginx 1.25.5-debian-12-r0 23b46c97c65f 2 weeks ago 184MB
rancher/klipper-lb v0.4.4 af74bd845c4a 11 months ago 12MB
rancher/local-path-provisioner v0.0.24 b29384aeb4b1 13 months ago 40.1MB
rancher/mirrored-metrics-server v0.6.3 817bbe3f2e51 13 months ago 68.9MB
rancher/mirrored-coredns-coredns 1.10.1 ead0a4a53df8 15 months ago 53.6MB
rancher/mirrored-pause 3.6 6270bb605e12 2 years ago 683kB
|
可以看到安装后,多出来前面两个镜像。
容器列表
1
2
3
4
5
6
7
8
9
10
11
12
13
|
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46e3c9462277 23b46c97c65f "/opt/bitnami/script…" 10 minutes ago Up 10 minutes k8s_nginx_nginx-test-54dc4fd9d4-skj25_default_7498f914-6b7c-4795-950a-58ed2e4e8f43_0
6f28efe9598c af74bd845c4a "entry" 11 minutes ago Up 11 minutes k8s_lb-tcp-443_svclb-nginx-test-2c41a801-gh9lw_kube-system_c72ae284-6301-49d7-bdfe-918fd0245591_0
a3ea4e95f7ee rancher/klipper-lb "entry" 11 minutes ago Up 11 minutes k8s_lb-tcp-80_svclb-nginx-test-2c41a801-gh9lw_kube-system_c72ae284-6301-49d7-bdfe-918fd0245591_0
0141a5471677 rancher/mirrored-pause:3.6 "/pause" 11 minutes ago Up 11 minutes k8s_POD_svclb-nginx-test-2c41a801-gh9lw_kube-system_c72ae284-6301-49d7-bdfe-918fd0245591_0
439c4ae9bc63 rancher/mirrored-pause:3.6 "/pause" 11 minutes ago Up 11 minutes k8s_POD_nginx-test-54dc4fd9d4-skj25_default_7498f914-6b7c-4795-950a-58ed2e4e8f43_0
785c59542d32 rancher/mirrored-metrics-server "/metrics-server --c…" 30 minutes ago Up 30 minutes k8s_metrics-server_metrics-server-67c658944b-kqjgk_kube-system_86610a87-3816-4da6-9a68-7e49e8588a7c_0
4c4551704157 rancher/mirrored-coredns-coredns "/coredns -conf /etc…" 31 minutes ago Up 31 minutes k8s_coredns_coredns-6799fbcd5-pp8sr_kube-system_ed8eaa59-eaa6-4dd4-a3be-1cae57bd5fd0_0
01f1e74d85fb rancher/local-path-provisioner "local-path-provisio…" 31 minutes ago Up 31 minutes k8s_local-path-provisioner_local-path-provisioner-84db5d44d9-7qlrp_kube-system_1906322a-f01a-4174-a728-c622d958b212_0
e71408df6a74 rancher/mirrored-pause:3.6 "/pause" 31 minutes ago Up 31 minutes k8s_POD_metrics-server-67c658944b-kqjgk_kube-system_86610a87-3816-4da6-9a68-7e49e8588a7c_0
6a3c855075bf rancher/mirrored-pause:3.6 "/pause" 31 minutes ago Up 31 minutes k8s_POD_local-path-provisioner-84db5d44d9-7qlrp_kube-system_1906322a-f01a-4174-a728-c622d958b212_0
32a27eaf5489 rancher/mirrored-pause:3.6 "/pause" 31 minutes ago Up 31 minutes k8s_POD_coredns-6799fbcd5-pp8sr_kube-system_ed8eaa59-eaa6-4dd4-a3be-1cae57bd5fd0_0
|
部署nginx后,容器多出来前面5个。
卸载
1
|
helm uninstall nginx-test
|
卸载后,对应的pod,svc都会一起删除
自定义部署
1
2
3
4
5
6
7
8
|
# 生成values.yaml文件
helm inspect values bitnami/nginx > values.yaml
# 编辑配置自定义
vim values.yaml
# 使用配置文件安装部署
helm install mywebserver bitnami/nginx -f values.yaml
|
参考