如何使用Minishift运行本地Openshift集群
本文旨在引导我们完成在Linux系统上获得运行Openshift OKD环境的最简单方法。
在之前的教程中,我们介绍了在Ubuntu上安装Openshift Container平台。这里,我们将重点介绍在任何Linux系统上运行Local Openshift集群的通用方法。
什么是Minishift?
Minishift是一种开源工具,可在VM内部本地运行单节点OpenShift集群。我们可以在本地主机上尝试OpenShift或者每天进行开发。
Minishift要求管理程序启动在其上配置了OpenShift群集的虚拟机。我们将在安装Minishift之前先安装我们选择的管理程序。
安装Hypervisor
对于Linux用户,常见的管理程序选择是KVM和VirtualBox。查看以下教程:
如何在Fedora,Kali Linux,Linux Mint,Ubuntu 18.04/16.04/Debian 9上安装VirtualBox
如何在RHEL/CentOS 8,Fedora,Arch Linux,CentOS,Ubuntu/Debian,SLES上安装KVM
设置Minishift虚拟机监控程序驱动程序
Minishift嵌入了VirtualBox驱动程序插件,因此无需其他步骤即可对其进行配置。但是,KVM用户需要手动安装驱动程序插件。
安装KVM驱动程序(对于KVM用户)
对于Ubuntu/Debian
sudo usermod -a -G libvirt $(whoami) newgrp libvirt || newgrp libvirtd curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.10.0/docker-machine-driver-kvm-ubuntu16.04 -o docker-machine-driver-kvm sudo mv docker-machine-driver-kvm /usr/local/bin/docker-machine-driver-kvm sudo chmod +x /usr/local/bin/docker-machine-driver-kvm
对于Fedora/CentOS
sudo usermod -a -G libvirtd $(whoami) newgrp libvirt curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.10.0/docker-machine-driver-kvm-centos7 -o docker-machine-driver-kvm sudo mv docker-machine-driver-kvm /usr/local/bin/docker-machine-driver-kvm sudo chmod +x /usr/local/bin/docker-machine-driver-kvm
对于Arch Linux/Manjaro
sudo usermod -a -G kvm,libvirt $(whoami) sudo sed -ri 's/.?group\s?=\s?".+"/group = "kvm"/1' /etc/libvirt/qemu.conf newgrp libvirt curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.10.0/docker-machine-driver-kvm-centos7 -o docker-machine-driver-kvm sudo mv docker-machine-driver-kvm /usr/local/bin/docker-machine-driver-kvm chmod +x /usr/local/bin/docker-machine-driver-kvm
启动默认的KVM网络。
sudo virsh net-start default sudo virsh net-autostart default
安装Minishift
从" Minishift版本"页面下载适用于操作系统的存档,然后解压缩其内容。
export VER="1.34.1" curl -L https://github.com/minishift/minishift/releases/download/v$VER/minishift-$VER-linux-amd64.tgz -o minishift-$VER-linux-amd64.tgz tar xvf minishift-$VER-linux-amd64.tgz
将minishift二进制文件添加到$PATH环境变量中。
sudo mv minishift-$VER-linux-amd64/minishift /usr/local/bin
确认安装。
$minishift version minishift v1.34.1+c2ff9cb
启动Minishift
我们已经安装了所有必需的依赖项,并准备使用Minishift启动单个节点Openshift集群。请注意,此集群针对开发工作流程进行了优化。
以下步骤描述了如何在具有KVM虚拟机管理程序驱动程序的Linux操作系统上使用Minishift。
1 ..运行minishift start命令:
$minishift start
这将进行大量检查,然后为Minishift VM提供以下配置:内存:4 GB vCPU:2磁盘大小:20 GB
输出示例:
-- Starting Minishift VM .................. OK -- Checking for IP address ... OK -- Checking for nameservers ... OK -- Checking if external host is reachable from the Minishift VM ... Pinging 8.8.8.8 ... OK -- Checking HTTP connectivity from the VM ... Retrieving http://minishift.io/index.html ... OK -- Checking if persistent storage volume is mounted ... OK -- Checking available disk space ... 1% used OK -- Writing current configuration for static assignment of IP address ... WARN Importing 'openshift/origin-control-plane:v3.11.0' CACHE MISS Importing 'openshift/origin-docker-registry:v3.11.0' CACHE MISS Importing 'openshift/origin-haproxy-router:v3.11.0' CACHE MISS -- OpenShift cluster will be configured with ... Version: v3.11.0 -- Pulling the OpenShift Container Image ................................................ OK -- Copying oc binary from the OpenShift container image to VM ... OK -- Starting OpenShift cluster ......................................................................................... Getting a Docker client ... Checking if image openshift/origin-control-plane:v3.11.0 is available ... Pulling image openshift/origin-cli:v3.11.0 .......................................... Login to server ... Creating initial project "myproject" ... Server Information ... OpenShift server started. The server is accessible via web console at: https://192.168.42.106:8443/console You are logged in as: User: developer Password: <any value> To login as administrator: oc login -u system:admin -- Exporting of OpenShift images is occuring in background process with pid 11207.
如果我们正在运行VirtualBox,则在启动Minishift VM时使用--vm-driver virtualbox
标志。
$minishift start --vm-driver virtualbox
要进行持久配置,以便我们运行minishift start而不每次都显式传递vm-driver virtualbox标志,请运行:
$minishift config set vm-driver virtualbox
IP是为每个OpenShift集群动态生成的。要检查IP,请运行minishift ip命令。
访问Openshift
我们可以从Web控制台或者CLI访问新部署的Openshift群集。要从Web控制台访问,请使用群集启动后显示的URL。
The server is accessible via web console at: https://192.168.42.106:8443/console
启动Minishift后,可以在shell程序中运行以下命令以获取Web控制台的URL:
$minishift console --url https://192.168.42.106:8443/console
或者,启动Minishift后,可以使用以下命令在浏览器中直接打开控制台:
$minishift console Opening the OpenShift Web console in the default browser… [16398:16398:0416/224729.206639:ERROR:sandbox_linux.cc(364)] InitializeSandbox() called with multiple threads in process gpu-process. [16359:16381:0416/224729.313961:ERROR:browser_process_sub_thread.cc(209)] Waited 5 ms for network service Opening in existing browser session.
要以管理员身份登录,请使用:
Username: system Password: admin
要从CLI运行Openshift,请继续执行。
安装OpenShift Client Binary(oc)
minishift start命令创建一个OpenShift集群并将oc二进制文件复制到主机上。该二进制文件位于~/.minishift/cache/oc/v(VER)目录中。我们需要将其复制到/usr/local/bin中,以供所有用户访问。
sudo cp ~/.minishift/cache/oc/v3.11.0/linux/oc /usr/local/bin
或者,我们可以使用minishift oc-env将此二进制文件添加到PATH中,该文件显示我们需要在shell中执行的命令。
$minishift oc-env export PATH="/home/jmutai/.minishift/cache/oc/v3.11.0/linux:$PATH" # Run this command to configure your shell: # eval $(minishift oc-env)
检查它是否正常工作。
$oc version oc v3.11.0+0cbc58b kubernetes v1.11.0+d4cacc0 features: Basic-Auth GSSAPI Kerberos SPNEGO Server https://192.168.42.106:8443 kubernetes v1.11.0+d4cacc0
这将告诉我们服务器的IP地址和端口。要以管理员身份登录,请使用系统帐户:
$oc login -u system:admin Logged into "https://192.168.42.106:8443" as "system:admin" using existing credentials. You have access to the following projects and can switch between them with 'oc project ': default kube-dns kube-proxy kube-public kube-system myproject openshift openshift-apiserver openshift-controller-manager openshift-core-operators openshift-infra openshift-node openshift-service-cert-signer openshift-web-console Using project "myproject".
用于访问的客户端证书存储在~/.kube/config中
要查看可用的登录上下文,请运行:
$oc config view apiVersion: v1 clusters: cluster: certificate-authority-data: REDACTED server: https://192.168.42.106:8443 name: 192-168-42-106:8443 contexts: context: cluster: 192-168-42-106:8443 namespace: myproject user: developer/192-168-42-106:8443 name: minishift context: cluster: 192-168-42-106:8443 namespace: myproject user: developer/192-168-42-106:8443 name: myproject/192-168-42-106:8443/developer context: cluster: 192-168-42-106:8443 namespace: myproject user: system:admin/192-168-42-106:8443 name: myproject/192-168-42-106:8443/system:admin current-context: myproject/192-168-42-106:8443/system:admin kind: Config preferences: {} users: name: developer/192-168-42-106:8443 user: token: QdSKNK5DbaLA2AOFM__8-_fJ-Pt7BikZP1uFwsqyNx0 name: system:admin/192-168-42-106:8443 user: client-certificate-data: REDACTED client-key-data: REDACTED
停止Minishift
要停止Openshift集群和Minishift VM,请运行:
$minishift stop Stopping the OpenShift cluster… Cluster stopped.
我们可以通过运行任何时间重新启动OpenShift集群
$minishift start