OpenShift を試してみよう

# OpenShiftとは
Red Hat® OpenShift® はエンタープライズ対応の Kubernetes コンテナプラットフォームで、
ハイブリッドクラウドやマルチクラウドのデプロイメントを管理するフルスタックの自動運用機能を備えています。

- Red Hat OpenShift Online
- Red Hat OpenShift Container Platform
- OKD(Red Hat OpenShift Origin)

の種類があり、今回は無料で試せるOKDをVM上に展開したいと思います。

OS: CentOS7.6
メモリ: 12GB

# 構成
今回はお試しという事で、All-in-One構成という冗長構成なんて知ったもんか構成をしていきます。

# prerequisites
firewallとIPv6を無効化します。

```
# systemctl disable firewalld; systemctl stop firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

# sed -i "s/GRUB_CMDLINE_LINUX=\"/GRUB_CMDLINE_LINUX=\"ipv6.disable=1 /" /etc/default/grub; grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-957.27.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.27.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-c8c205755449484dad7e313301fab377
Found initrd image: /boot/initramfs-0-rescue-c8c205755449484dad7e313301fab377.img
done
```

# Install modules
必要なものをインストールしていきましょう。

```
# yum update

# yum install -y wget git net-tools bind-utils yum-utils iptables-services bridge-utils bash-completion kexec-tools sos psacct

# yum -y install epel-release

# yum -y --enablerepo=epel install ansible pyOpenSSL

# yum install -y docker
```

# Install OpenShift
それでは、今回のメインのOpenShiftを入れていきましょう。

```
# git clone https://github.com/openshift/openshift-ansible

# cd openshift-ansible

# ls
BUILD.md         HOOKS.md  OWNERS     README_CONTAINER_IMAGE.md  docs  images     openshift-ansible.spec  requirements.txt  setup.cfg  test                   tox.ini
CONTRIBUTING.md  LICENSE   README.md  ansible.cfg                hack  inventory  playbooks               roles             setup.py   test-requirements.txt

# git checkout release-3.11

# ls
BUILD.md             HOOKS.md  README.md                             ansible.cfg  examples  inventory               playbooks         roles      test
CONTRIBUTING.md      LICENSE   README_CONTAINERIZED_INSTALLATION.md  conftest.py  hack      meta                    pytest.ini        setup.cfg  test-requirements.txt
DEPLOYMENT_TYPES.md  OWNERS    README_CONTAINER_IMAGE.md             docs         images    openshift-ansible.spec  requirements.txt  setup.py   tox.ini
```

git checkoutをした後、lsの結果が変わったことを確認しましょう。

そのあと、構成を確認していきます。

```
# ansible-playbook -i inventory/hosts.localhost playbooks/prerequisites.yml
```

このチェックが通ったら、デプロイしていきます。

```
# ansible-playbook -i inventory/hosts.localhost playbooks/deploy_cluster.yml
```

完了したら確認しましょう

```
# oc status
In project default on server https://openshift.mydom.local:8443

https://docker-registry-default.router.default.svc.cluster.local (passthrough) (svc/docker-registry)
  dc/docker-registry deploys docker.io/openshift/origin-docker-registry:v3.11
    deployment #1 deployed 15 minutes ago - 1 pod

svc/kubernetes - 172.30.0.1 ports 443->8443, 53->8053, 53->8053

https://registry-console-default.router.default.svc.cluster.local (passthrough) (svc/registry-console)
  dc/registry-console deploys docker.io/cockpit/kubernetes:latest
    deployment #1 deployed 15 minutes ago - 1 pod

svc/router - 172.30.138.12 ports 80, 443, 1936
  dc/router deploys docker.io/openshift/origin-haproxy-router:v3.11
    deployment #1 deployed 15 minutes ago - 1 pod

View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.
```

Node数はしっかり１です笑

```
 oc get nodes
NAME                    STATUS    ROLES                  AGE       VERSION
openshift.mydom.local   Ready     compute,infra,master   1d        v1.11.0+d4cacc0
```

get allでNode上で展開されているものすべてを見ていきましょう。

```
# oc get all
NAME                           READY     STATUS    RESTARTS   AGE
pod/docker-registry-1-8mbmr    1/1       Running   0          15m
pod/registry-console-1-v7hxk   1/1       Running   0          15m
pod/router-1-8bwkf             1/1       Running   0          15m

NAME                                       DESIRED   CURRENT   READY     AGE
replicationcontroller/docker-registry-1    1         1         1         15m
replicationcontroller/registry-console-1   1         1         1         15m
replicationcontroller/router-1             1         1         1         15m

NAME                       TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                   AGE
service/docker-registry    ClusterIP   172.30.29.106   <none>        5000/TCP                  15m
service/kubernetes         ClusterIP   172.30.0.1      <none>        443/TCP,53/UDP,53/TCP     18m
service/registry-console   ClusterIP   172.30.47.210   <none>        9000/TCP                  15m
service/router             ClusterIP   172.30.138.12   <none>        80/TCP,443/TCP,1936/TCP   15m

NAME                                                  REVISION   DESIRED   CURRENT   TRIGGERED BY
deploymentconfig.apps.openshift.io/docker-registry    1          1         1         config
deploymentconfig.apps.openshift.io/registry-console   1          1         1         config
deploymentconfig.apps.openshift.io/router             1          1         1         config

NAME                                        HOST/PORT                                                   PATH      SERVICES           PORT      TERMINATION   WILDCARD
route.route.openshift.io/docker-registry    docker-registry-default.router.default.svc.cluster.local              docker-registry    <all>     passthrough   None
route.route.openshift.io/registry-console   registry-console-default.router.default.svc.cluster.local             registry-console   <all>     passthrough   None
```

下のコマンドの結果に記載されているURLにログインすることで、GUIに入れます。
user: developer
password :developer

```
oc login -u system:admin
Logged into "https://openshift.mydom.local:8443" as "system:admin" using existing credentials.

You have access to the following projects and can switch between them with 'oc project <projectname>':

  * default
    kube-public
    kube-system
    management-infra
    openshift
    openshift-infra
    openshift-logging
    openshift-monitoring
    openshift-node
    openshift-sdn

Using project "default".
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/416540/f7aefff6-d7ae-24b1-23fa-9cef4b2a6b12.png)