OpenShiftをアップデート(マイナーアップデート)してみる

#はじめに
OpenShiftのアップデートが簡単に実行できるというこちらの記事[^1]ではGUIの例が紹介されていました。CLIではどうなるのか気になったので実行してみた結果を記載します。

[^1]: [OTAでOCP4とK8sをお手軽アップデート](https://rheb.hatenablog.com/entry/openshift4-ota-update)

#環境

OCPバージョン：4.2.0
構成：Master x3、Worker x2のクラスタ構成。すべてのノードからのインターネット接続は可能で、OSはすべてRHCOSを使ってUPIで構築した環境。


#実行前の確認

- バージョン情報

```
$ oc get clusterversion
NAME      VERSION   AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.2.0     True        False         36d     Cluster version is 4.2.0
```

- バージョン情報詳細

```yaml
$ oc get clusterversion -o yaml
apiVersion: v1
items:
- apiVersion: config.openshift.io/v1
  kind: ClusterVersion
  metadata:
    creationTimestamp: "2019-12-09T04:50:44Z"
    generation: 1
    name: version
    resourceVersion: "12026237"
    selfLink: /apis/config.openshift.io/v1/clusterversions/version
    uid: 7540da58-1a3f-11ea-84b4-000c293c13fe
  spec:
    channel: stable-4.2
    clusterID: 45590876-a846-4390-9c45-a995980b979d
    upstream: https://api.openshift.com/api/upgrades_info/v1/graph
  status:
    availableUpdates:
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:bac62983757570b9b8f8bc84c740782984a255c16372b3e30cfc8b52c0a187b9
      version: 4.2.7
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:77ade34c373062c6a6c869e0e56ef93b2faaa373adadaac1430b29484a24d843
      version: 4.2.12
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:f28cbabd1227352fe704a00df796a4511880174042dece96233036a10ac61639
      version: 4.2.9
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:dc782b44cac3d59101904cc5da2b9d8bdb90e55a07814df50ea7a13071b0f5f0
      version: 4.2.2
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:4bf307b98beba4d42da3316464013eac120c6e5a398646863ef92b0e2c621230
      version: 4.2.8
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:dc2e38fb00085d6b7f722475f8b7b758a0cb3a02ba42d9acf8a8298a6d510d9c
      version: 4.2.10
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:782b41750f3284f3c8ee2c1f8cb896896da074e362cf8a472846356d1617752d
      version: 4.2.13
    conditions:
    - lastTransitionTime: "2019-12-09T05:46:37Z"
      message: Done applying 4.2.0
      status: "True"
      type: Available
    - lastTransitionTime: "2019-12-09T05:46:37Z"
      status: "False"
      type: Failing
    - lastTransitionTime: "2019-12-09T05:46:37Z"
      message: Cluster version is 4.2.0
      status: "False"
      type: Progressing
    - lastTransitionTime: "2019-12-18T21:30:19Z"
      status: "True"
      type: RetrievedUpdates
    desired:
apiVersion: v1
items:
- apiVersion: config.openshift.io/v1
  kind: ClusterVersion
  metadata:
    creationTimestamp: "2019-12-09T04:50:44Z"
    generation: 1
    name: version
    resourceVersion: "12026237"
    selfLink: /apis/config.openshift.io/v1/clusterversions/version
    uid: 7540da58-1a3f-11ea-84b4-000c293c13fe
  spec:
    channel: stable-4.2
    channel: stable-4.2
    clusterID: 45590876-a846-4390-9c45-a995980b979d
    upstream: https://api.openshift.com/api/upgrades_info/v1/graph
      force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:c5337afd85b94c93ec513f21c8545e3f9e36a227f55d41bc1dfb8fcc3f2be129
      version: 4.2.0
    history:
    - completionTime: "2019-12-09T05:46:37Z"
      image: quay.io/openshift-release-dev/ocp-release@sha256:c5337afd85b94c93ec513f21c8545e3f9e36a227f55d41bc1dfb8fcc3f2be129
      startedTime: "2019-12-09T04:51:05Z"
      state: Completed
      verified: false
      version: 4.2.0
    observedGeneration: 1
    versionHash: tM2NjdTMVKw=
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""
```

`channel: stable-4.2`で`version: 4.2.0`ということが確認できます。

- アップデート可能なバージョン確認

```
$ oc adm upgrade
Cluster version is 4.2.0

Updates:

VERSION IMAGE
4.2.2   quay.io/openshift-release-dev/ocp-release@sha256:dc782b44cac3d59101904cc5da2b9d8bdb90e55a07814df50ea7a13071b0f5f0
4.2.7   quay.io/openshift-release-dev/ocp-release@sha256:bac62983757570b9b8f8bc84c740782984a255c16372b3e30cfc8b52c0a187b9
4.2.8   quay.io/openshift-release-dev/ocp-release@sha256:4bf307b98beba4d42da3316464013eac120c6e5a398646863ef92b0e2c621230
4.2.9   quay.io/openshift-release-dev/ocp-release@sha256:f28cbabd1227352fe704a00df796a4511880174042dece96233036a10ac61639
4.2.10  quay.io/openshift-release-dev/ocp-release@sha256:dc2e38fb00085d6b7f722475f8b7b758a0cb3a02ba42d9acf8a8298a6d510d9c
4.2.12  quay.io/openshift-release-dev/ocp-release@sha256:77ade34c373062c6a6c869e0e56ef93b2faaa373adadaac1430b29484a24d843
4.2.13  quay.io/openshift-release-dev/ocp-release@sha256:782b41750f3284f3c8ee2c1f8cb896896da074e362cf8a472846356d1617752d
```

現状のバージョン4.2.0に対してバージョン4.2.13までアップデート可能なことが確認できます。（2020/1/14現在）

- Node

```
$ oc get node
NAME       STATUS     ROLES    AGE   VERSION
master-0   Ready      master   36d   v1.14.6+c07e432da
master-1   Ready      master   36d   v1.14.6+c07e432da
master-2   NotReady   master   36d   v1.14.6+c07e432da
worker-0   NotReady   worker   36d   v1.14.6+c07e432da
worker-1   Ready      worker   36d   v1.14.6+c07e432da
```

- Opertor

```
$ oc get clusteroperator
NAME                                       VERSION   AVAILABLE   PROGRESSING   DEGRADED   SINCE
authentication                             4.2.0     True        False         False      35d
cloud-credential                           4.2.0     True        False         False      35d
cluster-autoscaler                         4.2.0     True        False         False      35d
console                                    4.2.0     True        False         False      35d
dns                                        4.2.0     True        False         False      35d
image-registry                             4.2.0     True        False         False      35d
ingress                                    4.2.0     True        False         False      35d
insights                                   4.2.0     True        False         False      35d
kube-apiserver                             4.2.0     True        False         False      35d
kube-controller-manager                    4.2.0     True        False         False      35d
kube-scheduler                             4.2.0     True        False         False      35d
machine-api                                4.2.0     True        False         False      35d
machine-config                             4.2.0     True        False         False      35d
marketplace                                4.2.0     True        False         False      35d
monitoring                                 4.2.0     True        False         False      35d
network                                    4.2.0     True        False         False      35d
node-tuning                                4.2.0     True        False         False      35d
openshift-apiserver                        4.2.0     True        False         False      35d
openshift-controller-manager               4.2.0     True        False         False      35d
openshift-samples                          4.2.0     True        False         False      35d
operator-lifecycle-manager                 4.2.0     True        False         False      35d
operator-lifecycle-manager-catalog         4.2.0     True        False         False      35d
operator-lifecycle-manager-packageserver   4.2.0     True        False         False      4d4h
service-ca                                 4.2.0     True        False         False      35d
service-catalog-apiserver                  4.2.0     True        False         False      35d
service-catalog-controller-manager         4.2.0     True        False         False      35d
storage                                    4.2.0     True        False         False      35d
```




#アップデート実行

アップデートの実行は、こちら[^2]を参考に`oc adm upgrade --to=<version>`コマンドでバージョン指定して実行します。
今回は（後で何度もアップデートできるように）ひとつ上の4.2.2にアップデートします。

[^2]: [3.3. CLI を使用したクラスターの更新](https://access.redhat.com/documentation/ja-jp/openshift_container_platform/4.2/html/updating_clusters/update-upgrading-cli_updating-cluster-cli)

```
[user01@bastion ~]$ oc adm upgrade --to=4.2.2
Updating to 4.2.2
[user01@bastion ~]$
```
あっさり、実行できました。
進行状況は下記のような感じで、`oc get clusterversion`コマンドを実行することで確認できます。

```
[user01@bastion ~]$ oc get clusterversion
NAME      VERSION   AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.2.0     True        True          19s     Working towards 4.2.2: downloading update
[user01@bastion ~]$ oc get clusterversion
NAME      VERSION   AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.2.0     True        True          2m4s    Working towards 4.2.2: 13% complete
[user01@bastion ~]$ oc get clusterversion
NAME      VERSION   AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.2.0     True        True          11m     Working towards 4.2.2: 85% complete
[user01@bastion ocp]$ oc get clusterversion
NAME      VERSION   AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.2.0     True        True          22m     Working towards 4.2.2: 88% complete, waiting on machine-config
[user01@bastion ocp]$ oc get clusterversion
NAME      VERSION   AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.2.0     True        True          26m     Working towards 4.2.2: 88% complete
[user01@bastion ocp]$ oc get clusterversion
NAME      VERSION   AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.2.2     True        False         7m41s   Cluster version is 4.2.2
```
↑最後の確認実行で、`Cluster version is 4.2.2`と表示され、アップデートが完了したことが確認できます。
なお、今回は30分程度でアップデートが完了しました。

#アップデート後の確認

- clusterversion確認

```yaml
$ oc get clusterversion -o yaml
apiVersion: v1
items:
- apiVersion: config.openshift.io/v1
  kind: ClusterVersion
  metadata:
    creationTimestamp: "2019-12-09T04:50:44Z"
    generation: 2
    name: version
    resourceVersion: "13335935"
    selfLink: /apis/config.openshift.io/v1/clusterversions/version
    uid: 7540da58-1a3f-11ea-84b4-000c293c13fe
  spec:
    channel: stable-4.2
    clusterID: 45590876-a846-4390-9c45-a995980b979d
    desiredUpdate:
      force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:dc782b44cac3d59101904cc5da2b9d8bdb90e55a07814df50ea7a13071b0f5f0
      version: 4.2.2
    upstream: https://api.openshift.com/api/upgrades_info/v1/graph
  status:
    availableUpdates:
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:782b41750f3284f3c8ee2c1f8cb896896da074e362cf8a472846356d1617752d
      version: 4.2.13
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:bac62983757570b9b8f8bc84c740782984a255c16372b3e30cfc8b52c0a187b9
      version: 4.2.7
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:77ade34c373062c6a6c869e0e56ef93b2faaa373adadaac1430b29484a24d843
      version: 4.2.12
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:f28cbabd1227352fe704a00df796a4511880174042dece96233036a10ac61639
      version: 4.2.9
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:4bf307b98beba4d42da3316464013eac120c6e5a398646863ef92b0e2c621230
      version: 4.2.8
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:dc2e38fb00085d6b7f722475f8b7b758a0cb3a02ba42d9acf8a8298a6d510d9c
      version: 4.2.10
    - force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:cebce35c054f1fb066a4dc0a518064945087ac1f3637fe23d2ee2b0c433d6ba8
      version: 4.2.4
    conditions:
    - lastTransitionTime: "2019-12-09T05:46:37Z"
      message: Done applying 4.2.2
      status: "True"
      type: Available
    - lastTransitionTime: "2020-01-14T08:22:05Z"
      status: "False"
      type: Failing
    - lastTransitionTime: "2020-01-14T08:27:50Z"
      message: Cluster version is 4.2.2
      status: "False"
      type: Progressing
    - lastTransitionTime: "2020-01-14T11:47:29Z"
      status: "True"
      type: RetrievedUpdates
    desired:
      force: false
      image: quay.io/openshift-release-dev/ocp-release@sha256:dc782b44cac3d59101904cc5da2b9d8bdb90e55a07814df50ea7a13071b0f5f0
      version: 4.2.2
    history:
    - completionTime: "2020-01-14T08:27:50Z"
      image: quay.io/openshift-release-dev/ocp-release@sha256:dc782b44cac3d59101904cc5da2b9d8bdb90e55a07814df50ea7a13071b0f5f0
      startedTime: "2020-01-14T07:58:55Z"
      state: Completed
      verified: true
      version: 4.2.2
    - completionTime: "2020-01-14T07:58:55Z"
      image: quay.io/openshift-release-dev/ocp-release@sha256:c5337afd85b94c93ec513f21c8545e3f9e36a227f55d41bc1dfb8fcc3f2be129
      startedTime: "2019-12-09T04:51:05Z"
      state: Completed
      verified: false
      version: 4.2.0
    observedGeneration: 2
    versionHash: ITlJ7b_Yn-s=
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""
```

↓
`channel: stable-4.2`で`version: 4.2.2`になっていることが確認できます。
また、Historyに以前のバージョン：4.2.0とアップデートしたバージョン：4.2.2が記録されています。

- Node確認

```
$ oc get node
NAME       STATUS   ROLES    AGE   VERSION
master-0   Ready    master   36d   v1.14.6+7e13ab9a7
master-1   Ready    master   36d   v1.14.6+7e13ab9a7
master-2   Ready    master   36d   v1.14.6+7e13ab9a7
worker-0   Ready    worker   36d   v1.14.6+7e13ab9a7
worker-1   Ready    worker   36d   v1.14.6+7e13ab9a7
```
~~こちらは特にバージョンは変わっていません。~~
（修正）バージョンは変わっていました。


- Operator確認

```
$ oc get clusteroperator
NAME                                       VERSION   AVAILABLE   PROGRESSING   DEGRADED   SINCE
authentication                             4.2.2     True        False         False      36d
cloud-credential                           4.2.2     True        False         False      36d
cluster-autoscaler                         4.2.2     True        False         False      36d
console                                    4.2.2     True        False         False      38m
dns                                        4.2.2     True        False         False      36d
image-registry                             4.2.2     True        False         False      41m
ingress                                    4.2.2     True        False         False      36d
insights                                   4.2.2     True        False         False      36d
kube-apiserver                             4.2.2     True        False         False      36d
kube-controller-manager                    4.2.2     True        False         False      36d
kube-scheduler                             4.2.2     True        False         False      36d
machine-api                                4.2.2     True        False         False      36d
machine-config                             4.2.2     True        False         False      36d
marketplace                                4.2.2     True        False         False      38m
monitoring                                 4.2.2     True        False         False      36m
network                                    4.2.2     True        False         False      36d
node-tuning                                4.2.2     True        False         False      36m
openshift-apiserver                        4.2.2     True        False         False      36m
openshift-controller-manager               4.2.2     True        False         False      36d
openshift-samples                          4.2.2     True        False         False      57m
operator-lifecycle-manager                 4.2.2     True        False         False      36d
operator-lifecycle-manager-catalog         4.2.2     True        False         False      36d
operator-lifecycle-manager-packageserver   4.2.2     True        False         False      36m
service-ca                                 4.2.2     True        False         False      36d
service-catalog-apiserver                  4.2.2     True        False         False      36d
service-catalog-controller-manager         4.2.2     True        False         False      36d
storage                                    4.2.2     True        False         False      58m
```

#まとめ

CLIでもインターネット接続が可能な環境では簡単にアップデートが実施できました。