Gần đây team Devops chúng tôi chuyển sang helm để deployment ứng dụng trên kubernetes(lạc hậu nhễ anh em devops khác đã dùng khá lâu).
Trong quá trình dùng thì khá là đơn giản, trước tiên bạn vào trang https://helm.sh/ để chọn phiên bản helm 3 hoặc helm 2, nhưng tôi khuyên bạn nên chọn helm 3 để có những tính năng mới nhất.
Sau khi cài đặt thành công, thì bạn có thể dùng một charts phổ biến từ cộng đồng https://github.com/helm/charts
$ helm repo add stable https://kubernetes-charts.storage.googleapis.com "stable" has been added to your repositories
Nó hỗ trợ gần như hầu hết các ứng dụng của bạn, ví dụ như database mysql, mongodb,
Cho log, monitor thì có grafana, prometheus, hoặc bạn có thể chạy lệnh này để tiềm kiếm ứng dụng
helm search repo prometheus NAME CHART VERSION APP VERSION DESCRIPTION stable/prometheus 11.3.0 2.18.1 Prometheus is a monitoring system and time seri... stable/prometheus-adapter 2.3.1 v0.6.0 A Helm chart for k8s prometheus adapter stable/prometheus-blackbox-exporter 4.1.0 0.16.0 Prometheus Blackbox Exporter stable/prometheus-cloudwatch-exporter 0.8.0 0.8.0 A Helm chart for prometheus cloudwatch-exporter stable/prometheus-consul-exporter 0.1.4 0.4.0 A Helm chart for the Prometheus Consul Exporter stable/prometheus-couchdb-exporter 0.1.1 1.0 A Helm chart to export the metrics from couchdb... stable/prometheus-mongodb-exporter 2.5.0 v0.10.0 A Prometheus exporter for MongoDB metrics stable/prometheus-mysql-exporter 0.5.2 v0.11.0 A Helm chart for prometheus mysql exporter with... stable/prometheus-nats-exporter 2.5.0 0.6.2 A Helm chart for prometheus-nats-exporter stable/prometheus-node-exporter 1.9.1 0.18.1 A Helm chart for prometheus node-exporter stable/prometheus-operator 8.13.8 0.38.1 Provides easy monitoring definitions for Kubern... stable/prometheus-postgres-exporter 1.3.0 0.8.0 A Helm chart for prometheus postgres-exporter stable/prometheus-pushgateway 1.4.0 1.2.0 A Helm chart for prometheus pushgateway stable/prometheus-rabbitmq-exporter 0.5.5 v0.29.0 Rabbitmq metrics exporter for prometheus stable/prometheus-redis-exporter 3.4.0 1.3.4 Prometheus exporter for Redis metrics stable/prometheus-snmp-exporter 0.0.5 0.14.0 Prometheus SNMP Exporter stable/prometheus-to-sd 0.3.0 0.5.2 Scrape metrics stored in prometheus format and ... stable/elasticsearch-exporter 3.3.0 1.1.0 Elasticsearch stats exporter for Prometheus stable/helm-exporter 0.3.3 0.4.0 DEPRECATED Exports helm release stats to promet... stable/karma 1.5.1 v0.60 A Helm chart for Karma - an UI for Prometheus A... stable/stackdriver-exporter 1.2.2 0.6.0 Stackdriver exporter for Prometheus stable/weave-cloud 0.3.7 1.4.0 Weave Cloud is a add-on to Kubernetes which pro... stable/kube-state-metrics 2.8.5 1.9.6 Install kube-state-metrics to generate and expo... stable/kuberhealthy 1.2.6 v1.0.2 The official Helm chart for Kuberhealthy. stable/mariadb 7.3.14 10.3.22 DEPRECATED Fast, reliable, scalable, and easy t...
Để cài đặt một chart chỉ cần chạy lệnh sau, ví dụ cài đặt prometheus để monitor các resource trên kube:
helm upgrade prometheus --install -f values.yaml stable/prometheus
Trong đó giá trị file value bạn có thể lấy từ https://github.com/helm/charts/blob/master/stable/prometheus/values.yaml
Mọi thứ đều OK, nhưng khi trong team của tôi có một bạn change value và re-deploy lại prometheus, thì bị lỗi sau một hồi debug thì biết vấn đề nằm ở chỗ trên máy của bạn team tôi thì helm nó tải về phiên bản prometheus, còn máy của tôi lại là phiên bản khác, do đó chúng tôi khuyên các bạn nên set cứng version khi deploy helm như sau
helm upgrade prometheus --install -f values.yaml stable/prometheus --version 11.3.0
Mục lục
Cách thức hoạt động helm
Sau khi bạn chạy lệnh ở trên thì toàn bộ charts sẽ lưu thông qua một file yaml
cat ~/.helm/repository/cache/stable-index.yaml apiVersion: v1 entries: acs-engine-autoscaler: - apiVersion: v1 appVersion: 2.1.1 created: 2020-04-15T06:29:24.612865102Z deprecated: true description: DEPRECATED Scales worker nodes within agent pools digest: 93f924d4498d588bcdda88c7401e27c6fa0f50ff0601e78885eca13eb683c1e2 home: https://github.com/wbuchwalter/Kubernetes-acs-engine-autoscaler icon: https://github.com/kubernetes/kubernetes/blob/master/logo/logo.png name: acs-engine-autoscaler sources: - https://github.com/wbuchwalter/Kubernetes-acs-engine-autoscaler urls: - https://kubernetes-charts.storage.googleapis.com/acs-engine-autoscaler-2.2.2.tgz version: 2.2.2 - apiVersion: v1 appVersion: 2.1.1 created: 2018-12-11T02:55:17.96986758Z description: Scales worker nodes within agent pools digest: 3232999ebabc42cd7c5475251b5cd2e0c6bf4363551cff13ebe3a78cee1dfba6 home: https://github.com/wbuchwalter/Kubernetes-acs-engine-autoscaler icon: https://github.com/kubernetes/kubernetes/blob/master/logo/logo.png maintainers: - email: [email protected] name: ritazh - email: [email protected] name: wbuchwalter name: acs-engine-autoscaler
Do tôi và đồng nghiệp của tôi chạy lệnh đó không cùng một thời điểm, nên dẫn đến cái file yaml đó trên 2 máy của chúng tôi khác nhau, dẫn đến khi deploy thì helm sẽ vào đó lấy phiên bản tương ứng cài đặt, nên dẫn đến ứng dụng sẽ bị break
Do đó tuyệt đối khi deploy thì bạn luôn luôn thêm tuỳ chọn –version, đó là đều bắt buộc.
Kết Luận
Trên đây là một tip chúng tôi thường dùng với helm, ngoài ra khi làm với helm thì chúng ta sẽ xây dựng một chart riêng cho các dự án cụ thể, trong bài viết sau chúng tôi sẽ chia sẽ kinh nghiệm triển khai nó với các bạn, như mọi khi nếu bạn thấy bài viết hay hãy chia sẽ cho đồng nghiệp của bạn^^