Fork me on GitHub

Minikube之CentOS单机部署

前言

方便自己快速搭建并体验Kubernetes。

部署环境

1
2
3
4
5
6
# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
# uname -r
3.10.0-327.el7.x86_64
# uname -m
x86_64

先决条件

  • kubectl
  • macOS
    Hyperkit driver, xhyve driver, VirtualBox, or VMware Fusion
  • Linux
    VirtualBox or KVM
    NOTE: Minikube also supports a –vm-driver=none option that runs the Kubernetes components on the host and not in a VM. Docker is required to use this driver but no hypervisor.
  • Windows
    VirtualBox or Hyper-V
  • VT-x/AMD-v virtualization must be enabled in BIOS
  • Internet connection on first run

安装kubectl

安装kubectl

1
2
3
# wget https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl
# install kubectl /usr/local/bin/
# kubectl cluster-info

设置shell命令补全

1
2
3
4
5
6
7
8
# yum install -y bash-completion
# echo "source <(kubectl completion bash)" >> ~/.bashrc
# kubectl
alpha auth config delete explain options replace set
annotate autoscale convert describe expose patch rolling-update taint
api-versions certificate cordon drain get plugin rollout top
apply cluster-info cp edit label port-forward run uncordon
attach completion create exec logs proxy scale version

安装Hypervisor(KVM)

1
2
3
4
5
6
# yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install
# systemctl enable libvirtd && systemctl start libvirtd
# wget https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.10.0/docker-machine-driver-kvm-centos7
# install docker-machine-driver-kvm-centos7 /usr/local/bin/docker-machine-driver-kvm
# usermod -a -G libvirt $(whoami)
# newgrp libvirt

安装minikube

1
2
3
4
5
6
7
# wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
# install minikube-linux-amd64 /usr/local/bin/minikube
# minikube config set WantReportErrorPrompt false
# minikube start --vm-driver=kvm
# kubectl version
# kubectl cluster-info
# kubectl get all

应用案例

1
2
3
4
5
6
7
8
9
10
11
# kubectl get nodes
NAME STATUS ROLES AGE VERSION
linux-node9.example.com Ready <none> 42m v1.8.0
# kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8080
deployment "hello-minikube" created
# kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-minikube-7844bdb9c6-k2sc6 0/1 ContainerCreating 0 14s
# kubectl delete service hello-minikube
service "hello-minikube" deleted
# minikube stop

FQA

1、minikube启动报错

1
2
3
4
5
6
7
[root@linux-node9 ~]# minikube start --vm-driver=kvm
Starting local Kubernetes v1.8.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
E0109 21:27:08.534646 4014 start.go:223] Error updating cluster: Error updating localkube from uri: Error creating localkube asset from url: Error opening file asset: /root/.minikube/cache/localkube/localkube-v1.8.0: open /root/.minikube/cache/localkube/localkube-v1.8.0: no such file or directory
E0109 21:27:20.094253 4014 util.go:151] Error uploading error message: : Post https://clouderrorreporting.googleapis.com/v1beta1/projects/k8s-minikube/events:report?key=AIzaSyACUwzG0dEPcl-eOgpDKnyKoUFgHdfoFuA: read tcp 192.168.56.109:48666->172.217.24.10:443: read: connection reset by peer

解决:

1
# minikube config set WantReportErrorPrompt false

参考资料

Minikube
KVM_Virtualization_in_RHEL_7_Made_Easy

======================================================
希望各位朋友支持一下

本文作者:dongsheng
本文地址https://mds1455975151.github.io/archives/5e6f338.html
版权声明:转载请注明出处!

坚持技术分享,您的支持将鼓励我继续创作!