Code Ready Container コマンドのメモ

## メモ

* 最近よくOpenShiftのCode Ready Containerを起動して、トラブルことが多いので、メモを残す。
* この環境はRHEL8.4の上でlibvertd動かしてCRCを動かしている。

## クラスターをふっとばすとき（爆

* `cleanup`だけして、再度`setup`しても、不安な人は`~/.crc/`も吹っ飛ばす。（キャッシュが含まれる）

```bash
$ crc stop
$ crc delete
$ crc cleanup
$ rm -rf ~/.crc/*
```

## setup、start後、oc loginできないとき

* キャッシュもろともふっ飛ばして、クラスタを再構成し、入手したクレデンシャルでログインできない時がある。

```bash
$ oc login -u developer -p developer https://api.crc.testing:6443
Login failed (401 Unauthorized)
Verify you have provided correct credentials.
```

* このときは`crc`のバージョンと、`start`のときに入力したSecret（下の絵の**Copy pull secret**）のバージョンが一致していないと思われる。
* 新しい`crc`を配置し直す（バージョンアップ）するとうまくいく。`crc`はそこそこのペースでバージョン上がっているので、気をつける。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/325101/c17a7846-7314-c75d-5b7b-0a71f56896b1.png)

## クラスタの設定

メモリ情報の取得

```bash
$ crc config get memory
Configuration property 'memory' is not set. Default value is '9216'
```

メモリ情報の設定

```bash
$ crc config set memory 15625
Changes to configuration property 'memory' are only applied when the CRC instance is started.
If you already have a running CRC instance, then for this configuration change to take effect, stop the CRC instance with 'crc stop' and restart it with 'crc start'
```

CPU情報の取得

```bash
$ crc config get cpus
Configuration property 'cpus' is not set. Default value is '4'
```

設定できるパラメータたち

```bash
$ crc config --help
Modifies crc configuration properties.
Properties: 

* autostart-tray                       Automatically start the tray (true/false, default: true)
* bundle                               Bundle path (string, default '/home/openshift/.crc/cache/crc_libvirt_4.8.5.crcbundle')
* consent-telemetry                    Consent to collection of anonymous usage data (yes/no)
* cpus                                 Number of CPU cores (must be greater than or equal to '4')
* disable-update-check                 Disable update check (true/false, default: false)
* disk-size                            Total size in GiB of the disk (must be greater than or equal to '31')
* enable-cluster-monitoring            Enable cluster monitoring Operator (true/false, default: false)
* enable-experimental-features         Enable experimental features (true/false, default: false)
* host-network-access                  Allow TCP/IP connections from the CodeReady Containers VM to services running on the host (true/false, default: false)
* http-proxy                           HTTP proxy URL (string, like 'http://my-proxy.com:8443')
* https-proxy                          HTTPS proxy URL (string, like 'https://my-proxy.com:8443')
* kubeadmin-password                   User defined kubeadmin password
* memory                               Memory size in MiB (must be greater than or equal to '9216')
* nameserver                           IPv4 address of nameserver (string, like '1.1.1.1 or 8.8.8.8')
* network-mode                         Network mode (user or system)
* no-proxy                             Hosts, ipv4 addresses or CIDR which do not use a proxy (string, comma-separated list such as '127.0.0.1,192.168.100.1/24')
* proxy-ca-file                        Path to an HTTPS proxy certificate authority (CA)
* pull-secret-file                     Path of image pull secret (download from https://cloud.redhat.com/openshift/create/local)
```

## CRCのVM(RHCOS)にログイン

```bash
$ export CRC_IP=$(crc ip)
$ ssh -i ~/.crc/machines/crc/id_ecdsa core@$CRC_IP
The authenticity of host '192.168.130.11 (192.168.130.11)' can't be established.
ECDSA key fingerprint is SHA256:ey9xZqtt8/8OpelQZoXkxTC0okFaVQ+XQ3JRcbW/X0o.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.130.11' (ECDSA) to the list of known hosts.
Red Hat Enterprise Linux CoreOS 48.84.202108062347-0
  Part of OpenShift 4.8, RHCOS is a Kubernetes native operating system
  managed by the Machine Config Operator (`clusteroperator/machine-config`).

WARNING: Direct SSH access to machines is not recommended; instead,
make configuration changes via `machineconfig` objects:
  https://docs.openshift.com/container-platform/4.8/architecture/architecture-rhcos.html

---
[core@crc-5dd5m-master-0 ~]$ cat /etc/redhat-release 
Red Hat Enterprise Linux CoreOS release 4.8
```

## kubeadminのパスワードを確認する

```bash
$ crc console --credentials
To login as a regular user, run 'oc login -u developer -p developer https://api.crc.testing:6443'.
To login as an admin, run 'oc login -u kubeadmin -p sE2UG-xxxxx-xxxxx-3QUGQ https://api.crc.testing:6443'
```


追加するかも。