Helm 研讀小記
OS: openSUSE Leap 15.4
Helm: 3.11.2
參考官方文件
安裝 helm 的部分, 可以參考之前的文章, 我是用 zypper 進行安裝
搜尋 chart
> helm search hub grafana
hub - 從 Artifact Hub ( https://artifacthub.io/ ) 進行搜尋
grafana - 此次搜尋的套件
> helm search repo grafana
從已經安裝的 repo 來進行搜尋
列出已經安裝到本機的 repo
> helm repo list
列出已經安裝的 release
> helm list
安裝 repo
> helm repo add grafana https://grafana.github.io/helm-charts
更新 helm repo
> helm repo update
取得 Chart 基本資訊
> helm show chart grafana/grafana
顯示所有資訊
> helm show all grafana/grafana
> helm show values grafana/grafana
> helm show values grafana/grafana | egrep -v '#|^$'
> helm install my-release grafana/grafana
NAME: my-release
LAST DEPLOYED: Mon Jun 26 22:00:49 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get your 'admin' user password by running:
kubectl get secret --namespace default my-release-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
2. The Grafana server can be accessed via port 80 on the following DNS name from within your cluster:
my-release-grafana.default.svc.cluster.local
Get the Grafana URL to visit by running these commands in the same shell:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=my-release" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace default port-forward $POD_NAME 3000
3. Login with the password from step 1 and the username: admin
#################################################################################
###### WARNING: Persistence is disabled!!! You will lose your data when #####
###### the Grafana pod is terminated. #####
#################################################################################
之後如果這個訊息忘記了, 可以用以下的指令查詢
> helm status my-release
> kubectl port-forward my-release-grafana-74c6c68658-xzhbv 3000
my-release-grafana-74c6c68658-xzhbv 為 pod 名稱
開啟瀏覽器, 輸入 localhost:3000
使用 admin 登入, 密碼如步驟 1 取得
這個在之前的文章內也有提到了
觀察目前安裝
> helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
my-release default 1 2023-06-26 22:00:49.478280863 +0800 CST deployed grafana-6.57.3 9.5.3
刪除剛剛安裝的 release
> helm delete my-release
release "my-release" uninstalled
因為我們用的是雲端的 Kubernetes 服務, 這次跟上次文章不同之處, 就是我們這次使用 Helm 安裝 Grafana 服務的時候, Service type 要使用 LoadBalancer
先來觀察預設的 value
> helm show values grafana/grafana
# 只擷取 service 的部份
## Expose the grafana service to be accessed from outside the cluster (LoadBalancer service).
## or access it from within the cluster (ClusterIP service). Set the service type and the port to serve it.
## ref: http://kubernetes.io/docs/user-guide/services/
##
service:
enabled: true
type: ClusterIP
port: 80
targetPort: 3000
# targetPort: 4181 To be used with a proxy extraContainer
## Service annotations. Can be templated.
annotations: {}
labels: {}
portName: service
# Adds the appProtocol field to the service. This allows to work with istio protocol selection. Ex: "http" or "tcp"
appProtocol: ""
將以上這段存成 test-values.yaml 然後進行一些修改
檔案內容如下
> cat test-values.yaml
#
service:
enabled: true
type: LoadBalancer
port: 80
targetPort: 3000
# targetPort: 4181 To be used with a proxy extraContainer
## Service annotations. Can be templated.
annotations: {}
labels: {}
portName: service
# Adds the appProtocol field to the service. This allows to work with istio protocol selection. Ex: "http" or "tcp"
appProtocol: ""
### Expose the grafana service to be accessed from outside the cluster (LoadBalancer service).
## or access it from within the cluster (ClusterIP service). Set the service type and the port to serve it.
## ref: http://kubernetes.io/docs/user-guide/services/
##
#service:
# enabled: true
# type: ClusterIP
# port: 80
# targetPort: 3000
# # targetPort: 4181 To be used with a proxy extraContainer
# ## Service annotations. Can be templated.
# annotations: {}
# labels: {}
# portName: service
# # Adds the appProtocol field to the service. This allows to work with istio protocol selection. Ex: "http" or "tcp"
# appProtocol: ""
這邊就是將原來的 value 部份, type 改為 LoadBalancer
再次進行安裝
> helm install my-release grafana/grafana -f test-values.yaml
這次加上我們剛剛修改的 test-values.yaml
安裝完畢之後, 可以觀察 services
> kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 9d
my-release-grafana LoadBalancer 10.0.8.152 20.237.74.66 80:30561/TCP 32m
然後可以直接連線 外部 IP, 就可以存取到 Grafana
另外可以藉由 get values 來進行觀察
> helm get values my-release
USER-SUPPLIED VALUES:
service:
annotations: {}
appProtocol: ""
enabled: true
labels: {}
port: 80
portName: service
targetPort: 3000
type: LoadBalancer
實驗完畢, 刪除 release
> helm delete my-release
release "my-release" uninstalled
這樣可以藉由 values.yaml 將自己想要進行的改變, 進行更動
又向 helm 與 kubernetes 更進一步
~ enjoy it
References
沒有留言:
張貼留言