helm3.0で導入が少し変わったっぽい? kindでhelmを触ってみた記事。
helm3.0はtillerlessになったみたいで、cluster-admin権限がいらないっぽい。tillerが導入の障壁になっているのは世界レベルだったらしい。
リンク
GitHub - helm/helm: The Kubernetes Package Manager GitHub - kubernetes-sigs/kind: Kubernetes IN Docker - local clusters for testing Kubernetes
本記事のゴール
kindで作成したk8sクラスタにhelm3.0でprometheusをdeployし、 web accessを行う
kindのインストールとクラスター作成
goが必要なのでgoを何らかの手順でインストールしておく。
kindをインストールしてPATHを通す
go get sigs.k8s.io/kind export PATH=$PATH:$(go env GOPATH)/bin
kindクラスタを作成する。control-plane1とworker2構成にする。
cat << 'EOL' > config.yaml kind: Cluster apiVersion: kind.sigs.k8s.io/v1alpha3 nodes: - role: control-plane - role: worker - role: worker EOL kind create cluster --name kind --config config.yaml
こんな感じで作成できる。
$ cat << 'EOL' > config.yaml kind: Cluster apiVersion: kind.sigs.k8s.io/v1alpha3 nodes: - role: control-plane - role: worker - role: worker EOL kind create cluster --name kind --config config.yaml Creating cluster "kind" ... ✓ Ensuring node image (kindest/node:v1.17.0) 🖼 ✓ Preparing nodes 📦 📦 📦 ✓ Writing configuration 📜 ✓ Starting control-plane 🕹️ ✓ Installing CNI 🔌 ✓ Installing StorageClass 💾 ✓ Joining worker nodes 🚜 Set kubectl context to "kind-kind" You can now use your cluster with: kubectl cluster-info --context kind-kind Have a nice day! 👋
Have a nice day! 👋
ということで kubectl cluster-info --context kind-kind
で情報を見てみる。
$ kubectl cluster-info --context kind-kind Kubernetes master is running at https://127.0.0.1:32771 KubeDNS is running at https://127.0.0.1:32771/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
問題なさそう。 kubectl config use-context kind-kind
でdefault contextに設定しておく。
$ kubectl config use-context kind-kind Switched to context "kind-kind".
helm のインストール
https://github.com/helm/helm#install を参考にインストールする。
completionを設定して補完できるようにする
bash
eval "$(helm completion bash)"
zsh
eval "$(helm completion zsh)"
3.0から? stable repoを追加しないと、stable チャートのインストールを行うことができない。
repoを追加する。
helm repo add stable https://kubernetes-charts.storage.googleapis.com/
ここまですればstableチャートを利用できるようになる。
helmを使ってチャートをインストールする
公式のhubに登録されているチャートを使う場合、 helm search hub
もしくは、 https://hub.helm.sh/ でチャートを検索できる。
試しに prometheus をdeployしてみる。
$ helm install prometheus stable/prometheus NAME: prometheus LAST DEPLOYED: Wed Jan 1 19:31:44 2020 NAMESPACE: default 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: prometheus-server.default.svc.cluster.local Get the Prometheus server URL by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace default -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace default port-forward $POD_NAME 9090 The Prometheus alertmanager can be accessed via port 80 on the following DNS name from within your cluster: prometheus-alertmanager.default.svc.cluster.local Get the Alertmanager URL by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace default -l "app=prometheus,component=alertmanager" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace default 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: prometheus-pushgateway.default.svc.cluster.local Get the PushGateway URL by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace default -l "app=prometheus,component=pushgateway" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace default port-forward $POD_NAME 9091 For more information on running Prometheus, visit: https://prometheus.io/
helm listで中身を確認する
$ helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION prometheus default 1 2020-01-01 19:31:44.862178 +0900 JST deployed prometheus-9.7.2 2.13.1
podを確認する
$ kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES prometheus-alertmanager-7b77498bcc-svsm8 2/2 Running 0 99s 10.244.2.5 kind-worker2 <none> <none> prometheus-kube-state-metrics-5b6475ddb8-8nccn 1/1 Running 0 99s 10.244.2.3 kind-worker2 <none> <none> prometheus-node-exporter-99dqr 1/1 Running 0 99s 172.17.0.6 kind-worker <none> <none> prometheus-node-exporter-rtb7n 1/1 Running 0 99s 172.17.0.5 kind-worker2 <none> <none> prometheus-pushgateway-6f657b989d-mg82b 1/1 Running 0 99s 10.244.1.3 kind-worker <none> <none> prometheus-server-6cb74f95df-nh2bn 2/2 Running 0 99s 10.244.1.5 kind-worker <none> <none>
無事にインストールできたっぽい。
prometheusにアクセスしてみる。
shellで、port-forwardの設定を行う
$ export POD_NAME=$(kubectl get pods --namespace default -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace default port-forward $POD_NAME 9090 Forwarding from 127.0.0.1:9090 -> 9090 Forwarding from [::1]:9090 -> 9090
ブラウザで、 https://localhost:9090/ にアクセスする。
無事にアクセスが確認できた。
手軽にkubernetesのマルチノードなクラスタを作成し、その上でアプリの開発や動作確認が手軽に行えるのはとてもいいなと感じた。 また、 helmの運用でコストに感じていたtiller関係がなくなったことで、 helmに対する精神的なストレスもなくなり、利用者も増えそうな気がする。