This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

AKS入門講座 Helmハンズオン

Last updated at Posted at 2020-05-22

Helm

独自Chartの作成

1.Helmコマンドの実行

コピー&ペースト用

コマンド
helm version

コマンド結果

コマンド
$ helm version
version.BuildInfo{Version:"v3.3.0-rc.1", GitCommit:"5c2dfaad847df2ac8f289d278186d048f446c70c", GitTreeState:"dirty", GoVersion:"go1.14.4"}

2.nginx_helmを作成

コピー&ペースト用

コマンド
helm create nginx_helm

コマンド結果

コマンド
$ helm create nginx_helm
Creating nginx_helm

3.「templates」配下のファイルを削除

コピー&ペースト用

コマンド
rm -rf nginx_helm/templates/*

コマンド結果

コマンド結果は表示されません。

コマンド
$ rm -rf nginx_helm/templates/*

4.「values.yaml」ファイルを初期化

コピー&ペースト用

コマンド
echo "" > nginx_helm/values.yaml

コマンド結果

コマンド結果は表示されません。

コマンド
$ echo "" > nginx_helm/values.yaml

5.NginxのDployment yamlファイルを作成

コピー&ペースト用

コマンド
kubectl create deployment nginx --image=nginx:1.19.2 --dry-run=client -o yaml > nginx_helm.yaml

コマンド結果

コマンド結果は表示されません。

コマンド
$ kubectl create deployment nginx --image=nginx:1.19.2 --dry-run=client -o yaml > nginx_helm.yaml

6.「templates」配下にnginx_helm.yamlファイルを移動

コピー&ペースト用

コマンド
mv nginx_helm.yaml nginx_helm/templates

コマンド結果

コマンド結果は表示されません。

コマンド
$ mv nginx_helm.yaml nginx_helm/templates

7.テンプレートファイルの作成

コピー&ペースト用

コマンド
vim nginx_helm/templates/nginx_helm.yaml
コマンド
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: {{ .Values.label }}
  name: {{ .Values.name }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .Values.label }}
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: {{ .Values.label }}
    spec:
      containers:
      - image: {{ .Values.image }}
        name: {{ .Values.name }}
        resources: {}
status: {}

作業全体

コマンド
$ vim nginx_helm/templates/nginx_helm.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: {{ .Values.label }}
  name: {{ .Values.name }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .Values.label }}
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: {{ .Values.label }}
    spec:
      containers:
      - image: {{ .Values.image }}
        name: {{ .Values.name }}
        resources: {}
status: {}

8.values.yamlファイルの作成

コピー&ペースト用

コマンド
vim nginx_helm/values.yaml
コマンド
name: nginx
label: nginx
image: nginx:1.19.2

作業全体

コマンド
$ vim nginx_helm/values.yaml
name: nginx
label: nginx
image: nginx:1.19.2

9.Chartのデバッグ

コピー&ペースト用

コマンド
helm install nginx --debug --dry-run ./nginx_helm

コマンド結果

コマンド
$ helm install nginx --debug --dry-run ./nginx_helm
install.go:159: [debug] Original chart version: ""
install.go:176: [debug] CHART PATH: /home/ichikawa/nginx_helm

NAME: nginx
LAST DEPLOYED: Wed May 20 04:18:28 2020
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
USER-SUPPLIED VALUES:
{}

COMPUTED VALUES:
image: nginx:1.7.8
label: nginx
name: nginx

HOOKS:
MANIFEST:
---
# Source: nginx_helm/templates/nginx_helm.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:1.7.8
        name: nginx
        resources: {}
status: {}

10.テンプレート検証

コピー&ペースト用

コマンド
helm lint ./nginx_helm

コマンド結果

コマンド
$ helm lint ./nginx_helm
==> Linting ./nginx_helm
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed

11.Chartをパッケージ

コピー&ペースト用

コマンド
helm package nginx_helm/

コマンド結果

コマンド
$ helm package nginx_helm/
Successfully packaged chart and saved it to: /home/ichikawa/nginx_helm-0.1.0.tgz

12.indexの作成

コピー&ペースト用

コマンド
helm repo index .

コマンド結果

コマンド結果は表示されません。

コマンド
$ helm repo index .

13.index.yamlの確認

index.yamlとnginx_helm-0.1.0.tgzを独自の公開リポジトリ(WebサーバやGitHubなど)にaddして利用する形となりますが、本ハンズオンではローカルでインストールを実施します。

コピー&ペースト用

コマンド
cat index.yaml

コマンド結果

コマンド
$ cat index.yaml
apiVersion: v1
entries:
  nginx_helm:
  - apiVersion: v2
    appVersion: 1.16.0
    created: "2020-05-20T04:22:49.558317337Z"
    description: A Helm chart for Kubernetes
    digest: e6f5f535c4576d99f024bf7861a3d38af8f1e58cf0fc97c6122cced1f9f51bbd
    name: nginx_helm
    type: application
    urls:
    - nginx_helm-0.1.0.tgz
    version: 0.1.0
generated: "2020-05-20T04:22:49.557823316Z"

14.Nginxをデプロイ

コピー&ペースト用

コマンド
helm install nginx ./nginx_helm

コマンド結果

コマンド
$ helm install nginx ./nginx_helm
NAME: nginx
LAST DEPLOYED: Wed May 20 04:25:12 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

15.deploymentとpodがデプロイされていることを確認

コピー&ペースト用1

コマンド
kubectl get deploy

コマンド結果1

コマンド
$ kubectl get deploy
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   1/1     1            1           88s

コピー&ペースト用2

コマンド
kubectl get pods

コマンド結果2

コマンド
$ kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-69c78976c7-dbw5k   1/1     Running   0          2m11s

HelmでWordPress環境構築

1.Helmチャートリポジトリの追加

コピー&ペースト用

コマンド
helm repo add stable https://kubernetes-charts.storage.googleapis.com/

コマンド結果

コマンド
$ helm repo add stable https://kubernetes-charts.storage.googleapis.com/
"stable" has been added to your repositories

2.登録リポジトリの確認

コピー&ペースト用

コマンド
helm repo list

コマンド結果

コマンド
$ helm repo list
NAME    URL
stable  https://kubernetes-charts.storage.googleapis.com/

3.リポジトリの更新

コピー&ペースト用

コマンド
helm repo update

コマンド結果

コマンド
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈

4.WordPress Chartの検索

コピー&ペースト用

コマンド
helm search repo wordpress

コマンド結果

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

5.WordPressをデプロイ

コピー&ペースト用

コマンド
helm install wordpress stable/wordpress

コマンド結果

コマンド
$ helm install wordpress stable/wordpress
WARNING: This chart is deprecated
NAME: wordpress
LAST DEPLOYED: Fri Sep 25 09:34:39 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
This Helm chart is deprecated

Given the `stable` deprecation timeline (https://github.com/helm/charts#deprecation-timeline), the Bitnami maintained Helm chart is now located at bitnami/charts (https://github.com/bitnami/charts/).

The Bitnami repository is already included in the Hubs and we will continue providing the same cadence of updates, support, etc that we've been keeping here these years. Installation instructions are very similar, just adding the _bitnami_ repo and using it during the installation (`bitnami/<chart>` instead of `stable/<chart>`)

bash
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm install my-release bitnami/<chart>           # Helm 3
$ helm install --name my-release bitnami/<chart>    # Helm 2


To update an exisiting _stable_ deployment with a chart hosted in the bitnami repository you can execute

bash
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm upgrade my-release bitnami/<chart>


Issues and PRs related to the chart itself will be redirected to `bitnami/charts` GitHub repository. In the same way, we'll be happy to answer questions related to this migration process in this issue (https://github.com/helm/charts/issues/20969) created as a common place for discussion.

** Please be patient while the chart is being deployed **

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)

6.デプロイしたHelmの確認

コピー&ペースト用

コマンド
helm list

コマンド結果

コマンド
$ helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
nginx           default         1               2020-09-25 09:24:22.657908866 +0000 UTC deployed        nginx_helm-0.1.0        1.16.0
wordpress       default         1               2020-09-25 09:34:39.881634164 +0000 UTC deployed        wordpress-9.0.3         5.3.2

7.エンドポイントの確認

「5.WordPressをデプロイ」の後半で生成されるコマンドです。都度異なるので、表示されたコマンドを実行してください。

コピー&ペースト用1

コマンド
SERVICE_IP=$(kubectl get svc --namespace default wordpress --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")

コピー&ペースト用2

コマンド
echo "WordPress Admin URL: http://$SERVICE_IP/admin"

コマンド結果2

コマンド
$ echo "WordPress Admin URL: http://$SERVICE_IP/admin"
WordPress Admin URL: http://20.46.190.159/admin

8.WordPressのログインパスワード確認

コピー&ペースト用

コマンド
echo Password: $(kubectl get secret --namespace default wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode)

コマンド結果

コマンド
$ echo Password: $(kubectl get secret --namespace default wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode)
Password: VOM0duPqHT

9.エンドポイントの確認で表示されたURLに「http://$SERVICE_IP/admin」にアクセス

Username:user
Password:VOM0duPqHT ※確認したパスワードを入力

screencapture-20-46-190-159-wp-login-php-2020-05-20-13_57_52.png

10.WordPressとNginxのアンインストール

コピー&ペースト用

コマンド
helm list

コマンド結果

コマンド
$ helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
nginx           default         1               2020-09-25 09:24:22.657908866 +0000 UTC deployed        nginx_helm-0.1.0        1.16.0
wordpress       default         1               2020-09-25 09:34:39.881634164 +0000 UTC deployed        wordpress-9.0.3         5.3.2

コピー&ペースト用

コマンド
helm uninstall wordpress

コマンド結果

コマンド
$ helm uninstall wordpress
release "wordpress" uninstalled

コピー&ペースト用

コマンド
helm uninstall nginx

コマンド結果

コマンド
$ helm uninstall nginx
release "nginx" uninstalled

コピー&ペースト用

コマンド
helm list

コマンド結果

コマンド
$ helm list
NAME    NAMESPACE       REVISION        UPDATED STATUS  CHART   APP VERSION
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