Helm使用ガイド
    • PDF

    Helm使用ガイド

    • PDF

    Article Summary

    Classic環境で利用できます。

    Helmは、kubernetes Package Managerで、クライアントであるHelmとcluster内にインストールされるtillerサーバで構成されています。

    このガイドはHelmv2を基準に作成しております。

    Helmインストール

    Helmを使用するためには、kubectlのインストールとkubeconfig設定が先行されなければなりません。

    HelmインストールはOS Platformに合わせて次ページの案内に従って行われます。

    • https://v2.helm.sh/docs/using_helm/#installing-helm

    例示: macOS

    $ brew install helm@2
    

    Helmを使用するためにはtillerの配布を実行する必要がありますが、配布前にtillerのclusterrolebinding権限を与える前にtillerのclusterrolebinding権限を与える必要があります。

    Cluster role binding 追加

    $ kubectl --kubeconfig=$KUBE_CONFIG create clusterrolebinding tiller-cluster-admin \
    --clusterrole=cluster-admin \
    --serviceaccount=kube-system:default
    
    clusterrolebinding.rbac.authorization.k8s.io/tiller-cluster-admin created
    

    cluster rolebinding権限を追加した後、Helm初期化でtillerを配布します。

    Helm 初期化

    $ helm --kubeconfig=$KUBE_CONFIG init
    ...
    
    Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.
    
    Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
    To prevent this, run `helm init` with the --tiller-tls-verify flag.
    For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation
    Happy Helming!
    

    初期化コマンドの実行後、tiller-deploy Podが配布完了することを確認でき、STATUSがRunning状態であればHelmを使用できる状態になります。

    tiller-deploy podを確認する

    $ kubectl --kubeconfig=$KUBE_CONFIG get pods -n kube-system -w
    NAME                                            READY   STATUS    RESTARTS   AGE
    ...
    tiller-deploy-845cffcd48-llds2                  1/1     Running   0          18h
    ...
    

    HelmでNFS Client ProvisionerをインストールしてNASを連動する

    参考

    Helmv3は下記リンクのガイドをご参照ください。

    クラスタには基本的にBlockStorage CSIがインストールされているので、Storage Classも自動的に生成されますが、
    Helm nfs-client-provisioner chartを利用して、NASを連動させたStorage Classを作成することもできます。
    まずNASからNFSプロトコルへのボリューム生成が必要です。

    参考

    NAS作成の際、クラスター内のワーカーノードサーバーをACLにすべて登録する必要があります。

    NASボリュームが生成されれば、マウント情報のIPおよびPATH情報を確認します。

    IPとPATH情報は、Helm chartをインストールする際に設定値として使用されます。

    예시

    • __NAS_IP__: 10.250.48.16
    • __NAS_PATH__: /n000075_nkstest3

    nfs-client-provisioner をインストールする

    次のコマンドの__NAS_IP____NAS_PATH__の値は上記の例を参考に設定値を指定します。

    $ helm --kubeconfig=$KUBE_CONFIG --name storage install stable/nfs-client-provisioner \
    --set nfs.server=__NAS_IP__ \
    --set nfs.path=__NAS_PATH__
    
    NAME:   storage
    LAST DEPLOYED: Tue Feb 19 16:56:50 2019
    NAMESPACE: default
    STATUS: DEPLOYED
    
    RESOURCES:
    ==> v1/ClusterRole
    NAME                                   AGE
    storage-nfs-client-provisioner-runner  1s
    
    ==> v1/ClusterRoleBinding
    run-storage-nfs-client-provisioner  0s
    
    ==> v1/Role
    leader-locking-storage-nfs-client-provisioner  0s
    
    ==> v1/RoleBinding
    leader-locking-storage-nfs-client-provisioner  0s
    
    ==> v1/Deployment
    storage-nfs-client-provisioner  0s
    
    ==> v1/Pod(related)
    
    NAME                                             READY  STATUS             RESTARTS  AGE
    storage-nfs-client-provisioner-6f4b47749d-x9cn2  0/1    ContainerCreating  0         0s
    
    ==> v1/StorageClass
    
    NAME        AGE
    nfs-client  1s
    
    ==> v1/ServiceAccount
    storage-nfs-client-provisioner  1s
    

    Storage classを確認する

    $ kubectl --kubeconfig=$KUBE_CONFIG get storageclass
    NAME                   PROVISIONER                                    AGE
    nfs-client (default)   cluster.local/storage-nfs-client-provisioner   16s
    

    上記パッケージがインストールされると、Helmパッケージの中にPVCがある場合、連動したNASに自動的にPVを生成します。

    注意

    nfs-client-provisionerを通じてNASにマウントされたWorker Nodeを停止する場合、停止失敗状態になることがあります。
    これはOSのバグで、アカウントされたNASに対してIが存在する場合に発生します。
    そのため、停止する前にノードメンテナンスガイドを参考に、終了するNodeを予めDrainしてから停止しておくことをお勧めします。

    Helmを利用したアプリケーションをインストールする

    本ガイドではHelmを利用してJenkinsアプリケーションのインストール及び接続できる方法を説明します。

    次のコマンドでJenkinsのインストールを実行します。

    制約事項

    • アプリケーションをインストールする前にPersistentVolumeを作成するためにStorageClassが必要です。

    Jenkins 設置する

    $ helm --kubeconfig=$KUBE_CONFIG install --name=ci stable/jenkins
    NAME:   ci
    LAST DEPLOYED: Wed Feb 20 15:38:07 2019
    NAMESPACE: default
    STATUS: DEPLOYED
    
    RESOURCES:
    ==> v1/ConfigMap
    NAME              AGE
    ci-jenkins        0s
    ci-jenkins-tests  0s
    
    ==> v1/PersistentVolumeClaim
    ci-jenkins  0s
    
    ==> v1/Service
    ci-jenkins-agent  0s
    ci-jenkins        0s
    
    ==> v1/Deployment
    ci-jenkins  0s
    
    ==> v1/Pod(related)
    
    NAME                         READY  STATUS   RESTARTS  AGE
    ci-jenkins-7fb57bf7bb-t8dd9  0/1    Pending  0         0s
    
    ==> v1/Secret
    
    NAME        AGE
    ci-jenkins  0s
    
    
    NOTES:
    1. Get your 'admin' user password by running:
      printf $(kubectl get secret --namespace default ci-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:
      NOTE: It may take a few minutes for the LoadBalancer IP to be available.
            You can watch the status of by running 'kubectl get svc --namespace default -w ci-jenkins'
      export SERVICE_IP=$(kubectl get svc --namespace default ci-jenkins --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")
      echo http://$SERVICE_IP:8080/login
    
    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
    
    • ユーザー名: admin
    • パスワード: secret을 통해 확인

    Jenkinsのインストールが完了すると、結果画面でアカウント情報を確認できるガイドを提供し、PV情報を確認することができます。

    PVC, PV 確認する

    $ kubectl --kubeconfig=$KUBE_CONFIG get pvc
    NAME         STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS         AGE
    ci-jenkins   Bound    pvc-1548887b-34da-11e9-89a3-f220cd2fe758   10Gi       RWO            nfs-client           23s
    
    $ kubectl --kubeconfig=$KUBE_CONFIG get pv
    NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                STORAGECLASS      REASON   AGE
    pvc-1548887b-34da-11e9-89a3-f220cd2fe758   10Gi       RWO            Delete           Bound    default/ci-jenkins   nfs-client                 23s
    

    SecretでJenkins接続アカウントのパスワードを確認する

    $ kubectl --kubeconfig=$KUBE_CONFIG get secret --namespace default ci-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode;echo
    Oq307Rj2Yu
    

    これで、ローカルマシンでkubectlコマンドのうち、port-forwardを利用してインストールされたJenkinsに接続できます。

    ローカルマシンでJenkinsに接続する

    $ export POD_NAME=$(kubectl --kubeconfig=$KUBE_CONFIG get pods -l "app.kubernetes.io/name=jenkins" -o jsonpath="{.items[0].metadata.name}"); echo $POD_NAME; kubectl --kubeconfig=$KUBE_CONFIG port-forward $POD_NAME 18080:8080
    Forwarding from [::1]:18080 -> 8080
    Forwarding from 127.0.0.1:18080 -> 8080
    

    上記コマンドを実行後、ブラウザから次のリンクにアクセスすると、Jenkinsログイン画面が確認できます。

    • http://localhost:18080

    nks-1-2-5_ja

    Jenkinsアカウント情報を入力してログインすると、Jenkinsの初期画面にアクセスできます。

    nks-1-2-6_ja

    Helmを利用したPrometheusGrafanaのインストール及びクラスターモニタリング

    このガイドではモニタリングシステムであるPrometheusと分析プラットフォームであるGrafanaを連動してクラスターをモニタリングする方法を説明します。
    PrometheusとGrafanaに関する詳細は、下記の公式ホームページでご確認いただけます。

    • https://prometheus.io
    • https://grafana.com

    制約事項

    • アプリケーションをインストールする前にPersistentVolumeを作成するためにStorageClassが必要です。

    Prometheusのインストール

    まず、モニタリングのための別途のネームスペースを作成します。

    Name space作成

    $ kubectl --kubeconfig=$KUBE_CONFIG create namespace pg
    

    Helmコマンドを利用してPrometheusをインストールします。

    HelmでPrometheusをインストール

    $ helm --kubeconfig=$KUBE_CONFIG install --name prometheus stable/prometheus --version 6.7.4 --namespace pg
    NAME:   prometheus
    LAST DEPLOYED: Thu Feb 28 11:24:30 2019
    NAMESPACE: pg
    STATUS: DEPLOYED
    
    RESOURCES:
    ==> v1/Pod(related)
    NAME                                            READY  STATUS             RESTARTS  AGE
    prometheus-node-exporter-pdrq7                  0/1    ContainerCreating  0         1s
    prometheus-alertmanager-7b945bb544-87knh        0/2    ContainerCreating  0         1s
    prometheus-kube-state-metrics-86996f7fff-tfm92  0/1    Pending            0         1s
    prometheus-pushgateway-b9477487f-42bhh          0/1    Pending            0         1s
    prometheus-server-6f9d569489-q75mx              0/2    Pending            0         1s
    
    ==> v1/PersistentVolumeClaim
    
    NAME                     AGE
    prometheus-alertmanager  1s
    prometheus-server        1s
    
    ==> v1beta1/ClusterRole
    prometheus-kube-state-metrics  1s
    prometheus-server              1s
    
    ==> v1beta1/ClusterRoleBinding
    prometheus-kube-state-metrics  1s
    prometheus-server              1s
    
    ==> v1/Service
    prometheus-alertmanager        1s
    prometheus-kube-state-metrics  1s
    prometheus-node-exporter       1s
    prometheus-pushgateway         1s
    prometheus-server              1s
    
    ==> v1beta1/DaemonSet
    prometheus-node-exporter  1s
    
    ==> v1/ConfigMap
    prometheus-alertmanager  1s
    prometheus-server        1s
    
    ==> v1/ServiceAccount
    prometheus-alertmanager        1s
    prometheus-kube-state-metrics  1s
    prometheus-node-exporter       1s
    prometheus-pushgateway         1s
    prometheus-server              1s
    
    ==> v1beta1/Deployment
    prometheus-alertmanager        1s
    prometheus-kube-state-metrics  1s
    prometheus-pushgateway         1s
    prometheus-server              1s
    
    
    NOTES:
    The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:
    prometheus-server.pg.svc.cluster.local
    
    
    Get the Prometheus server URL by running these commands in the same shell:
      export POD_NAME=$(kubectl get pods --namespace pg -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")
      kubectl --namespace pg 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.pg.svc.cluster.local
    
    
    Get the Alertmanager URL by running these commands in the same shell:
      export POD_NAME=$(kubectl get pods --namespace pg -l "app=prometheus,component=alertmanager" -o jsonpath="{.items[0].metadata.name}")
      kubectl --namespace pg port-forward $POD_NAME 9093
    
    
    The Prometheus PushGateway can be accessed via port 9091 on the following DNS name from within your cluster:
    prometheus-pushgateway.pg.svc.cluster.local
    
    
    Get the PushGateway URL by running these commands in the same shell:
      export POD_NAME=$(kubectl get pods --namespace pg -l "app=prometheus,component=pushgateway" -o jsonpath="{.items[0].metadata.name}")
      kubectl --namespace pg port-forward $POD_NAME 9091
    
    For more information on running Prometheus, visit:
    https://prometheus.io/
    

    ローカルマシンでPrometheusに接続する

    $ export POD_NAME=$(kubectl --kubeconfig=$KUBE_CONFIG get pods --namespace pg -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")
    $ kubectl --kubeconfig=$KUBE_CONFIG --namespace pg port-forward $POD_NAME 9090
    

    上記コマンドの実行後、ブラウザで次のリンクで Prometheus に接続することができます。

    • http://localhost:9090

    Grafana 設置

    Grafanaをインストールする前にPrometheusとの連動を設定するために、下のvalues.ymlを先に作成します。
    datasources.urlの値は http://<prometheus-server-name>です。 上記のガイドのとおりに進行した場合、<prometheus-server-name>prometheus-serverなので http://prometheus-serverに設定します。

    values.yml

    persistence:
      enabled: true
      accessModes:
        - ReadWriteOnce
      size: 5Gi
    
    datasources:
     datasources.yaml:
       apiVersion: 1
       datasources:
       - name: Prometheus
         type: prometheus
         url: http://prometheus-server
         access: proxy
         isDefault: true
    
    dashboards:
        kube-dash:
          gnetId: 6663
          revision: 1
          datasource: Prometheus
        kube-official-dash:
          gnetId: 2
          revision: 1
          datasource: Prometheus
    
    dashboardProviders:
      dashboardproviders.yaml:
        apiVersion: 1
        providers:
        - name: 'default'
          orgId: 1
          folder: ''
          type: file
          disableDeletion: false
          editable: true
          options:
            path: /var/lib/grafana/dashboards
    

    上記ファイルの作成後、`-f values.ymlオプションとともにHelmを利用してGrafanaをインストールします。

    HelmでGrafanaを設置

    $ helm --kubeconfig=$KUBE_CONFIG install --name grafana stable/grafana --version 1.11.6 -f values.yml --namespace pg
    NAME:   grafana
    LAST DEPLOYED: Thu Feb 28 14:38:24 2019
    NAMESPACE: pg
    STATUS: DEPLOYED
    
    RESOURCES:
    ==> v1beta1/RoleBinding
    NAME     AGE
    grafana  0s
    
    ==> v1/Service
    grafana  0s
    
    ==> v1beta2/Deployment
    grafana  0s
    
    ==> v1/Pod(related)
    
    NAME                      READY  STATUS   RESTARTS  AGE
    grafana-76dbd66b77-d2dkl  0/1    Pending  0         0s
    
    ==> v1beta1/PodSecurityPolicy
    
    NAME     AGE
    grafana  0s
    
    ==> v1/Secret
    grafana  0s
    
    ==> v1/ConfigMap
    grafana                  0s
    grafana-dashboards-json  0s
    
    ==> v1/ClusterRole
    grafana-clusterrole  0s
    
    ==> v1/PersistentVolumeClaim
    grafana  0s
    
    ==> v1/ServiceAccount
    grafana  0s
    
    ==> v1/ClusterRoleBinding
    grafana-clusterrolebinding  0s
    
    ==> v1beta1/Role
    grafana  0s
    
    
    NOTES:
    1. Get your 'admin' user password by running:
    
       kubectl get secret --namespace pg 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:
    
       grafana.pg.svc.cluster.local
    
       Get the Grafana URL to visit by running these commands in the same shell:
    
         export POD_NAME=$(kubectl get pods --namespace pg -l "app=grafana,component=" -o jsonpath="{.items[0].metadata.name}")
         kubectl --namespace pg port-forward $POD_NAME 3000
    
    3. Login with the password from step 1 and the username: admin
    

    SecretでGrafana接続アカウントのパスワードを確認する

    $ kubectl --kubeconfig=$KUBE_CONFIG get secret --namespace pg grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
    

    ローカルマシンでGrafanaに接続する

    $ export POD_NAME=$(kubectl --kubeconfig=$KUBE_CONFIG get pods --namespace pg -l "app=grafana" -o jsonpath="{.items[0].metadata.name}")
    $ kubectl --kubeconfig=$KUBE_CONFIG --namespace pg port-forward $POD_NAME 3000
    

    上記コマンドを実行後、Secretで取得したパスワードで下のリンクからGrafanaダッシュボードにアクセスすることができます。

    • http://localhost:3000
    • ユーザー名: admin
    • パスワード: secretを通じて確認

    대시보드 추가하기

    連動したPrometheusのデータを利用してモニタリングするためには、以下の2つのKubernetes用ダッシュボードを追加する必要があります。

    • https://grafana.com/dashboards/8588
    • https://grafana.com/dashboards/1621
    1. Grafanaの左側のメニューからCreate > importをクリックします。
      nks-1-2-10_ja

    2. 上のダッシュボードリンクを入力し、 をクリックします。
      nks-1-2-11_ja

    3. datasourceでPrometheusを選択し、importをクリックします。
      nks-1-2-12_ja

    4. インポートが完了するとダッシュボードが確認できます。
      nks-1-2-13_ja

    5. 他のダッシュボードも同様の方法で追加します。


    この記事は役に立ちましたか?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.