云网牛站
所在位置:首页 > Linux云服务器 > 使用KVM在CentOS 8/CentOS 7上安装Minikube Kubernetes

使用KVM在CentOS 8/CentOS 7上安装Minikube Kubernetes

2020-01-27 10:23:32作者:符天稿源:云网牛站

Minikube支持VirtualBox和KVM虚拟机管理程序,编写本教程是为了帮助您使用KVM Hypervisor在CentOS 8/CentOS 7系统上安装Minikube。Minikube打包并配置了Linux VM,然后将Docker和所有Kubernetes组件安装到其中,您可以通过主机系统中运行的kubectl管理和部署应用程序。在进行以下操作时,请先更新系统,运行sudo yum -y update命令。

 

步骤1:安装KVM虚拟机监控程序

我们将使用KVM作为Minikube VM的首选Hypervisor,安装KVM请参考在CentOS 7/Ubuntu 16.04/Debian 9/SLES 12上安装KVM的方法

确认libvirtd服务正在运行:

$ systemctl status libvirtd

使用KVM在CentOS 8/CentOS 7上安装Minikube Kubernetes

如果安装后未运行,请启动并将其设置为在启动时启动:

sudo systemctl enable --now libvirtd

您的用户应属于libvirt组:

sudo usermod -a -G libvirt $(whoami)

newgrp libvirt

打开文件/etc/libvirt/libvirtd.conf进行编辑:

sudo vi /etc/libvirt/libvirtd.conf

将UNIX域套接字组所有权设置为libvirt(在第85行附近):

unix_sock_group = "libvirt"

设置R/W套接字的UNIX套接字权限(在第102行附近):

unix_sock_rw_perms = "0770"

进行更改后,重新启动libvirt守护程序:

sudo systemctl restart libvirtd.service

 

步骤2:下载minikube

您需要下载minikube二进制文件,我将把二进制文件放在/usr/local/bin目录下,因为它位于$PATH中:

sudo yum -y install wget

wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

chmod +x minikube-linux-amd64

sudo mv minikube-linux-amd64 /usr/local/bin/minikube

确认在系统上安装了Minikube:

$ minikube version

minikube version: v1.6.2

 

步骤3:安装kubectl

我们需要kubectl,这是用于在Kubernetes上部署和管理应用程序的命令行工具:

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

给文件可执行文件位,然后移到PATH中的某个位置:

chmod +x kubectl

sudo mv kubectl  /usr/local/bin/

确认安装的kubectl版本:

$ kubectl version -o json

{

"clientVersion": {

"major": "1",

"minor": "17",

"gitVersion": "v1.17.1",

"gitCommit": "d224476cd0730baca2b6e357d144171ed74192d6",

"gitTreeState": "clean",

"buildDate": "2020-01-14T21:04:32Z",

"goVersion": "go1.13.5",

"compiler": "gc",

"platform": "linux/amd64"

}

}

 

步骤4:启动minikube

现在已经安装了组件,您可以启动minikube,将为Kubernetes单节点群集下载并配置VM映像。

有关选项列表,请运行:

$ minikube start --help

要使用默认选项创建一个minikube VM,请运行:

$ minikube start

要使用的默认容器运行时是docker,但您也可以使用crio或containerd:

$ minikube start --container-runtime=cri

$ minikube start --container-runtime=containerd

安装程序将自动检测KVM并下载KVM驱动程序。

* minikube v1.6.2 on Centos 8.1.1911

* Automatically selected the 'kvm2' driver (alternates: [none])

* Downloading driver docker-machine-driver-kvm2:

> docker-machine-driver-kvm2.sha256: 65 B / 65 B [-------] 100.00% ? p/s 0s

> docker-machine-driver-kvm2: 13.86 MiB / 13.86 MiB  100.00% 791.09 KiB p/s

* Downloading VM boot image ...

如果您有多个管理程序,请指定它:

$ minikube start --vm-driver kvm2

请注意,已安装最新的Kubernetes稳定版本,使用--kubernetes-version选项指定要安装的版本,例:

--kubernetes-version='1.16.5'

等待下载和设置完成,然后确认一切正常:

$ minikube start

* minikube v1.6.2 on Centos 8.1.1911

* Automatically selected the 'kvm2' driver (alternates: [none])

* Downloading driver docker-machine-driver-kvm2:

> docker-machine-driver-kvm2.sha256: 65 B / 65 B [-------] 100.00% ? p/s 0s

> docker-machine-driver-kvm2: 13.86 MiB / 13.86 MiB  100.00% 791.09 KiB p/s

* Downloading VM boot image ...

> minikube-v1.6.0.iso.sha256: 65 B / 65 B [--------------] 100.00% ? p/s 0s

> minikube-v1.6.0.iso: 150.93 MiB / 150.93 MiB [] 100.00% 1.27 MiB p/s 2m0s

* Creating kvm2 VM (CPUs=2, Memory=2000MB, Disk=20000MB) ...

* Preparing Kubernetes v1.17.0 on Docker '19.03.5' ...

* Downloading kubelet v1.17.0

* Downloading kubeadm v1.17.0

* Pulling images ...

* Launching Kubernetes ... 

* Waiting for cluster to come online ...

* Done! kubectl is now configured to use "minikube"

 

步骤5:Minikube基本操作

kubectl命令行工具配置为使用“minikube”。

要检查集群状态,请运行:

$ kubectl cluster-info

Kubernetes master is running at https://192.168.39.2:8443

KubeDNS is running at https://192.168.39.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

要进一步调试和诊断集群问题,请使用“kubectl cluster-info dump”。

您的Minikube配置文件位于~/.minikube/machines/minikube/config.json下。

要查看配置,请使用:

$ kubectl config view

apiVersion: v1

clusters:

- cluster:

certificate-authority: /home/jkmutai/.minikube/ca.crt

server: https://192.168.39.2:8443

name: minikube

contexts:

- context:

cluster: minikube

user: minikube

name: minikube

current-context: minikube

kind: Config

preferences: {}

users:

- name: minikube

user:

client-certificate: /home/jkmutai/.minikube/client.crt

client-key: /home/jkmutai/.minikube/client.key

要检查正在运行的nodes:

$ kubectl get nodes

使用KVM在CentOS 8/CentOS 7上安装Minikube Kubernetes

使用ssh访问minikube VM:

$ minikube ssh

使用KVM在CentOS 8/CentOS 7上安装Minikube Kubernetes

$ sudo su -

要停止正在运行的本地kubernetes集群,请运行:

$ minikube stop

* Stopping "minikube" in kvm2 ...

* "minikube" stopped.

要启动VM,请运行:

$ minikube start

* minikube v1.6.2 on Centos 8.1.1911

* Selecting 'kvm2' driver from existing profile (alternates: [none])

* Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.

* Starting existing kvm2 VM for "minikube" ...

* Waiting for the host to be provisioned ...

* Preparing Kubernetes v1.17.0 on Docker '19.03.5' ...

* Launching Kubernetes ... 

* Done! kubectl is now configured to use "minikube"

要删除本地kubernetes集群,请使用:

$ minikube delete

 

步骤6:启用Kubernetes仪表板

Kubernetes随附有Web仪表板,可让您在不与命令行交互的情况下管理集群,仪表板插件在minikube上默认安装并启用:

$ minikube addons list

- addon-manager: enabled

- coredns: disabled

- dashboard: enabled

- default-storageclass: enabled

- efk: disabled

- freshpod: disabled

- heapster: disabled

- ingress: disabled

- kube-dns: enabled

- metrics-server: disabled

- registry: disabled

- registry-creds: disabled

- storage-provisioner: enabled

要直接在默认浏览器上打开,请使用:

$ minikube dashboard

获取仪表板的URL:

$ minikube dashboard --url

http://192.168.39.117:30000

然后通过在您喜欢的浏览器上打开URL来访问Kubernetes仪表板。到这里,使用KVM在CentOS 8/CentOS 7系统上安装Minikube Kubernetes的操作步骤全部完成了。

 

相关主题

在Ubuntu 18.04系统上安装Minikube的步骤

精选文章
热门文章