1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Helmをインストールして動作を確認する

Last updated at Posted at 2020-08-05

はじめに

Helmは「The package manager for Kubernetes」ということで、Kubernetesのパッケージマネージメントツールです。RH系のyumみたいなものですね。
通常Kubernetesで何らかのサービスをデプロイする場合は、Podをデプロイして、その設定情報をConfigMapやSecretで用意し、クラスタ外に通信するためのServiceをデプロイしたりします。Helmを使うとこれらをまとめてデプロイしてくれることになります。

今回はこのHelmをインストールしてパッケージをHelmからデプロイしてみたいと思います。

Helmのインストール

以下に沿ってインストールします。
https://helm.sh/ja/docs/intro/install/

インストールスクリプトのダウンロードと実行

$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh
Error: could not find tiller
Helm v3.2.4 is available. Changing from version .
Downloading https://get.helm.sh/helm-v3.2.4-linux-amd64.tar.gz
Preparing to install helm into /usr/local/bin
helm installed into /usr/local/bin/helm

Helm Ver.3からはTillerが不要になったのですが、Tillerが見つからないとエラーが出ています。
インストールはできているようなので、無視して先に進みます。

バージョンを確認します。

$ helm version
version.BuildInfo{Version:"v3.2.4", GitCommit:"0ad800ef43d3b826f31a5ad8dfbb4fe05d143688", GitTreeState:"clean", GoVersion:"go1.13.12"}

リポジトリとパッケージの検索

Helmではパッケージのことを「Chart」と呼びます。helmコマンドを使って、パッケージを検索してみます。

パッケージの検索

helm search hubコマンドでHelm Hubを検索します。

$ helm search hub wordpress
URL                                                     CHART VERSION   APP VERSION     DESCRIPTION
https://hub.helm.sh/charts/bitnami/wordpress            9.4.0           5.4.2           Web publishing platform for building blogs and ...
https://hub.helm.sh/charts/presslabs/wordpress-...      0.10.2          0.10.2          Presslabs WordPress Operator Helm Chart
https://hub.helm.sh/charts/presslabs/wordpress-...      v0.10.0         v0.10.0         A Helm chart for deploying a WordPress site on ...

ローカルリポジトリの追加

初期状態ではリポジトリが何も設定されていないので、ローカル環境にリポジトリを追加します。

$ helm repo list
Error: no repositories to show
$ helm repo add stable https://kubernetes-charts.storage.googleapis.com/
"stable" has been added to your repositories
$ helm repo list
NAME    URL
stable  https://kubernetes-charts.storage.googleapis.com/

helm search repoコマンドでローカルリポジトリを検索します。

$ helm search repo wordpress
NAME                    CHART VERSION   APP VERSION     DESCRIPTION
stable/wordpress        9.0.3           5.3.2           DEPRECATED Web publishing platform for building...

パッケージのインストール

wordpress

インストールの準備ができましたので、リポジトリからパッケージをインストールします。

$ helm install wordpress stable/wordpress
WARNING: This chart is deprecated
NAME: wordpress
LAST DEPLOYED: Tue Aug  4 21:57:54 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
This Helm chart is deprecated

・・・

To access your WordPress site from outside the cluster follow the steps below:

1. Get the WordPress URL by running these commands:

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace default -w wordpress'

   export SERVICE_IP=$(kubectl get svc --namespace default wordpress --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
   echo "WordPress URL: http://$SERVICE_IP/"
   echo "WordPress Admin URL: http://$SERVICE_IP/admin"

2. Open a browser and access WordPress using the obtained URL.

3. Login with the following credentials below to see your blog:

  echo Username: user
  echo Password: $(kubectl get secret --namespace default wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode

インストール後のアクセス方法なども出力されますね。

helm listでStatusなどが確認できます。

$ helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
wordpress       default         1               2020-08-04 21:57:54.573193726 +0900 JST deployed        wordpress-9.0.3 5.3.2

Kubernetesのリソース確認

kubectlコマンドでKubernetesリソースを確認します。

$ kubectl get pod | grep word
wordpress-5667d74df4-bdkmm   0/1     Pending   0          4m44s
wordpress-mariadb-0          0/1     Pending   0          4m44s
$ kubectl get svc | grep word
wordpress           LoadBalancer   10.110.221.143   10.20.30.151   80:30801/TCP,443:32703/TCP   4m55s
wordpress-mariadb   ClusterIP      10.105.56.50     <none>         3306/TCP                     4m55s

PodとServiceが2つずつデプロイされていますね。ただ、PodはPending状態です。

Podの詳細を確認します。

$ kubectl describe pod wordpress-mariadb-0
Name:           wordpress-mariadb-0
Namespace:      default
・・・
Events:
  Type     Reason            Age                  From               Message
  ----     ------            ----                 ----               -------
  Warning  FailedScheduling  69s (x3 over 2m39s)  default-scheduler  running "VolumeBinding" filter plugin for pod "wordpress-mariadb-0": pod has unbound immediate PersistentVolumeClaims

PVがClaimできてないようです。もう一つのPodも同じ状態でした。

PVCまではパッケージングされていますが、PVは事前に用意しておかないといけないようですね。

$ kubectl get pvc
NAME                       STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
data-wordpress-mariadb-0   Pending                                                     6m
wordpress                  Pending                                                     6m

nginx

事前準備がいらなさそうなものとしてnginxをインストールしてみます。

リポジトリを追加してからインストールします。

$  helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
$ helm repo list
NAME    URL
stable  https://kubernetes-charts.storage.googleapis.com/
bitnami https://charts.bitnami.com/bitnami
$ helm install nginx-helm bitnami/nginx
NAME: nginx-helm
LAST DEPLOYED: Tue Aug  4 22:18:07 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Get the NGINX URL:

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace default -w nginx-helm'

  export SERVICE_IP=$(kubectl get svc --namespace default nginx-helm --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
  echo "NGINX URL: http://$SERVICE_IP/"

Kubernetesのリソース確認

同様にリソースを確認します。

$ kubectl get pod nginx-helm-5bc5bb68b9-5g8nh
NAME                          READY   STATUS    RESTARTS   AGE
nginx-helm-5bc5bb68b9-5g8nh   1/1     Running   0          60s
$ kubectl get svc nginx-helm
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)                      AGE
nginx-helm   LoadBalancer   10.100.171.112   10.20.30.152   80:31116/TCP,443:31492/TCP   12m

PodとServiceが一つずつデプロイされています。

疎通も確認します。

$ curl -s 10.20.30.152:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
・・・

まとめ

マニフェストファイルを用意しないで、コマンド一発でPodとServiceなどをデプロイしてくれるのは便利ですね。
ただ、全てのパッケージがHelmだけでデプロイできる訳ではなく、事前準備が必要なものもあるということがわかりました。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?