# About Helm Helm 是 Kubernetes 的包管理器 # Quick start ### 1. env * 有一座 k8s cluster * Helm和k8s 版本有沒有支援 * k8s 上裝 helm ### 2. Installation 官方文件對應 os 可參考 : https://helm.sh/zh/docs/intro/install/ ``` $ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 $ chmod 700 get_helm.sh $ ./get_helm.sh ``` Helm安裝後,要 helm 增加一個chart repository。從 Artifact Hub中查找有效的Helm chartrepository ``` $ helm repo add bitnami https://charts.bitnami.com/bitnami ``` 安装的charts列表: ``` $ helm search repo bitnami NAME CHART VERSION APP VERSION DESCRIPTION bitnami/bitnami-common 0.0.9 0.0.9 DEPRECATED Chart with custom templates used in ... bitnami/airflow 8.0.2 2.0.0 Apache Airflow is a platform to programmaticall... bitnami/apache 8.2.3 2.4.46 Chart for Apache HTTP Server bitnami/aspnet-core 1.2.3 3.1.9 ASP.NET Core is an open-source framework create... # ... and many more ``` # Helm 使用 ### 什麼是 Chart ? cahrt 就一個Helm 標準安裝包,它包含在k8s叢集內部運行應用成是套件。相對於是MacOS 的 Homebrew ,Formula,Ubuntu/Debium 的 Apt dpkg,或Rathat/CentOS 的 Yum RPM 套件管理工具。 ### 安裝 Chart : helm install 使用 helm install 安装 chart ``` $ helm repo update # 确定我们可以拿到最新的charts列表 $ helm install bitnami/mysql --generate-name NAME: mysql-1612624192 LAST DEPLOYED: Sat Feb 6 16:09:56 2021 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None ``` * k8s 上 透過helm 安裝 example: ``` helm install --namespace=default --timeout=10m0s --values=/home/shell/helm/values-k8s-monitoring-0.6.2.yaml --version=0.6.2 --wait=true k8s-monitoring /home/shell/helm/k8s-monitoring-0.6.2.tgz ``` ### 查詢版本 : helm list ``` $ helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION mysql-1612624192 default 1 2021-02-06 16:09:56.283059 +0100 CET deployed mysql-8.3.0 8.0.23 ``` ### 搜尋套件 : helm search * Helm自帶了一個強大的搜尋指令,可以用於從兩種來源進行搜尋: * helm search hub * 從 Artifact Hub 中尋找 helm cart。 Artifact Hub 中存放了大量不同的倉庫。 * helm search repo * 從您新增(使用 helm repo add)到本地 helm 用戶端中的倉庫中進行查找。 ``` $ helm search hub wordpress URL CHART VERSION APP VERSION DESCRIPTION https://hub.helm.sh/charts/bitnami/wordpress 7.6.7 5.2.4 Web publishing platform for building blogs and ... https://hub.helm.sh/charts/presslabs/wordpress-... v0.6.3 v0.6.3 Presslabs WordPress Operator Helm Chart https://hub.helm.sh/charts/presslabs/wordpress-... v0.7.1 v0.7.1 A Helm chart for deploying a WordPress site on ... ``` ### 解安裝 : helm uninstall ``` $ helm uninstall mysql-1612624192 release "mysql-1612624192" uninstalled ``` ## helm cahrt 安裝過程 你會看見 helm 患產生很多安裝訊息,其中包括:哪些資源已經被創建,釋放當前的狀態,以及您是否還需要執行額外的設定步驟。 Helm 依照以下順序安裝資源: Namespace, NetworkPolicy, ResourceQuota, LimitRange, PodSecurityPolicy, PodDisruptionBudget, ServiceAccount, Secret, SecretList, ConfigMap, StorageClass, PersistentVolume, PersistentVolumeClaim, CustomResourceDefinition, ClusterRole, ClusterRoleList, ClusterRoleBinding, ClusterRoleBindingList, Role, RoleList, RoleBinding, RoleBindingList, DaemonSet, Pod, ReplicationController, ReplicaSet, Deployment, HorizontalPodAutoscaler, StatefulSet, Job, CronJob, Ingress, APIService ### 追蹤helm 狀態 :helm status 因為有些helm 需要抓把叫大的 image,安裝時間很長,可以用指令去追蹤狀況 ### 查看chart的配置選項: helm show values 可以使用 YAML 格式的文件覆盖上述任意配置项,用來客製化自己的 helm * 安裝過程有兩種方式交付設定資料: * --values (或 -f):使用 YAML 檔案覆蓋設定。可以指定多個,優先使用最右邊的檔案。 * --set:透過命令列的方式對指定項進行覆蓋。 ``` $ echo '{mariadb.auth.database: user0db, mariadb.auth.username: user0}' > values.yaml $ helm install -f values.yaml bitnami/wordpress --generate-name ``` ## 創建 cahrt :helm create ``` $ helm create deis-workflow Creating deis-workflow ``` ### rollback 安裝版本 在helm 安裝過程中,發生了不符合預期的事情,也很容易通過 helm rollback [RELEASE] [REVISION] 命令回滾到之前的發布版本。 `$ helm rollback happy-panda 1` ### Chart.yaml 文件 ![image](https://hackmd.io/_uploads/r17ddtaUp.png) ![image](https://hackmd.io/_uploads/SJyiOtaLp.png) Chart.yaml格式結構意義: ![image](https://hackmd.io/_uploads/HyfJtKa8a.png)