在Mac上安装OpenShift 4
总结
在 Mac 上安装 OpenShift 3.x 系列可以使用 Red Hat Container Development Kit (CDK) 或 Minishift,但从 OpenShift 4.x 系列开始,安装方法已经改变了。
现在通过使用 Code Ready Containers (CRC),可以在 Mac 上安装 OpenShift 4.1。
系统需求
行动环境
以下是MacBook Pro的信息。
$ system_profiler SPHardwareDataType
Model Name: MacBook Pro
Model Identifier: MacBookPro14,3
Processor Name: Intel Core i7
Processor Speed: 2.9 GHz
Number of Processors: 1
Total Number of Cores: 4
Memory: 16 GB
以下内容是在完成安装后获取的。
$ crc version
version: 1.0.0-beta.3-4.1.11+e97bf65
$ oc version
Client Version: v4.2.0
Server Version: 4.1.11
Kubernetes Version: v1.13.4+df9cebc
安装Code Ready Containers(CRC)。
在下载之前,需要创建一个Red Hat Developer账户。
从cloud.redhat.com上的下载源下载.tar.xz文件。
下载后,使用tar xvf解压,并设置路径。
在下述情况中,已经将crc文件移动到经过路径设置的目录中。
$ tar xvf crc-macos-amd64.tar.xz
x crc-macos-1.0.0-beta.3-amd64/
x crc-macos-1.0.0-beta.3-amd64/LICENSE
x crc-macos-1.0.0-beta.3-amd64/doc.pdf
x crc-macos-1.0.0-beta.3-amd64/crc
$ mv crc-macos-1.0.0-beta.3-amd64/crc /usr/local/bin/.
CRC的环境配置
我会在crc setup中进行环境设置。
将会创建一个~/.crc目录。
$ crc setup
INFO Caching oc binary
INFO Setting up virtualization with HyperKit
Password:
INFO Installing crc-machine-hyperkit
INFO Setting file permissions for /etc/resolver/testing
INFO Setting file permissions for /etc/hosts
INFO Unpacking bundle from the CRC binary
$ ls ~/.crc
bin
crc.json
crc.log
crc_hyperkit_4.1.11.crcbundle
启动OpenShift 4.1集群
当使用 crc start 命令开始时,会要求输入 Image pull 密钥。
$ crc start
INFO Checking if oc binary is cached
INFO Checking if HyperKit is installed
INFO Checking if crc-driver-hyperkit is installed
INFO Checking file permissions for /etc/resolver/testing
INFO Checking file permissions for /etc/hosts
INFO Checking if CRC bundle is cached in '$HOME/.crc'
? Image pull secret [? for help]
INFO Loading bundle: crc_hyperkit_4.1.11.crcbundle ...
INFO Extracting bundle: crc_hyperkit_4.1.11.crcbundle ...
INFO Creating VM ...
INFO Verifying validity of the cluster certificates ...
INFO Restarting the host network
INFO Check internal and public dns query ...
INFO Copying kubeconfig file to instance dir ...
INFO Adding user's pull secret and cluster ID ...
INFO Starting OpenShift cluster ... [waiting 3m]
INFO To access the cluster using 'oc', run 'eval $(crc oc-env) && oc login -u kubeadmin -p ************************ https://api.crc.testing:6443'
INFO Access the OpenShift web-console here: https://console-openshift-console.apps-crc.testing
INFO Login to the console with user: kubeadmin, password: ************************
CodeReady Containers instance is running
从执行crc start命令到完成不到10分钟。
请确认启动
确认 oc login。
执行 crc start 后在标准输出中出现了访问集群的操作,因此执行该操作。
$ 'eval $(crc oc-env) && oc login -u kubeadmin -p ************************ https://api.crc.testing:6443'
The server uses a certificate signed by an unknown authority.
You can bypass the certificate check, but any data you send to the server could be intercepted by others.
Use insecure connections? (y/n): y
Login successful.
You have access to the following projects and can switch between them with 'oc project <projectname>':
* default
kube-public
kube-system
openshift
openshift-apiserver
openshift-apiserver-operator
openshift-authentication
openshift-authentication-operator
openshift-cloud-credential-operator
openshift-cluster-machine-approver
openshift-cluster-node-tuning-operator
openshift-cluster-samples-operator
openshift-cluster-storage-operator
openshift-cluster-version
openshift-config
openshift-config-managed
openshift-console
openshift-console-operator
openshift-controller-manager
openshift-controller-manager-operator
openshift-dns
openshift-dns-operator
openshift-etcd
openshift-image-registry
openshift-infra
openshift-ingress
openshift-ingress-operator
openshift-kube-apiserver
openshift-kube-apiserver-operator
openshift-kube-controller-manager
openshift-kube-controller-manager-operator
openshift-kube-scheduler
openshift-kube-scheduler-operator
openshift-machine-api
openshift-machine-config-operator
openshift-marketplace
openshift-monitoring
openshift-multus
openshift-network-operator
openshift-node
openshift-operator-lifecycle-manager
openshift-operators
openshift-sdn
openshift-service-ca
openshift-service-ca-operator
openshift-service-catalog-apiserver-operator
openshift-service-catalog-controller-manager-operator
Using project "default".
接下来,我们尝试访问Web控制台。
在标准输出中可以找到访问Web控制台所需的动作 crc start,我们要执行这个动作。
https://console-openshift-console.apps-crc.testing
用户名:kubeadmin,密码:************************
只要屏幕输出就是确认完成了。
下一个
由于其他服务也被提供,所以我想要试试看。
$ oc get route --all-namespaces=true
NAMESPACE NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
openshift-authentication oauth-openshift oauth-openshift.apps-crc.testing oauth-openshift 6443 passthrough/Redirect None
openshift-console console console-openshift-console.apps-crc.testing console https reencrypt/Redirect None
openshift-console downloads downloads-openshift-console.apps-crc.testing downloads http edge None
openshift-image-registry default-route default-route-openshift-image-registry.apps-crc.testing image-registry <all> reencrypt None
openshift-monitoring alertmanager-main alertmanager-main-openshift-monitoring.apps-crc.testing alertmanager-main web reencrypt/Redirect None
openshift-monitoring grafana grafana-openshift-monitoring.apps-crc.testing grafana https reencrypt/Redirect None
openshift-monitoring prometheus-k8s prometheus-k8s-openshift-monitoring.apps-crc.testing prometheus-k8s web reencrypt/Redirect None
提示
在 CRC 启动时向 /etc/hosts 文件添加额外内容。
192.168.64.13 api.crc.testing oauth-openshift.apps-crc.testing
使用CRC创建的节点似乎是RHEL7.7。
$ oc get nodes
NAME STATUS ROLES AGE VERSION
crc-56mmj-master-0 Ready master,worker 21d v1.13.4+d81afa6ba
$ oc debug nodes/crc-56mmj-master-0
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.7 (Maipo)
故障排除
某次出现了证书过期的错误。
错误发生:证书已过期,有效期至:2019年9月23日12时25分 +0000。
仔细阅读指南后,似乎在30天后过期。
您正在使用最新的 CodeReady Containers 发布版本。嵌入式系统镜像包生成的证书在 30 天后过期。使用较旧的系统镜像包可能导致与过期的 x509 证书相关的错误。
在提交日志中有关于如何处理的说明。简而言之,只需要将最新的 crc 替换掉,然后再次进行 Code Ready Containers(CRC) 的安装。
$ crc version
$ crc version
version: 1.0.0-beta.5+f2aa58c
OpenShift version: 4.1.14 (embedded in binary)
升级后,上述错误已得到解决。
参考
以下是两篇关于“Red Hat CodeReady Containers在本地运行OpenShift 4”的文章:
– Red Hat Developer官方博客发布的文章可在以下链接找到:https://developers.redhat.com/blog/2019/09/05/red-hat-openshift-4-on-your-laptop-introducing-red-hat-codeready-containers/
– Jeff Geerling个人博客发布的文章可在以下链接找到:https://www.jeffgeerling.com/blog/2019/trying-out-crc-code-ready-containers-run-openshift-4x-locally
有一个视频在YouTube上。