在Linux中使用minikube

Minikebe

Minikube是一个轻量级Kubernetes实现,它在本地机器上创建一个VM,并部署一个只包含一个节点的简单集群。

Minikube使用Docker机器来管理Kubernetes VM,因此它得益于Docker机器使用的驱动程序插件架构,该架构提供了一种一致的方式来管理各种VM提供者。Minikube嵌入了VirtualBox和VMware Fusion驱动程序,因此不需要额外的步骤来使用它们。但是,其他驱动程序需要在主机路径中提供额外的二进制文件。

先决条件:

  1. 系统支持虚拟化技术

  2. 已安装配置KVM2或Virtualbox

  3. 已安装Docker(Docher CE 或 Docker EE)

 

--KVM2 Driver

KVM2安装(KVM2需要安装libvirt 1.3.1或更高版本和qemu-kvm)

  • Debian or Ubuntu 18.x: sudo apt install libvirt-clients libvirt-daemon-system qemu-kvm
  • Ubuntu 16.x or older: sudo apt install libvirt-bin libvirt-daemon-system qemu-kvm
  • Fedora/CentOS/RHEL: sudo yum install libvirt-daemon-kvm qemu-kvm
  • openSUSE/SLES: sudo zypper install libvirt qemu-kvm

  检查virsh版本: virsh --version

  若版本高于1.3.1则可下载预构造的KVM2 driver

curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 \
  && sudo install docker-machine-driver-kvm2 /usr/local/bin/
#查看kvm driver版本

docker-machine-driver-kvm2 version

  

--安装Docker

yum install docker -y

--安装minikube 1.2.0

curl -L minikube https://storage.googleapis.com/minikube/releases/v1.2.0/minikube-linux-amd64 -o /usr/local/bin/minikube

--安装kubectl 1.15.0

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl

--启动libvirtd服务

systemctl enable libvirtd.service
systemctl start libvirtd.service
systemctl status libvirtd.service

#将当前用户加入libvirt组
usermod -a -G libvirt $(whoami)
#切换用户有效组
newgrp libvirt

--启动minikube

minikube start --vm-driver=kvm2

#可将kvm2设置为默认driver
minikube config set vm-driver kvm2
#我的启动输出,为了出现不必要麻烦,我使用root安装的
[root@oc1657727366 ~]# minikube start --vm-driver=kvm2
😄 minikube v1.2.0 on linux (amd64)
⚠️ Please don't run minikube as root or with 'sudo' privileges. It isn't necessary.
🔥 Creating kvm2 VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
🐳 Configuring environment for Kubernetes v1.15.0 on Docker 18.09.6
💾 Downloading kubeadm v1.15.0
💾 Downloading kubelet v1.15.0
🚜 Pulling images ...
🚀 Launching Kubernetes ... 
⌛ Verifying: apiserver proxy etcd scheduler controller dns
🏄 Done! kubectl is now configured to use "minikube"

#查看minikube状态

[root@oc1657727366 ~]# minikube status
host: Running
kubelet: Running
apiserver: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.39.42

  

--minikube使用

 
#创建一个名为my-nginx的deployment
[root@oc1657727366 ~]# kubectl create deployment --image=nginx my-nginx
deployment.apps/my-nginx created


#查看pod列表
[root@oc1657727366 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
my-nginx-f969cff84-kcc49 1/1 Running 0 6m21s


#查看已建立的deployment
[root@oc1657727366 ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
my-nginx 1/1 1 1 7m19s


#扩展nginx pod数量到两个
[root@oc1657727366 ~]# kubectl scale deployment --replicas 2 my-nginx
deployment.extensions/my-nginx scaled


#再次查看pod列表
[root@oc1657727366 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
my-nginx-f969cff84-c92vj 1/1 Running 0 9s
my-nginx-f969cff84-kcc49 1/1 Running 0 9m28s
#通过minikube打开dashboard
[root@oc1657727366 ~]# minikube dashboard
🤔 Verifying dashboard health ...
🚀 Launching proxy ...
🤔 Verifying proxy health ...
🎉 Opening http://127.0.0.1:43575/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/ in your default browser...
START /usr/bin/google-chrome-stable "http://127.0.0.1:43575/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/"
[18070:18070:0717/193410.832958:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

 

--其他

# 查看集群的所有资源
kubectl get all
kubectl get all -o wide

# 进入节点服务器
minikube ssh

# 执行节点服务器命令,例如查看节点 docker info
minikube ssh -- docker info

# 删除集群
minikube delete

# 关闭集群
minikube stop
#进入节点服务器后可以查看当前docker服务,开启容器交互模式终端
[root@oc1657727366 ~]# minikube ssh
                         _             _            
            _         _ ( )           ( )           
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __  
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)

$ who am i
docker   pts/0        Jul 17 12:04 (192.168.39.1)
$ ip add|grep 'inet '
    inet 127.0.0.1/8 scope host lo
    inet 192.168.122.246/24 brd 192.168.122.255 scope global dynamic eth0
    inet 192.168.39.42/24 brd 192.168.39.255 scope global dynamic eth1
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
$ uname -r
4.15.0
$ cat /etc/os-release       
NAME=Buildroot
VERSION=2018.05.3
ID=buildroot
VERSION_ID=2018.05.3
PRETTY_NAME="Buildroot 2018.05.3"

$ docker ps

$ docker exec -it e86496c07070 /bin/bash

  

  

  

  

参考网站:

https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#kvm2-driver

https://github.com/kubernetes/examples/blob/master/staging/simple-nginx.md

https://xcodest.me/minikube.html

  

 

 

  

 

posted @ 2019-07-17 19:01  夏覓  Views(3072)  Comments(0Edit  收藏  举报