Docker for Mac で helm v3.1 を動かす
Docker for Mac で helm v3.1 を動かす
update: 2020/8/29
この記事は、Docker for Mac で helm v3.1 を動かした手順を説明します。
以下の記事を参考に稼働させた結果です。
- 参考にした記事
確認したこと
環境
- macOS Catalina 10.15.6
- メモリ: 8GB
- Docker for Mac Ver 2.2.0.4
- Engine 19.03.12
- Kubernetes v1.16.5
手順の概要
- helm のインストールとセットアップ
- Jenkins のインストール, 動作確認、アンインストール
- Prometheus のインストール、動作確認
- Grafana のインストール、Prometheus との連携
1.helm のインストールとセットアップ
helm のインストール Homebrew でインストールします。Homebrew 自体のインストールは、以下を参照してください。
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" $ brew -v Homebrew 2.2.9 Homebrew/homebrew-core (git revision 257bb; last commit 2020-03-06)
以下のコマンドラインでhelm をインストールします。
$ brew install kubernetes-helm Updating Homebrew... ==> Auto-updated Homebrew! Updated 1 tap (homebrew/core). ==> New Formulae ...<略> ==> Downloading https://homebrew.bintray.com/bottles/helm-3.1.1.catalina.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/28/28fe58e7c52754887d08a060a86ec6df03b0774e6c02eed63f6fa20 ######################################################################## 100.0% ==> Pouring helm-3.1.1.catalina.bottle.tar.gz ==> Caveats Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completions have been installed to: /usr/local/share/zsh/site-functions ==> Summary ? /usr/local/Cellar/helm/3.1.1: 7 files, 41.2MB $ helm version version.BuildInfo{Version:"v3.1.1", GitCommit:"afe70585407b420d0097d07b21c47dc511525ac8", GitTreeState:"clean", GoVersion:"go1.13.8"}
Chart リポジトリの追加 helm chart を使用するためのリポジトリを追加します
$ helm repo add stable https://kubernetes-charts.storage.googleapis.com/ "stable" has been added to your repositories $ helm search repo stable NAME CHART VERSION APP VERSION DESCRIPTION ... stable/jenkins 1.9.21 lts Open source continuous integration server. It s... stable/prometheus 11.0.2 2.16.0 Prometheus is a monitoring system and time seri...
2.Jenkins のインストール, 動作確認、アンインストール
- Jenkins のインストール
$ helm install my-jenkins stable/jenkins NAME: my-jenkins LAST DEPLOYED: Sat Mar 7 17:17:03 2020 NAMESPACE: default STATUS: deployed REVISION: 1 NOTES: 1. Get your 'admin' user password by running: printf $(kubectl get secret --namespace default my-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo 2. Get the Jenkins URL to visit by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/component=jenkins-master" -l "app.kubernetes.io/instance=my-jenkins" -o jsonpath="{.items[0].metadata.name}") echo http://127.0.0.1:8080 kubectl --namespace default port-forward $POD_NAME 8080:8080 3. Login with the password from step 1 and the username: admin For more information on running Jenkins on Kubernetes, visit: https://cloud.google.com/solutions/jenkins-on-container-engine
- 動作確認
- 上記の出力にある、1と2 のコマンドラインをそのまま実行する
- 実行後、ブラウザで
http://localhost:8080
でJenkins が開く
$ printf $(kubectl get secret --namespace default my-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo (adminのパスワードが表示される) $ export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/component=jenkins-master" -l "app.kubernetes.io/instance=my-jenkins" -o jsonpath="{.items[0].metadata.name}") $ echo http://127.0.0.1:8080 $ kubectl --namespace default port-forward $POD_NAME 8080:8080
- Jenkins の削除
$ helm ls NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION my-jenkins default 1 2020-03-07 17:17:03.662622 +0900 JST deployed jenkins-1.9.21 lts $ helm delete my-jenkins release "my-jenkins" uninstalled $ helm ls NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
3.Prometheus のインストール、動作確認
- 監視用のnamespace 作成
$ kubectl create ns monitoring
- Prometheus のインストール
$ helm install my-prometheus --namespace monitoring stable/prometheus NAME: my-prometheus LAST DEPLOYED: Sat Aug 29 12:50:08 2020 NAMESPACE: monitoring STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster: my-prometheus-server.monitoring.svc.cluster.local Get the Prometheus server URL by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace monitoring port-forward $POD_NAME 9090 The Prometheus alertmanager can be accessed via port 80 on the following DNS name from within your cluster: my-prometheus-alertmanager.monitoring.svc.cluster.local Get the Alertmanager URL by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=alertmanager" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace monitoring port-forward $POD_NAME 9093 ################################################################################# ###### WARNING: Pod Security Policy has been moved to a global property. ##### ###### use .Values.podSecurityPolicy.enabled with pod-based ##### ###### annotations ##### ###### (e.g. .Values.nodeExporter.podSecurityPolicy.annotations) ##### ################################################################################# The Prometheus PushGateway can be accessed via port 9091 on the following DNS name from within your cluster: my-prometheus-pushgateway.monitoring.svc.cluster.local Get the PushGateway URL by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=pushgateway" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace monitoring port-forward $POD_NAME 9091 For more information on running Prometheus, visit: https://prometheus.io/
- 動作確認
- 上記の出力にある、
Get the Prometheus server URL by running these commands in the same shell:
をそのまま実行する - 実行後、ブラウザで
http://localhost:9090
でPrometheus が開く
- 上記の出力にある、
$ export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}") $ kubectl --namespace default port-forward $POD_NAME 9090
4. Grafana のインストール、Prometheus との連携
- Grafana のインストール
$ helm install my-grafana --namespace monitoring stable/grafana NAME: my-grafana LAST DEPLOYED: Sat Aug 29 12:55:03 2020 NAMESPACE: monitoring STATUS: deployed REVISION: 1 NOTES: 1. Get your 'admin' user password by running: kubectl get secret --namespace monitoring my-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-grafana.monitoring.svc.cluster.local Get the Grafana URL to visit by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=grafana,release=my-grafana" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace monitoring 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. ##### #################################################################################
Get the Grafana URL to visit by running these commands in the same shell
に記載されている、Admin アカウントのパスワード取得とGrafana UI の起動を行う
- Admin アカウントのパスワード取得
$ kubectl get secret --namespace monitoring my-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
表示されるワードを覚えておく
- Grafana UI の起動
$ export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=grafana,release=my-grafana" -o jsonpath="{.items[0].metadata.name}") $ kubectl --namespace monitoring port-forward $POD_NAME 3000
POD_NAME
取得で以下のエラーとなった
error: error executing jsonpath "{.items[0].metadata.name}": Error executing template: array index out of bounds: index 0, length 0. Printing more information for debugging the template: template was: {.items[0].metadata.name} object given to jsonpath engine was: map[string]interface {}{"apiVersion":"v1", "items":[]interface {}{}, "kind":"List", "metadata":map[string]interface {}{"resourceVersion":"", "selfLink":""}}
このため、GrafanaのPod名を以下で調べる
$ kubectl get pods --namespace monitoring NAME READY STATUS RESTARTS AGE my-grafana-7bf85bb57c-xt4jq 1/1 Running 0 11m my-prometheus-alertmanager-5867bc9cb-b57pw 2/2 Running 0 16m my-prometheus-kube-state-metrics-78fcdfc68c-sl5vk 1/1 Running 0 16m my-prometheus-node-exporter-r4k6j 1/1 Running 0 16m my-prometheus-pushgateway-6c6945ccc7-vf5cp 1/1 Running 0 16m my-prometheus-server-f78799785-rnt2z 2/2 Running 0 16m
以下でGrafana UIを起動する
$ kubectl --namespace monitoring port-forward my-grafana-7bf85bb57c-xt4jq 3000
実行後、ブラウザで http://localhost:3000
でGrafana が開く
- Promethues との連携は、以下の記事をそのまま実施する
- MinikubeにPrometheusとGrafanaをHelmチャートでデプロイする
- この記事は、Minikube 向けであるが、連携部分はそのまま使える
- 若干、バージョンが異なるため利用方法が異なっているが、よく見ると対応可能