IBM Cloud PrivateにMicroclimate 1.2.0をデプロイする

シングルノードのICPにMicroclimateをデプロイした作業メモです。ICPのバージョンは2.1.0.3、Microcliamteのチャートのバージョンは1.2.0です。手順は以下に従います。

https://github.com/IBM/charts/blob/master/stable/ibm-microclimate/README.md

## Secretを作成する

Secretを作成する。

```
kubectl create secret docker-registry microclimate-registry-secret \
  --docker-server=mycluster.icp:8500 \
  --docker-username=admin \
  --docker-password=admin \
  --docker-email=null
```

```shell-session
[root@myicp01 ~]# kubectl get secret
NAME                  TYPE                                  DATA      AGE
default-token-m9bb4   kubernetes.io/service-account-token   3         7d
istio.default         istio.io/key-and-cert                 3         7d
[root@myicp01 ~]#
[root@myicp01 ~]#
[root@myicp01 ~]# kubectl create secret docker-registry microclimate-registry-secret \
>   --docker-server=mycluster.icp:8500 \
>   --docker-username=admin \
>   --docker-password=admin \
>   --docker-email=null
secret "microclimate-registry-secret" created
[root@myicp01 ~]#
[root@myicp01 ~]#
[root@myicp01 ~]# kubectl get secret
NAME                           TYPE                                  DATA      AGE
default-token-m9bb4            kubernetes.io/service-account-token   3         7d
istio.default                  istio.io/key-and-cert                 3         7d
microclimate-registry-secret   kubernetes.io/dockerconfigjson        1         5s
[root@myicp01 ~]#
[root@myicp01 ~]#
```

## ServiceAccountにパッチを当てる

ServiceAccountにパッチを当てる。

```
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "microclimate-registry-secret"}]}'
```

もどすには

```
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "sa-default"}]}'
```

両方残しておくには

```
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "sa-default"}, {"name": "microclimate-registry-secret"}]}'
```

```shell-session
[root@myicp01 ~]# kubectl get serviceaccount -o wide
NAME      SECRETS   AGE
default   1         7d
[root@myicp01 ~]#
[root@myicp01 ~]#
[root@myicp01 ~]# kubectl describe serviceaccount default
Name:                default
Namespace:           default
Labels:              <none>
Annotations:         <none>
Image pull secrets:  <none>
Mountable secrets:   default-token-m9bb4
Tokens:              default-token-m9bb4
Events:              <none>
[root@myicp01 ~]#
[root@myicp01 ~]#
[root@myicp01 ~]# kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "sa-default"}, {"name": "microclimate-registry-secret"}]}'
serviceaccount "default" patched
[root@myicp01 ~]#
[root@myicp01 ~]#
[root@myicp01 ~]# kubectl describe serviceaccount default
Name:                default
Namespace:           default
Labels:              <none>
Annotations:         <none>
Image pull secrets:  sa-default (not found)
                     microclimate-registry-secret
Mountable secrets:   default-token-m9bb4
Tokens:              default-token-m9bb4
Events:              <none>
[root@myicp01 ~]#
[root@myicp01 ~]#
```

## Helm用のsecretの作成

MicroclimateのパイプラインからHelmリリースをするためのSecretを作成する。

```
kubectl create secret generic microclimate-helm-secret \
  --from-file=cert.pem=.helm/cert.pem \
  --from-file=ca.pem=.helm/ca.pem \
  --from-file=key.pem=.helm/key.pem
```

```shell-session
[root@myicp01 ~]# kubectl create secret generic microclimate-helm-secret \
>   --from-file=cert.pem=.helm/cert.pem \
>   --from-file=ca.pem=.helm/ca.pem \
>   --from-file=key.pem=.helm/key.pem
secret "microclimate-helm-secret" created
[root@myicp01 ~]#
[root@myicp01 ~]#
[root@myicp01 ~]# kubectl get secret
NAME                           TYPE                                  DATA      AGE
default-token-m9bb4            kubernetes.io/service-account-token   3         7d
istio.default                  istio.io/key-and-cert                 3         7d
microclimate-helm-secret       Opaque                                3         6s
microclimate-registry-secret   kubernetes.io/dockerconfigjson        1         6m
[root@myicp01 ~]#
[root@myicp01 ~]#
```

## Helmリポジトリーの追加

Helmリリースのためにリポジトリーを追加する。

```shell-session
[root@myicp01 ~]# helm repo list
NAME  	URL
stable	https://kubernetes-charts.storage.googleapis.com
local 	http://127.0.0.1:8879/charts
[root@myicp01 ~]#
[root@myicp01 ~]#
[root@myicp01 ~]# helm repo add ibm-charts https://raw.githubusercontent.com/IBM/charts/master/repo/stable/
"ibm-charts" has been added to your repositories
[root@myicp01 ~]#
[root@myicp01 ~]#
[root@myicp01 ~]# helm repo list
NAME      	URL
stable    	https://kubernetes-charts.storage.googleapis.com
local     	http://127.0.0.1:8879/charts
ibm-charts	https://raw.githubusercontent.com/IBM/charts/master/repo/stable/
[root@myicp01 ~]#
[root@myicp01 ~]#
```

## PersistantVolumeの用意

今回はHostpathのPVを使うので、ノード上にディレクトリーを用意する。

```shell-session
[root@myicp01 export]# pwd
/export
[root@myicp01 export]# mkdir MC_jenkins01
[root@myicp01 export]# mkdir MC_microclimate01
[root@myicp01 export]# ls -l
合計 8
drwxr-xr-x  5 root    root   56  5月 23 11:09 CAM_BPD_appdata
drwxr-xr-x  4 polkitd root 4096  5月 29 16:56 CAM_db
drwxr-xr-x 18 root    root 4096  5月 23 11:11 CAM_logs
drwxr-xr-x  3 root    root   38  5月 23 11:09 CAM_terraform
drwxr-xr-x  2 root    root    6  5月 29 16:57 MC_jenkins01
drwxr-xr-x  2 root    root    6  5月 29 16:57 MC_microclimate01
[root@myicp01 export]#
```

ICPダッシュボードのプラットフォーム > ストレージから、「PersistantVolumeの作成」ボタンをクリックし、PVを2つ作成する。適当なlabelを指定しておく。

Jenkins用

```json
{
  "kind": "PersistentVolume",
  "apiVersion": "v1",
  "metadata": {
    "name": "mc-jenkins01",
    "labels": {
      "mylabel": "jenkins01"
    }
  },
  "spec": {
    "capacity": {
      "storage": "8Gi"
    },
    "accessModes": [
      "ReadWriteOnce"
    ],
    "persistentVolumeReclaimPolicy": "Retain",
    "hostPath": {
      "path": "/export/MC_jenkins01"
    }
  }
}
```

Microclimate用

```json
{
  "kind": "PersistentVolume",
  "apiVersion": "v1",
  "metadata": {
    "name": "mc-microclimate01",
    "labels": {
      "mylabel": "microclimate01"
    }
  },
  "spec": {
    "capacity": {
      "storage": "2Gi"
    },
    "accessModes": [
      "ReadWriteOnce"
    ],
    "persistentVolumeReclaimPolicy": "Retain",
    "hostPath": {
      "path": "/export/MC_microclimate01"
    }
  }
}
```

続いてPersistantVolumeClaimeタブに移動し、「PersistantVolumeClaimeの作成」ボタンを押してPVCを2つ作成する。先ほど指定したlabelを使ってPVを指定する。

Jenkins用

```json
{
  "kind": "PersistentVolumeClaim",
  "apiVersion": "v1",
  "metadata": {
    "name": "mc-jenkins01",
    "namespace": "default"
  },
  "spec": {
    "resources": {
      "requests": {
        "storage": "8Gi"
      }
    },
    "accessModes": [
      "ReadWriteOnce"
    ],
    "selector": {
      "matchLabels": {
        "mylabel": "jenkins01"
      }
    }
  }
}
```

Microclimate用

```json
{
  "kind": "PersistentVolumeClaim",
  "apiVersion": "v1",
  "metadata": {
    "name": "mc-microclimate01",
    "namespace": "default"
  },
  "spec": {
    "resources": {
      "requests": {
        "storage": "2Gi"
      }
    },
    "accessModes": [
      "ReadWriteOnce"
    ],
    "selector": {
      "matchLabels": {
        "mylabel": "microclimate01"
      }
    }
  }
}
```

ステータスがBoundになったことを確認。

![image.png](https://qiita-image-store.s3.amazonaws.com/0/86449/0c078e6f-c30c-4dc4-d662-7968f4a77998.png)


## インストールの実行

JenkinsのIngressのホスト名、MicroclimateのIngressのホスト名、先ほど作成したPVCを指定してインストールを実行する。ここではnip.io（ワイルドカードDNS）を使用。

```
helm install --tls --name microclimate01 \
--set hostName=microclimate.XX.XX.XX.XX.nip.io \
--set jenkins.Master.HostName=jenkins.XX.XX.XX.XX.nip.io \
--set persistence.useDynamicProvisioning=false \
--set persistence.existingClaimName=mc-microclimate01 \
--set jenkins.Persistence.ExistingClaim=mc-jenkins01 \
ibm-charts/ibm-microclimate
```

```shell-session
[root@myicp01 ~]# helm install --tls --name microclimate01 \
> --set hostName=microclimate.XX.XX.XX.XX.nip.io \
> --set jenkins.Master.HostName=jenkins.XX.XX.XX.XX.nip.io \
> --set persistence.useDynamicProvisioning=false \
> --set persistence.existingClaimName=mc-microclimate01 \
> --set jenkins.Persistence.ExistingClaim=mc-jenkins01 \
> ibm-charts/ibm-microclimate
NAME:   microclimate01
LAST DEPLOYED: Fri Jun  1 15:14:20 2018
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1beta1/Ingress
NAME                             HOSTS                            ADDRESS      PORTS    AGE
microclimate01-jenkins           jenkins.XX.XX.XX.XX.nip.io       XX.XX.XX.XX  80, 443  1m
microclimate01-ibm-microclimate  microclimate.XX.XX.XX.XX.nip.io  XX.XX.XX.XX  80, 443  1m

==> v1/Pod(related)
NAME                                                     READY  STATUS             RESTARTS  AGE
microclimate01-jenkins-6566c7767c-g248m                  0/1    Running            0         1m
microclimate01-ibm-microclimate-devops-56d9f576f4-6lwqx  0/1    Running            0         1m
microclimate01-ibm-microclimate-6f5b5fd4f8-fndnf         0/3    ContainerCreating  0         1m
microclimate01-ibm-microclimate-oic-jenkins-mh522        0/1    Completed          0         1m

==> v1/Secret
NAME                             TYPE    DATA  AGE
microclimate01-jenkins           Opaque  2     1m
microclimate01-mc-tls-secret     Opaque  2     1m
microclimate01-tls-secret        Opaque  2     1m
microclimate01-ibm-microclimate  Opaque  3     1m

==> v1/ConfigMap
NAME                                                   DATA  AGE
microclimate01-jenkins                                 6     1m
microclimate01-jenkins-tests                           1     1m
microclimate01-ibm-microclimate-fixup-jenkins-ingress  1     1m

==> v1/Service
NAME                                    TYPE       CLUSTER-IP  EXTERNAL-IP  PORT(S)                     AGE
microclimate01-jenkins-agent            ClusterIP  10.0.0.122  <none>       50000/TCP                   1m
microclimate01-jenkins                  ClusterIP  10.0.0.105  <none>       8080/TCP                    1m
microclimate01-ibm-microclimate-devops  ClusterIP  10.0.0.16   <none>       9191/TCP                    1m
microclimate01-ibm-microclimate         ClusterIP  10.0.0.80   <none>       4191/TCP,9090/TCP,9091/TCP  1m

==> v1beta1/Deployment
NAME                                    DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
microclimate01-jenkins                  1        1        1           0          1m
microclimate01-ibm-microclimate-devops  1        1        1           0          1m
microclimate01-ibm-microclimate         1        1        1           0          1m

==> v1/Job
NAME                                         DESIRED  SUCCESSFUL  AGE
microclimate01-ibm-microclimate-oic-jenkins  1        1           1m


NOTES:
ibm-microclimate-1.2.0

1. Access the Microclimate portal at the following URL: https://microclimate.XX.XX.XX.XX.nip.io

[root@myicp01 ~]#
```

Podが立ち上がるのを待つ。

```shell-session
[root@iseicp01 ~]# kubectl get all -l chart=ibm-microclimate-1.2.0
NAME                                                      READY     STATUS    RESTARTS   AGE
microclimate01-ibm-microclimate-6f5b5fd4f8-fndnf          3/3       Running   0          8m
microclimate01-ibm-microclimate-devops-56d9f576f4-6lwqx   1/1       Running   0          8m

NAME                                     TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                      AGE
microclimate01-ibm-microclimate          ClusterIP   10.0.0.80    <none>        4191/TCP,9090/TCP,9091/TCP   8m
microclimate01-ibm-microclimate-devops   ClusterIP   10.0.0.16    <none>        9191/TCP                     8m

NAME                                     DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
microclimate01-ibm-microclimate          1         1         1            1           8m
microclimate01-ibm-microclimate-devops   1         1         1            1           8m

NAME                                                DESIRED   CURRENT   READY     AGE
microclimate01-ibm-microclimate-6f5b5fd4f8          1         1         1         8m
microclimate01-ibm-microclimate-devops-56d9f576f4   1         1         1         8m
[root@iseicp01 ~]#
```

## Microclimateにアクセス

さきほど指定したホスト名でIngressにアクセスする。ブラウザで以下URLにアクセス。

https://microclimate.XX.XX.XX.XX.nip.io/

![image.png](https://qiita-image-store.s3.amazonaws.com/0/86449/6fa62254-ddf0-d8b6-d24b-a7fc2614cc56.png)