天天看點

運作在筆記本上的OpenShift4環境

Red Hat CodeReady Containers(crc)用于在筆記本/桌上型電腦上建構一個最小化的 OpenShift4 開發/測試環境。

開箱即用,網絡順暢的話,10分鐘就可以搞定。支援win10,macos,linux。将虛拟機和運作在虛拟機中的 OpenShift 打包提供給使用者。

基本介紹

硬體需求

4 physical CPU cores

9 GB of free memory

35 GB of storage space

支援作業系統版本

  1. Windows

    Windows 10 Fall Creators Update (version 1709) 及之後版本,早于這個的版本不支援。

    Microsoft Windows 10 Home Edition 不支援。

  2. macOS

    macOS 10.14 Mojave 及以上版本。

  3. Linux

    隻支援 Red Hat Enterprise Linux/CentOS 7.5 or newer (including 8.x versions) and on the latest two stable Fedora releases.

與 OpenShift4 标準版的差異

OpenShift4 标準版現在已經不支援單 master 方式,且标準版預設內建 prometheus,所需資源已經無法在普通的桌上型電腦或筆記本上運作。

CRC 不可用于生産環境。

CRC 沒有帶 machine-config 和 monitoring operator,及其他一些 ClusterOperator 也有删減。是以監控資料及版本更新的功能是沒有了。

CRC 的域名、網絡位址都是采用預設值,不支援自定義。需要注意與外部位址不要沖突。(官網說用的172網段,可我實際部署出來的網段是 10.217.x.x)

install on mac

我的筆記本是 macbook air,雙核1.6,16G 記憶體。可以正常運作,啟動 OpenShift 後 CPU 基本拉滿了, air的 CPU 太弱雞了。

安裝包下載下傳位址

https://cloud.redhat.com/openshift/create/local

安裝文檔

https://access.redhat.com/documentation/en-us/red_hat_codeready_containers/1.28/html/getting_started_guide/installation_gsg

mac 安裝很簡單,按照圖形化安裝界面的提示一路點下一步就可以了。

裝完之後在啟動裡,有個 CodeReady Containers 圖示,居然有圖形化的管理工具,比之前的版本更加友善了。

運作在筆記本上的OpenShift4環境

點選啟動後,可以通過 log 看到啟動過程

運作在筆記本上的OpenShift4環境

使用

虛拟機管理

虛拟機的管理可以通過圖形界面。或者 crc 指令。

➜  ~ crc status 
CRC VM:          Running
OpenShift:       Running (v4.7.13)
Disk Usage:      12.25GB of 32.74GB (Inside the CRC VM)
Cache Usage:     11.21GB
Cache Directory: /Users/feng/.crc/cache
➜  ~ crc -h     
CodeReady Containers is a tool that manages a local OpenShift 4.x cluster optimized for testing and development purposes

Usage:
  crc [flags]
  crc [command]

Available Commands:
  bundle      Manage CRC bundles
  cleanup     Undo config changes
  config      Modify crc configuration
  console     Open the OpenShift Web Console in the default browser
  delete      Delete the OpenShift cluster
  help        Help about any command
  ip          Get IP address of the running OpenShift cluster
  oc-env      Add the 'oc' executable to PATH
  podman-env  Setup podman environment
  setup       Set up prerequisites for the OpenShift cluster
  start       Start the OpenShift cluster
  status      Display status of the OpenShift cluster
  stop        Stop the OpenShift cluster
  version     Print version information

Flags:
  -h, --help               help for crc
      --log-level string   log level (e.g. "debug | info | warn | error") (default "info")

Use "crc [command] --help" for more information about a command.
➜  ~ 
           

OpenShift 管理

使用者與叢集狀态

内置了兩個預設使用者 kubeadmin 和 developer

在圖形界面的 “Copy OC Login Command” 按鈕下可以選擇兩個使用者的登入指令,包含使用者名密碼,和api 位址。

oc login -u kubeadmin -p iVXn9-7iCrj-26yHs-vNoP5 https://api.crc.testing:6443
oc login -u developer -p developer https://api.crc.testing:6443
           

或者用 crc console --credentials 指令也可以擷取以上資訊

oc 指令檢視叢集資訊,單節點。

➜  ~ oc get node
 oNAME                 STATUS   ROLES           AGE    VERSION
crc-pkjt4-master-0   Ready    master,worker   7d7h   v1.20.0+df9c838

➜  ~  oc get co
NAME                                       VERSION   AVAILABLE   PROGRESSING   DEGRADED   SINCE
authentication                             4.7.13    True        False         False      11h
config-operator                            4.7.13    True        False         False      7d7h
console                                    4.7.13    True        False         False      7d6h
dns                                        4.7.13    True        False         False      12h
etcd                                       4.7.13    True        False         False      7d7h
image-registry                             4.7.13    True        False         False      12h
ingress                                    4.7.13    True        False         False      7d7h
kube-apiserver                             4.7.13    True        False         False      7d7h
kube-controller-manager                    4.7.13    True        False         False      7d7h
kube-scheduler                             4.7.13    True        False         False      7d7h
machine-approver                           4.7.13    True        False         False      7d7h
marketplace                                4.7.13    True        False         False      22m
network                                    4.7.13    True        False         False      7d7h
node-tuning                                4.7.13    True        False         False      12h
openshift-apiserver                        4.7.13    True        False         False      12h
openshift-controller-manager               4.7.13    True        False         False      12h
openshift-samples                          4.7.13    True        False         False      7d7h
operator-lifecycle-manager                 4.7.13    True        False         False      7d7h
operator-lifecycle-manager-catalog         4.7.13    True        False         False      7d7h
operator-lifecycle-manager-packageserver   4.7.13    True        False         False      21m
service-ca                                 4.7.13    True        False         False      7d7h
           

跟我标準版 OpenShift4 對比,少了十個預設 operator

[[email protected] ~]# oc get co
NAME                                       VERSION   AVAILABLE   PROGRESSING   DEGRADED   SINCE
authentication                             4.7.5     True        False         False      44m
baremetal                                  4.7.5     True        False         False      4h26m
cloud-credential                           4.7.5     True        False         False      4h52m
cluster-autoscaler                         4.7.5     True        False         False      4h21m
config-operator                            4.7.5     True        False         False      4h26m
console                                    4.7.5     True        False         False      10m
csi-snapshot-controller                    4.7.5     True        False         False      3h43m
dns                                        4.7.5     True        False         False      4h19m
etcd                                       4.7.5     True        False         False      4h23m
image-registry                             4.7.5     True        False         False      4h16m
ingress                                    4.7.5     True        False         False      3h52m
insights                                   4.7.5     True        False         False      4h18m
kube-apiserver                             4.7.5     True        False         False      4h19m
kube-controller-manager                    4.7.5     True        False         False      4h19m
kube-scheduler                             4.7.5     True        False         False      4h22m
kube-storage-version-migrator              4.7.5     True        False         False      3h53m
machine-api                                4.7.5     True        False         False      4h21m
machine-approver                           4.7.5     True        False         False      4h24m
machine-config                             4.7.5     True        False         False      4h16m
marketplace                                4.7.5     True        False         False      4h22m
monitoring                                 4.7.5     True        False         False      7s
network                                    4.7.5     True        False         False      4h26m
node-tuning                                4.7.5     True        False         False      4h21m
openshift-apiserver                        4.7.5     True        False         False      45m
openshift-controller-manager               4.7.5     True        False         False      4h20m
openshift-samples                          4.7.5     True        False         False      42m
operator-lifecycle-manager                 4.7.5     True        False         False      4h21m
operator-lifecycle-manager-catalog         4.7.5     True        False         False      4h21m
operator-lifecycle-manager-packageserver   4.7.5     True        False         False      47m
service-ca                                 4.7.5     True        False         False      4h26m
storage                                    4.7.5     True        False         False      4h26m


           

Web Console

打開 web console 通過圖形界面的“Open Web Console” 按鈕或者指令

crc console

crc console --url

頁面和 OpenShift4 标準版沒什麼差别。個别頁面會沒資料,比如監控、線上版本更新,是因為對應元件在這個版本中沒有,不影響主要功能。

運作在筆記本上的OpenShift4環境

測試應用釋出

釋出一個tomcat 測試下。我們是在虛拟機外面通過 oc 指令連接配接 OpenShift 叢集,是以是不能直接通路到 pod ip的

需要建立svc,route

➜  ~ oc create deploy tomtest --image=docker.io/tomcat

➜  ~ oc get pod -o wide
NAME                       READY   STATUS    RESTARTS   AGE   IP            NODE                 NOMINATED NODE   READINESS GATES
tomtest-76d6788777-snl7x   1/1     Running   0          20m   10.217.0.52   crc-pkjt4-master-0   <none>           <none>

# 給tomcat 建一個 index 檔案
➜  ~ oc rsh tomtest-76d6788777-snl7x 
~# bash
[email protected]:/usr/local/tomcat# cd webapps
[email protected]:/usr/local/tomcat/webapps# mkdir ROOT
[email protected]:/usr/local/tomcat/webapps# echo 123 > ROOT/index.html

➜  ~ oc expose deploy tomtest --port=8080
➜  ~ oc expose svc tomtest  

➜  ~ oc get route
NAME           HOST/PORT                               PATH   SERVICES       
tomtest        tomtest-default.apps-crc.testing               tomtest        8080                     None
           

通路一下,傳回了我們上面輸入到 index.html 的内容“123”。用浏覽器也一樣。

➜  ~ curl tomtest-default.apps-crc.testing
123
           

寫在最後,建議你的電腦最好有4核,我的筆記本現在有點燙手。。。或許我應該煎個雞蛋來做宵夜。

繼續閱讀