1、概述

我们一般是在k8s里面部署一些简单的应用,比如用deployment,daemonset,statefuleset的方式来部署应用,但是如果要部署一些复杂的应用,那么整个配置的编写、部署的过程就会变的更加的复杂,那么helm这个工具就可以来帮助解决这个复杂应用的部署问题。

helm可以类比与linux环境下yum部署应用的方式,只需要执行几条命令,就可以将应用需要的配置、依赖都部署到环境中。同样,helm也是通过几条简单的命令,将某个应用需要的配置、依赖都部署到了k8s集群上。

本文档就通过helm的安装和使用的角度来介绍下helm这个k8s的应用包管理工具。

2、helm中基本概念

在helm这个工具的使用中,主要有3个基本的概念需要了解:

Chart: chart就是helm中的包。类似yum安装中使用的rpm包。chart安装到k8s之后就是一个应用,那么chart中就包含了所有需要的资源的定义。

Repository: chart存放的位置。类似yum源的概念。

Release: chart在k8s集群中运行起来之后形成的实例。就类似与部署一个deployment要给一个名字一样。一个chart可以在同一个集群中被安装很多次,每一次的安装,都会创建一个新的release。就和拿一个redis的安装包可以安装很多次一样的。每次安装都有一个实例对应有自己的端口号,配置一样的。

那么针对以上的概念的说明,针对helm可以有如下的表述:

helm在chart仓库中获得chart,然后将chart安装到k8s集群中,每次安装都创建一个release.

3、helm的安装

可以通过预编译的二进制文件来安装helm的客户端命令,具体的版本可以到helm的github上去下载:

https://github.com/helm/helm/releases

本文档使用的版本:

https://get.helm.sh/helm-v3.7.2-linux-amd64.tar.gz

注意:安装在包含kubeconfig的主机上,这样helm就可以操作k8s集群来部署对应的应用,helm默认去"~/.kube/config"目录下获取kubeconfig来连接k8s集群。

安装过程

(1)先上传helm的压缩包到服务器

(2)解压并且复制helm命令

  1. tar -zxf helm-v3.7.2-linux-amd64.tar.gz \
  2. && cd linux-amd64 \
  3. cp helm /usr/local/bin/

(3)验证helm命令

输入helm命令,如果输出如下,则表示helm安装成功

  1. [root@nccztsjb-node-11 linux-amd64]# helm
  2. The Kubernetes package manager
  3. Common actions for Helm:
  4. - helm search: search for charts
  5. - helm pull: download a chart to your local directory to view
  6. - helm install: upload the chart to Kubernetes
  7. - helm list: list releases of charts
  8. Environment variables:
  9. | Name | Description |
  10. |------------------------------------|-----------------------------------------------------------------------------------|
  11. | $HELM_CACHE_HOME | set an alternative location for storing cached files. |
  12. | $HELM_CONFIG_HOME | set an alternative location for storing Helm configuration. |
  13. | $HELM_DATA_HOME | set an alternative location for storing Helm data. |
  14. | $HELM_DEBUG | indicate whether or not Helm is running in Debug mode |
  15. | $HELM_DRIVER | set the backend storage driver. Values are: configmap, secret, memory, sql. |
  16. | $HELM_DRIVER_SQL_CONNECTION_STRING | set the connection string the SQL storage driver should use. |
  17. | $HELM_MAX_HISTORY | set the maximum number of helm release history. |
  18. | $HELM_NAMESPACE | set the namespace used for the helm operations. |
  19. | $HELM_NO_PLUGINS | disable plugins. Set HELM_NO_PLUGINS=1 to disable plugins. |
  20. | $HELM_PLUGINS | set the path to the plugins directory |
  21. | $HELM_REGISTRY_CONFIG | set the path to the registry config file. |
  22. | $HELM_REPOSITORY_CACHE | set the path to the repository cache directory |
  23. | $HELM_REPOSITORY_CONFIG | set the path to the repositories file. |
  24. | $KUBECONFIG | set an alternative Kubernetes configuration file (default "~/.kube/config") |
  25. | $HELM_KUBEAPISERVER | set the Kubernetes API Server Endpoint for authentication |
  26. | $HELM_KUBECAFILE | set the Kubernetes certificate authority file. |
  27. | $HELM_KUBEASGROUPS | set the Groups to use for impersonation using a comma-separated list. |
  28. | $HELM_KUBEASUSER | set the Username to impersonate for the operation. |
  29. | $HELM_KUBECONTEXT | set the name of the kubeconfig context. |
  30. | $HELM_KUBETOKEN | set the Bearer KubeToken used for authentication. |
  31. Helm stores cache, configuration, and data based on the following configuration order:
  32. - If a HELM_*_HOME environment variable is set, it will be used
  33. - Otherwise, on systems supporting the XDG base directory specification, the XDG variables will be used
  34. - When no other location is set a default location will be used based on the operating system
  35. By default, the default directories depend on the Operating System. The defaults are listed below:
  36. | Operating System | Cache Path | Configuration Path | Data Path |
  37. |------------------|---------------------------|--------------------------------|-------------------------|
  38. | Linux | $HOME/.cache/helm | $HOME/.config/helm | $HOME/.local/share/helm |
  39. | macOS | $HOME/Library/Caches/helm | $HOME/Library/Preferences/helm | $HOME/Library/helm |
  40. | Windows | %TEMP%\helm | %APPDATA%\helm | %APPDATA%\helm |
  41. Usage:
  42. helm [command]
  43. Available Commands:
  44. completion generate autocompletion scripts for the specified shell
  45. create create a new chart with the given name
  46. dependency manage a chart's dependencies
  47. env helm client environment information
  48. get download extended information of a named release
  49. help Help about any command
  50. history fetch release history
  51. install install a chart
  52. lint examine a chart for possible issues
  53. list list releases
  54. package package a chart directory into a chart archive
  55. plugin install, list, or uninstall Helm plugins
  56. pull download a chart from a repository and (optionally) unpack it in local directory
  57. repo add, list, remove, update, and index chart repositories
  58. rollback roll back a release to a previous revision
  59. search search for a keyword in charts
  60. show show information of a chart
  61. status display the status of the named release
  62. template locally render templates
  63. test run tests for a release
  64. uninstall uninstall a release
  65. upgrade upgrade a release
  66. verify verify that a chart at the given path has been signed and is valid
  67. version print the client version information
  68. Flags:
  69. --debug enable verbose output
  70. -h, --help help for helm
  71. --kube-apiserver string the address and the port for the Kubernetes API server
  72. --kube-as-group stringArray group to impersonate for the operation, this flag can be repeated to specify multiple groups.
  73. --kube-as-user string username to impersonate for the operation
  74. --kube-ca-file string the certificate authority file for the Kubernetes API server connection
  75. --kube-context string name of the kubeconfig context to use
  76. --kube-token string bearer token used for authentication
  77. --kubeconfig string path to the kubeconfig file
  78. -n, --namespace string namespace scope for this request
  79. --registry-config string path to the registry config file (default "/root/.config/helm/registry.json")
  80. --repository-cache string path to the file containing cached repository indexes (default "/root/.cache/helm/repository")
  81. --repository-config string path to the file containing repository names and URLs (default "/root/.config/helm/repositories.yaml")
  82. Use "helm [command] --help" for more information about a command.

4、helm的使用

那么这里就要介绍在如何使用helm来安装和管理应用包了。

4.1、获取应用的repository

比如我们要安装一个nginx应用,那么我们首先要知道哪些库,类似于哪些yum源中有这个包,那么方法就是登录如下的地址:

https://artifacthub.io/

这个中包含了所有的有这个应用包的一个汇总

在其中搜索“nginx”

就会有各种组织发布的不同的功能的包含nginx的包。

点开第一个,就会有相关的使用的说明

那么这个https://charts.bitnami.com/bitnami URL就是包含这个chart的仓库。

4.2、helm添加仓库和删除

4.2.1、添加

OK,基于4.1中找到了包含需要的nginx的仓库,那么就要把他加入到helm的repo中,也可以按照上面的查找的nginx的repo页面的描述来添加和安装。

https://artifacthub.io/packages/helm/bitnami/nginx这个页面就有关于这个chart如何安装和使用的具体的说明。

  1. helm repo add bitnami https://charts.bitnami.com/bitnami

其中bitnami是定义的仓库的名字,由于是要加入到本地的,可自行的定义。

执行过程

  1. [root@nccztsjb-node-11 ~]# helm repo add bitnami https://charts.bitnami.com/bitnami
  2. "bitnami" has been added to your repositories

查看仓库列表

  1. [root@nccztsjb-node-11 ~]# helm repo list
  2. NAME URL
  3. bitnami https://charts.bitnami.com/bitnami
  4. [root@nccztsjb-node-11 ~]#

可以看到仓库和对应的URL信息。

4.2.1、删除

可以通过如下的命令进行仓库的删除

  1. helm repo remove bitnami

执行过程

  1. [root@nccztsjb-node-11 ~]# helm repo remove bitnami
  2. "bitnami" has been removed from your repositories
  3. [root@nccztsjb-node-11 ~]# helm repo list
  4. Error: no repositories to show
  5. [root@nccztsjb-node-11 ~]#

可以看到在helm中没有任何的仓库的信息了。

通过以上的库的增加和删除可以看到,就是对helm进行配置将包含chart的url地址添加为helm的仓库。后续helm命令就去这些仓库对应的url中去找需要的chart,获取chart的包,然后部署到k8s上。

4.3、chart的查找

在已经添加的本地库中查找需需要的char即应用包

  1. [root@nccztsjb-node-11 ~]# helm search repo nginx
  2. NAME CHART VERSION APP VERSION DESCRIPTION
  3. bitnami/nginx 9.7.1 1.21.5 Chart for the nginx server
  4. bitnami/nginx-ingress-controller 9.1.2 1.1.1 Chart for the nginx Ingress controller
  5. bitnami/kong 5.0.1 2.7.0 Kong is a scalable, open source API layer (aka ...
  6. [root@nccztsjb-node-11 ~]#

从输出中可以看到软件包的名字,其中的应用的版本信息,chart的版本信息,具体的chart的描述

4.4、chart安装和卸载

4.4.1、安装

以安装nginx的chart为例

  1. helm install helm-nginx bitnami/nginx

install后面就是release的名字,可根据需要自行的定义。

安装过程

  1. [root@nccztsjb-node-11 ~]# helm install helm-nginx bitnami/nginx
  2. NAME: helm-nginx
  3. LAST DEPLOYED: Mon Jan 17 10:33:26 2022
  4. NAMESPACE: default
  5. STATUS: deployed
  6. REVISION: 1
  7. TEST SUITE: None
  8. NOTES:
  9. CHART NAME: nginx
  10. CHART VERSION: 9.7.1
  11. APP VERSION: 1.21.5
  12. ** Please be patient while the chart is being deployed **
  13. NGINX can be accessed through the following DNS name from within your cluster:
  14. helm-nginx.default.svc.cluster.local (port 80)
  15. To access NGINX from outside the cluster, follow the steps below:
  16. 1. Get the NGINX URL by running these commands:
  17. NOTE: It may take a few minutes for the LoadBalancer IP to be available.
  18. Watch the status with: 'kubectl get svc --namespace default -w helm-nginx'
  19. export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services helm-nginx)
  20. export SERVICE_IP=$(kubectl get svc --namespace default helm-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
  21. echo "http://${SERVICE_IP}:${SERVICE_PORT}"

安装是异步的,也就是这里提示的只是成功的将chart发布到了k8s中,应用的部署还需要时间。

从其他的信息中也可以知道,如果要访问其中的服务的方法是什么。

  1. export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services helm-nginx)
  2. export SERVICE_IP=$(kubectl get svc --namespace default helm-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
  3. echo "http://${SERVICE_IP}:${SERVICE_PORT}"

查看部署的状态

  1. [root@nccztsjb-node-11 ~]# helm status helm-nginx
  2. NAME: helm-nginx
  3. LAST DEPLOYED: Mon Jan 17 10:33:26 2022
  4. NAMESPACE: default
  5. STATUS: deployed
  6. REVISION: 1
  7. TEST SUITE: None
  8. NOTES:
  9. CHART NAME: nginx
  10. CHART VERSION: 9.7.1
  11. APP VERSION: 1.21.5
  12. ** Please be patient while the chart is being deployed **
  13. NGINX can be accessed through the following DNS name from within your cluster:
  14. helm-nginx.default.svc.cluster.local (port 80)
  15. To access NGINX from outside the cluster, follow the steps below:
  16. 1. Get the NGINX URL by running these commands:
  17. NOTE: It may take a few minutes for the LoadBalancer IP to be available.
  18. Watch the status with: 'kubectl get svc --namespace default -w helm-nginx'
  19. export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services helm-nginx)
  20. export SERVICE_IP=$(kubectl get svc --namespace default helm-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
  21. echo "http://${SERVICE_IP}:${SERVICE_PORT}"

查看具体的pod的运行状态

  1. [root@nccztsjb-node-11 ~]# kubectl get pod | grep helm-nginx
  2. helm-nginx-5756488bdb-vvp9g 1/1 Running 0 3m1s
  3. [root@nccztsjb-node-11 ~]#

pod已经正常的处于Running的状态了。

4.4.2、卸载

如果要卸载应用,方法如下

  1. [root@nccztsjb-node-11 ~]# helm uninstall helm-nginx
  2. release "helm-nginx" uninstalled
  3. [root@nccztsjb-node-11 ~]# helm status helm-nginx
  4. Error: release: not found
  5. [root@nccztsjb-node-11 ~]# helm list
  6. NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
  7. [root@nccztsjb-node-11 ~]#

OK,这样就完成了应用的卸载。

4.5、查看chart的信息

和yum中的rpm包一样,我们也可以查看chart中的描述信息

  1. [root@nccztsjb-node-11 ~]# helm inspect
  2. This command consists of multiple subcommands to display information about a chart
  3. Usage:
  4. helm show [command]
  5. Aliases:
  6. show, inspect
  7. Available Commands:
  8. all show all information of the chart
  9. chart show the chart's definition
  10. crds show the chart's CRDs
  11. readme show the chart's README
  12. values show the chart's values
  13. Flags:
  14. -h, --help help for show
  15. Global Flags:
  16. --debug enable verbose output
  17. --kube-apiserver string the address and the port for the Kubernetes API server
  18. --kube-as-group stringArray group to impersonate for the operation, this flag can be repeated to specify multiple groups.
  19. --kube-as-user string username to impersonate for the operation
  20. --kube-ca-file string the certificate authority file for the Kubernetes API server connection
  21. --kube-context string name of the kubeconfig context to use
  22. --kube-token string bearer token used for authentication
  23. --kubeconfig string path to the kubeconfig file
  24. -n, --namespace string namespace scope for this request
  25. --registry-config string path to the registry config file (default "/root/.config/helm/registry.json")
  26. --repository-cache string path to the file containing cached repository indexes (default "/root/.cache/helm/repository")
  27. --repository-config string path to the file containing repository names and URLs (default "/root/.config/helm/repositories.yaml")
  28. Use "helm show [command] --help" for more information about a command.

其中,all是所有的信息,配置的默认值使用value命令。

查看nginx chart的安装使用的默认值

  1. [root@nccztsjb-node-11 ~]# helm inspect values bitnami/nginx
  2. ## @section Global parameters
  3. ## Global Docker image parameters
  4. ## Please, note that this will override the image parameters, including dependencies, configured to use the global value
  5. ## Current available global Docker image parameters: imageRegistry, imagePullSecrets and storageClass
  6. ## @param global.imageRegistry Global Docker image registry
  7. ## @param global.imagePullSecrets Global Docker registry secret names as an array
  8. ##
  9. global:
  10. imageRegistry: ""
  11. ## E.g.
  12. ## imagePullSecrets:
  13. ## - myRegistryKeySecretName
  14. ##
  15. imagePullSecrets: []
  16. ## @section Common parameters
  17. ## @param nameOverride String to partially override nginx.fullname template (will maintain the release name)
  18. ##
  19. nameOverride: ""
  20. ## @param fullnameOverride String to fully override nginx.fullname template
  21. ##
  22. fullnameOverride: ""
  23. ## @param kubeVersion Force target Kubernetes version (using Helm capabilities if not set)
  24. ##
  25. kubeVersion: ""
  26. ## @param clusterDomain Kubernetes Cluster Domain
  27. ##
  28. clusterDomain: cluster.local
  29. ## @param extraDeploy Extra objects to deploy (value evaluated as a template)
  30. ##
  31. extraDeploy: []
  32. ## @param commonLabels Add labels to all the deployed resources
  33. ##
  34. commonLabels: {}
  35. ## @param commonAnnotations Add annotations to all the deployed resources
  36. ##
  37. commonAnnotations: {}
  38. ## @section NGINX parameters
  39. ## Bitnami NGINX image version
  40. ## ref: https://hub.docker.com/r/bitnami/nginx/tags/
  41. ## @param image.registry NGINX image registry
  42. ## @param image.repository NGINX image repository
  43. ## @param image.tag NGINX image tag (immutable tags are recommended)
  44. ## @param image.pullPolicy NGINX image pull policy
  45. ## @param image.pullSecrets Specify docker-registry secret names as an array
  46. ## @param image.debug Set to true if you would like to see extra information on logs
  47. ##
  48. image:
  49. registry: docker.io
  50. repository: bitnami/nginx
  51. ... 以下的内容省略...

这些就是一些默认的配置项,在安装的时候可以通过yaml或者--set来进行指定修改默认的配置,比如使用的镜像的信息,版本等。

4.6、chart导出为本地压缩包

chart就是部署应用时需要的配置,那么可以将这些配置都拉取到本地,和rpm一样。

使用如下的命令来获取

  1. [root@nccztsjb-node-11 ~]# helm pull bitnami/nginx .
  2. Error: non-absolute URLs should be in form of repo_name/path_to_chart, got: .
  3. [root@nccztsjb-node-11 ~]# ls -l
  4. total 24376
  5. -rw-------. 1 root root 1396 Jun 22 2018 anaconda-ks.cfg
  6. -rw-r--r-- 1 root root 3485 Aug 10 2013 cloud-set-guest-password
  7. -rw-r--r-- 1 root root 13870692 Jan 14 14:02 helm-v3.7.2-linux-amd64.tar.gz
  8. -rw-r--r-- 1 root root 9080681 Jan 14 14:55 kubectl-df-pv_v0.3.0_linux_amd64.tar.gz
  9. -rw-r--r-- 1 root root 1870468 Jan 14 14:45 kubectl-example_1.1.0_Linux_x86_64.tar.gz
  10. -rw-r--r-- 1 1001 docker 11343 Jul 27 22:05 LICENSE
  11. drwxr-xr-x 2 3434 3434 4096 Dec 9 04:31 linux-amd64
  12. -rw-r--r-- 1 root root 1021 Jan 14 09:45 ncc-sysconfig-ing.yaml
  13. -rw-r--r-- 1 root root 38340 Jan 17 11:32 nginx-9.7.1.tgz
  14. -rw-r--r-- 1 root root 48556 Jan 13 16:47 rabbitmq-8.26.1.tgz
  15. -rw-r--r-- 1 1001 docker 6154 Jul 27 22:05 README.md
  16. -rwxr-xr-x 1 root root 4220 Dec 6 15:33 update_image
  17. [root@nccztsjb-node-11 ~]# ls -l nginx-9.7.1.tgz
  18. -rw-r--r-- 1 root root 38340 Jan 17 11:32 nginx-9.7.1.tgz

这样就把nginx的char下载到了本地。其中9.7.1是chart的版本信息。

4.7、查看本地chart包

对于本地的chart来说就是一个目录

  1. [root@nccztsjb-node-11 ~]# tar -zxf nginx-9.7.1.tgz
  2. [root@nccztsjb-node-11 ~]# ls -ltr
  3. total 60
  4. -rw-r--r-- 1 root root 3485 Aug 10 2013 cloud-set-guest-password
  5. -rw-------. 1 root root 1396 Jun 22 2018 anaconda-ks.cfg
  6. -rwxr-xr-x 1 root root 4220 Dec 6 15:33 update_image
  7. -rw-r--r-- 1 root root 38340 Jan 17 11:32 nginx-9.7.1.tgz
  8. drwxr-xr-x 5 root root 4096 Jan 17 11:35 nginx

chart目录结构如下:

  1. [root@nccztsjb-node-11 ~]# tree nginx
  2. nginx
  3. ├── Chart.lock
  4. ├── charts
  5.    └── common
  6.    ├── Chart.yaml
  7.    ├── README.md
  8.    ├── templates
  9.       ├── _affinities.tpl
  10.       ├── _capabilities.tpl
  11.       ├── _errors.tpl
  12.       ├── _images.tpl
  13.       ├── _ingress.tpl
  14.       ├── _labels.tpl
  15.       ├── _names.tpl
  16.       ├── _secrets.tpl
  17.       ├── _storage.tpl
  18.       ├── _tplvalues.tpl
  19.       ├── _utils.tpl
  20.       ├── validations
  21.          ├── _cassandra.tpl
  22.          ├── _mariadb.tpl
  23.          ├── _mongodb.tpl
  24.          ├── _postgresql.tpl
  25.          ├── _redis.tpl
  26.          └── _validations.tpl
  27.       └── _warnings.tpl
  28.    └── values.yaml
  29. ├── Chart.yaml
  30. ├── ci
  31.    ├── ct-values.yaml
  32.    └── values-with-ingress-metrics-and-serverblock.yaml
  33. ├── README.md
  34. ├── templates
  35.    ├── deployment.yaml
  36.    ├── extra-list.yaml
  37.    ├── health-ingress.yaml
  38.    ├── _helpers.tpl
  39.    ├── hpa.yaml
  40.    ├── ingress.yaml
  41.    ├── ldap-daemon-secrets.yaml
  42.    ├── NOTES.txt
  43.    ├── pdb.yaml
  44.    ├── prometheusrules.yaml
  45.    ├── server-block-configmap.yaml
  46.    ├── serviceaccount.yaml
  47.    ├── servicemonitor.yaml
  48.    ├── svc.yaml
  49.    └── tls-secrets.yaml
  50. ├── values.schema.json
  51. └── values.yaml
  52. 6 directories, 43 files
  53. [root@nccztsjb-node-11 ~]#

主要的目录结构

  1. [root@nccztsjb-node-11 ~]# tree -L 1 nginx
  2. nginx
  3. ├── Chart.lock
  4. ├── charts
  5. ├── Chart.yaml
  6. ├── ci
  7. ├── README.md
  8. ├── templates
  9. ├── values.schema.json
  10. └── values.yaml
  11. 3 directories, 5 files
  12. [root@nccztsjb-node-11 ~]#

4.8、chart安装时使用自定义的配置

在安装chart的时候,如果不进行指定,那么就会使用默认的配置,比如,默认的镜像版本,镜像仓库,启动命令等等,这个可以根据实际的需要进行修改。

安装时使用自定义的配置的方式有2种,一种是在命令行中使用--set命令,一种是使用yaml配置文件。

4.8.1、--set的方式

--set 后面设置key1=value1,key2=value2,多个值之间用逗号隔开,再有,层级关系的用.(点)间隔

  1. helm install helm-nginx bitnami/nginx --set resources.limits.cpu=2,resources.limits.memory=2048Mi,resources.requests.cpu=1,resources.requests.memory=1024Mi

安装后,查看具体的pod的资源情况

  1. [root@nccztsjb-node-11 ~]# kubectl get deployment helm-nginx -o yaml | grep -A 6 resources
  2. f:resources:
  3. .: {}
  4. f:limits:
  5. .: {}
  6. f:cpu: {}
  7. f:memory: {}
  8. f:requests:
  9. --
  10. resources:
  11. limits:
  12. cpu: "2"
  13. memory: 2Gi
  14. requests:
  15. cpu: "1"
  16. memory: 1Gi
  17. [root@nccztsjb-node-11 ~]#

可以看到resources部分,cpu和memory的值都已经被修改了。

如果不加任何的参数,默认的值:

  1. [root@nccztsjb-node-11 ~]# kubectl get deployment helm-nginx -o yaml | grep -A 6 resources
  2. f:resources: {}
  3. f:terminationMessagePath: {}
  4. f:terminationMessagePolicy: {}
  5. f:dnsPolicy: {}
  6. f:restartPolicy: {}
  7. f:schedulerName: {}
  8. f:securityContext: {}
  9. --
  10. resources: {}
  11. terminationMessagePath: /dev/termination-log
  12. terminationMessagePolicy: File
  13. dnsPolicy: ClusterFirst
  14. restartPolicy: Always
  15. schedulerName: default-scheduler
  16. securityContext: {}
  17. [root@nccztsjb-node-11 ~]#

默认是 resources: {}即没有资源的限制。

具体的怎么查找值,可以参考4.5中values的部分

  1. resources:
  2. ## Example:
  3. ## limits:
  4. ## cpu: 100m
  5. ## memory: 128Mi
  6. limits: {}
  7. ## Examples:
  8. ## requests:
  9. ## cpu: 100m
  10. ## memory: 128Mi
  11. requests: {}
  12. ## NGINX containers' liveness probe.
  13. ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes
  14. ## @param livenessProbe.enabled Enable livenessProbe
  15. ## @param livenessProbe.initialDelaySeconds Initial delay seconds for livenessProbe
  16. ## @param livenessProbe.periodSeconds Period seconds for livenessProbe
  17. ## @param livenessProbe.timeoutSeconds Timeout seconds for livenessProbe
  18. ## @param livenessProbe.failureThreshold Failure threshold for livenessProbe
  19. ## @param livenessProbe.successThreshold Success threshold for livenessProbe
  20. ##

OK,以上就是通过--set在命令行中以key-value的方式进行设置。

4.8.2、-f config.yaml的方式

另外的一种方式就是通过yaml配置文件来进行设置,可以指定多个yaml文件

将配置都写入到yaml文件中去

resource.yaml(对资源配置的修改)

  1. [root@nccztsjb-node-11 ~]# cat resource.yaml
  2. resources:
  3. limits:
  4. cpu: 2
  5. memory: 2048Mi
  6. requests:
  7. cpu: 1
  8. memory: 1024Mi

健康检查配置调整

  1. [root@nccztsjb-node-11 ~]# cat healthCheck.yaml
  2. livenessProbe:
  3. enabled: true
  4. initialDelaySeconds: 20
  5. timeoutSeconds: 5
  6. periodSeconds: 10
  7. failureThreshold: 6
  8. successThreshold: 1
  9. readinessProbe:
  10. enabled: true
  11. initialDelaySeconds: 15
  12. timeoutSeconds: 3
  13. periodSeconds: 5
  14. failureThreshold: 3
  15. successThreshold: 1
  16. [root@nccztsjb-node-11 ~]#

通过以上的配置文件进行安装

  1. helm install helm-nginx bitnami/nginx -f resource.yaml -f healthCheck.yaml

查看安装之后的配置

  1. [root@nccztsjb-node-11 ~]# kubectl get deployment helm-nginx -o yaml | grep -A 6 resources
  2. f:resources:
  3. .: {}
  4. f:limits:
  5. .: {}
  6. f:cpu: {}
  7. f:memory: {}
  8. f:requests:
  9. --
  10. resources:
  11. limits:
  12. cpu: "2"
  13. memory: 2Gi
  14. requests:
  15. cpu: "1"
  16. memory: 1Gi
  17. [root@nccztsjb-node-11 ~]#
  1. [root@nccztsjb-node-11 ~]# kubectl get deployment helm-nginx -o yaml | grep -A 6 livenessProbe
  2. f:livenessProbe:
  3. .: {}
  4. f:failureThreshold: {}
  5. f:periodSeconds: {}
  6. f:successThreshold: {}
  7. f:tcpSocket:
  8. .: {}
  9. --
  10. livenessProbe:
  11. failureThreshold: 6
  12. periodSeconds: 10
  13. successThreshold: 1
  14. tcpSocket:
  15. port: http
  16. timeoutSeconds: 5
  17. [root@nccztsjb-node-11 ~]# kubectl get deployment helm-nginx -o yaml | grep -A 6 readinessProbe
  18. f:readinessProbe:
  19. .: {}
  20. f:failureThreshold: {}
  21. f:initialDelaySeconds: {}
  22. f:periodSeconds: {}
  23. f:successThreshold: {}
  24. f:tcpSocket:
  25. --
  26. readinessProbe:
  27. failureThreshold: 3
  28. initialDelaySeconds: 15
  29. periodSeconds: 5
  30. successThreshold: 1
  31. tcpSocket:
  32. port: http
  33. [root@nccztsjb-node-11 ~]#

通过以上的输出可以看到,通过在安装时指定配置文件已经将pod的资源、健康检查的配置进行了调整为非默认值。

4.9、创建本地的Chart仓库

以上的chart都是通过远程仓库的URL中拉取使用的,那么对于helm来说,也可以使用类似于yum建立本地仓库源一样建立chart的自定义的本地仓库。

方法如下。

4.9.1、部署nginx或者apache服务

此处的目的就是将仓库暴露为http的服务。本例使用nginx作为映射,具体部署的过程不赘述。

4.9.2、映射目录

该目录将作为chart的本地目录

  1. location / {
  2. alias /data/;
  3. autoindex on;
  4. autoindex_format html;
  5. autoindex_exact_size off;
  6. autoindex_localtime on;
  7. }

4.9.3、上传chart包

将4.6中的chart包,或者自己修改的chart包上传到该目录中

  1. [root@node142 repo]# pwd
  2. /data/kubernetes/helm/repo
  3. [root@node142 repo]# ls -l
  4. total 44
  5. -rw-r--r-- 1 root root 38340 Jan 17 11:32 nginx-9.7.1.tgz
  6. -rw-r--r-- 1 root root 4011 Jan 13 16:22 tomcat-0.4.0.tgz
  7. [root@node142 repo]#

4.9.4、创建索引文件

为了能够通过目录找到需要的chart包就需要一个索引文件,通过helm命令创建这个索引文件(注意:文件服务器中也需要安装helm命令)

创建索引文件:

  1. helm repo index /data/kubernetes/helm/repo/ --url http://172.20.56.117/kubernetes/helm/repo

最后面的是具体http访问的url,前面是要在哪个目录中创建索引文件

  1. [root@node142 repo]# helm repo index /data/kubernetes/helm/repo/ --url http://172.20.56.117/kubernetes/helm/repo
  2. [root@node142 repo]# ls
  3. index.yaml nginx-9.7.1.tgz tomcat-0.4.0.tgz
  4. [root@node142 repo]#

OK,索引文件已经创建完成。

4.9.4、使用本地仓库部署chart

将刚建立的仓库添加到helm中

  1. [root@nccztsjb-node-11 ~]# helm repo add local http://172.20.56.117/kubernetes/helm/repo
  2. "local" has been added to your repositories
  3. [root@nccztsjb-node-11 ~]# helm repo list
  4. NAME URL
  5. local http://172.20.56.117/kubernetes/helm/repo
  6. [root@nccztsjb-node-11 ~]#

本地仓库中查找chart

  1. [root@nccztsjb-node-11 ~]# helm search repo nginx
  2. NAME CHART VERSION APP VERSION DESCRIPTION
  3. local/nginx 9.7.1 1.21.5 Chart for the nginx server
  4. [root@nccztsjb-node-11 ~]#

使用本地的仓库进行安装

  1. [root@nccztsjb-node-11 ~]# helm install local-nginx local/nginx
  2. NAME: local-nginx
  3. LAST DEPLOYED: Mon Jan 17 14:13:29 2022
  4. NAMESPACE: default
  5. STATUS: deployed
  6. REVISION: 1
  7. TEST SUITE: None
  8. NOTES:
  9. CHART NAME: nginx
  10. CHART VERSION: 9.7.1
  11. APP VERSION: 1.21.5
  12. ** Please be patient while the chart is being deployed **
  13. NGINX can be accessed through the following DNS name from within your cluster:
  14. local-nginx.default.svc.cluster.local (port 80)
  15. To access NGINX from outside the cluster, follow the steps below:
  16. 1. Get the NGINX URL by running these commands:
  17. NOTE: It may take a few minutes for the LoadBalancer IP to be available.
  18. Watch the status with: 'kubectl get svc --namespace default -w local-nginx'
  19. export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services local-nginx)
  20. export SERVICE_IP=$(kubectl get svc --namespace default local-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
  21. echo "http://${SERVICE_IP}:${SERVICE_PORT}"
  22. [root@nccztsjb-node-11 ~]#

OK,已经可以获取到chart包进行安装。

以上就是helm的安装和基本使用。

k8s的应用包管理工具helm的部署和使用的更多相关文章

  1. Kubernetes-17:Kubernets包管理工具—>Helm介绍与使用

    Kubernets包管理工具->Helm 什么是Helm? 我们都知道,Linux系统各发行版都有自己的包管理工具,比如Centos的YUM,再如Ubuntu的APT. Kubernetes也有 ...

  2. k8s包管理工具helm - 介绍和安装

    目录 1.Kubernetes 应用部署的挑战 2.Helm 是什么 3.Helm 组件及相关术语 4.Helm 工作原理 5.Helm 安装 5.1 客户端安装 5.2 安装服务端 Tiller 5 ...

  3. 云原生之旅 - 5)Kubernetes时代的包管理工具 Helm

    前言 上一篇文章 [基础设施即代码 使用 Terraform 创建 Kubernetes] 教会了你如何在Cloud上面建Kubernetes资源,那么本篇来讲一下如何在Kubernetes上面部署应 ...

  4. Kubernetes的包管理工具Helm的安装和使用

    1.源码安装 [root@master ~]# wget https://storage.googleapis.com/kubernetes-helm/helm-v2.14.0-linux-amd64 ...

  5. kubernetes包管理工具Helm安装

    helm官方建议使用tls,首先生成证书. openssl genrsa -out ca.key.pem openssl req -key ca.key.pem -new -x509 -days -s ...

  6. Helm包管理工具(简介、安装、方法)

    认识Helm 每次我们要部署一个应用都需要写一个配置清单(维护一套yaml文件),但是每个环境又不一样.部署一套新的环境成本是真的很高.如果我们能够使用类似于yum的工具来安装我们的应用的话那就太好了 ...

  7. 使用 Helm 包管理工具简化 Kubernetes 应用部署

    当在 Kubernetes 中已经部署很多应用时,后续需要对每个应用的 yaml 文件进行维护操作,这个过程会变的很繁琐,我们可以使用 Helm 来简化这些工作.Helm 是 Kubernetes 的 ...

  8. ASP.NET Core on K8S深入学习(10)K8S包管理器Helm

    本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章. 一.关于Helm 1.1 为何需要Helm? 虽然K8S能够很好地组织和编排容 ...

  9. Helm:kubernetes应用包管理工具

    概要 Helm:kubernetes应用包管理工具 K8s部署应用的时候,应用会通过yaml描述信息调用K8s-api:Helm即是管理这些Yaml的应用包管理工具 组成 Helm包含5个部分 Hel ...

随机推荐

  1. Oracle 函数高级查询

    目录 oracle高级查询 Oracle SQL获取每个分组中日期最新的一条数据 求平均值(为0的参数不均摊) 字符串清除前面的0 判断字符串串是否包含某个字符串 switch 判断 oracle不足 ...

  2. LuoguP2556 [AHOI2002]黑白图像压缩 题解

    Content 题目描述太过于繁琐而无法简化,请前往原题面查看. 数据范围:\(1\leqslant n\leqslant 8\times 10^4\). Solution & Code 一个 ...

  3. AcWing1341. 十三号星期五

    题目: 十三号星期五真的很不常见吗? 每个月的十三号是星期五的频率是否比一周中的其他几天低? 请编写一个程序,计算 N 年内每个月的 13 号是星期日,星期一,星期二,星期三,星期四,星期五和星期六的 ...

  4. ajaxFileUpload上传文件成功后却无法解析服务器返回的json数据

    可能是应该返回内容带了标签,过滤下 var index=data.indexOf("<"); if (index!=-1){ data=data.substring(0,in ...

  5. 【Android开发】找乐,一个笑话App的制作过程记录

    缘起 想做一个笑话App的原因是因为在知乎上看过一个帖子,做Android可以有哪些数据可以练手,里面推荐了几个数据开放平台.在这些平台中无一不是有公共的笑话接口,当时心想这个可以拿来练手啊,还挺有意 ...

  6. 【LeetCode】231. Power of Two 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二进制 位运算 判断是不是最大2的幂的因数 判断因子 ...

  7. 【LeetCode】930. Binary Subarrays With Sum 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 字典 相似题目 参考资料 日期 题目地址: ...

  8. 【LeetCode】93. Restore IP Addresses 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...

  9. Leapin' Lizards(hdu 2732)

    Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  10. 教学日志:javaSE-面向对象2

    一.局部变量和成员变量 package class4.oop1; /** * @Auther: Yu Panpan * @Date: 2021/12/10 - 12 - 10 - 14:47 * @D ...