云网牛站
所在位置:首页 > Linux云服务器 > 使用Minishift运行本地Openshift集群的方法

使用Minishift运行本地Openshift集群的方法

2019-04-17 11:43:15作者:魏承戈稿源:云网牛站

本文介绍在Linux系统上运行Openshift OKD环境的最简单方法,使用Minishift运行本地Openshift集群的方法。

 

Minishift简介

Minishift是一个开源工具,可帮助你在VM内部本地运行单节点OpenShift集群,可以在本地主机上试用OpenShift或与它一起开发。

Minishift需要管理程序来启动配置OpenShift集群的虚拟机,我们将在Minishift设置之前安装你选择的虚拟机管理程序。

 

一、安装Hypervisor参考文章

对于Linux用户,常见的管理程序选择是KVM和VirtualBox,参考:

在Ubuntu 18.04/Debian 9上安装VirtualBox 6.0的方法

在Fedora 29/Fedora 28中安装Vagrant和Virtualbox

在CentOS 7/Ubuntu 16.04/Debian 9/SLES 12上安装KVM的方法

 

二、设置Minishift管理程序驱动程序

Minishift嵌入了VirtualBox驱动程序插件,因此无需其他步骤即可配置它,但是,KVM用户需要手动安装驱动程序插件。以下安装KVM驱动程序(适用于KVM用户)。

1、对于Fedora/CentOS:

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

2、对于Ubuntu/Debian:

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

3、对于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 1.33.0,下载:

curl -L https://github.com/minishift/minishift/releases/download/v1.33.0/minishift-1.33.0-linux-amd64.tgz -o minishift-1.33.0-linux-amd64.tgz

tar xvf minishift-1.33.0-linux-amd64.tgz

将minishift二进制文件添加到$PATH环境变量中:

sudo mv minishift-1.33.0-linux-amd64/minishift /usr/local/bin

确认安装成果,运行minishift version命令查看安装的版本:

$ minishift version

minishift v1.33.0+ba29431

 

四、开始Minishift

我们安装了所有必需的依赖项,并且我们准备使用Minishift启动单个节点的Openshift集群,请注意,此群集针对开发工作流程进行了优化。

以下步骤介绍了如何在具有KVM管理程序驱动程序的Linux操作系统上开始使用Minishift。

1.运行minishift start命令:

$ minishift start

使用Minishift运行本地Openshift集群的方法

这将进行一些检查,然后配置Minishift VM:内存4GB、vCPU是2、磁盘大小20GB。

输出如下信息:

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

为每个OpenShift集群动态生成IP,要检查IP,请运行minishift ip命令。

2.访问Openshift

可以从Web控制台或CLI访问新部署的Openshift群集,要从Web控制台进行访问,请使用群集启动后显示的URL。

可以通过Web控制台访问服务器: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.

使用Minishift运行本地Openshift集群的方法

要以管理员身份登录,帐户信息为用户名是system,密码是admin:

使用Minishift运行本地Openshift集群的方法

要从CLI操作Openshift,请继续执行下面步骤。

 

五、安装OpenShift客户端二进制文件(oc)

minishift start命令创建一个OpenShift集群并将ocbinary复制到你的主机上,该二进制文件位于~/.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 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

 

相关主题

在Ubuntu 18.04/16.04上安装和配置OpenShift Origin(OKD)的方法

精选文章
热门文章