检查kvm模块是否安装
[root@localhost ~]# lsmod |grep kvm
kvm_intel 55496 32
kvm 337772 1 kvm_intel

安装 virtualbox

添加 repo配置文件,/etc/yum.repos.d/virtualbox.repo

[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc

运行
yum install -y VirtualBox-6.0

安装kubectl

添加 repo配置文件,/etc/yum.repos.d/kubernetes.repo

[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

运行:
yum install -y kubectl

若出现以下错误

Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 13332.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: PackageKit
    Memory :  92 M RSS (505 MB VSZ)

运行:
rm -f /var/run/yum.pid,
重新 yum install -y kubectl

安装 minikube
   curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 
   #install 会自动添加可执行属性
   install minikube-linux-amd64 /usr/local/bin/minikube

如果出现以下错误

-bash: /usr/local/bin/minikube: cannot execute binary file

有可能是可执行文件没有完全下载下来所致

运行minikube
minikube start

如果出现以下错误

-   Pulling images required by Kubernetes v1.14.0 ...
X   Unable to pull images, which may be OK: running cmd: sudo kubeadm config images pull --config /var/lib/kubeadm.yaml: command failed: sudo kubeadm config images pull --config /var/lib/kubeadm.yaml
stdout: 
stderr: failed to pull image "k8s.gcr.io/kube-apiserver:v1.14.0": output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
, error: exit status 1
: Process exited with status 1

则需要设置HTTP 代理

export HTTP_PROXY=http://xxx:{port}
export HTTPS_PROXY=http://xxx:{port}

如果出现以下错误

:   Waiting for pods: apiserver
!   Error starting cluster: wait: waiting for component=kube-apiserver: timed out waiting for the condition

*   Sorry that minikube crashed. If this was unexpected, we would love to hear from you:
-   https://github.com/kubernetes/minikube/issues/new
X   Problems detected in "kube-addon-manager":
    - error: no objects passed to apply
    - error: no objects passed to apply
    - error: no objects passed to apply
  

则需要设置NO_PROXY

export NO_PROXY=localhost,127.0.0.1,10.96.0.0/12,192.168.99.0/24,192.168.39.0/24

所以, minikube 综合启动命令为

minikube start --docker-env=HTTP_PROXY=$HTTP_PROXY --docker-env HTTPS_PROXY=$HTTPS_PROXY \
  --docker-env NO_PROXY=$NO_PROXY

正确的response

o   minikube v1.0.0 on linux (amd64)
$   Downloading Kubernetes v1.14.0 images in the background ...
i   Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
:   Re-using the currently running virtualbox VM for "minikube" ...
:   Waiting for SSH access ...
-   "minikube" IP address is 192.168.99.102
o   Found network options:
    - HTTP_PROXY=http://child-prc.intel.com:913
    - HTTPS_PROXY=http://child-prc.intel.com:913
    - NO_PROXY=localhost,127.0.0.1,10.96.0.0/12,192.168.99.0/24,192.168.39.0/24
-   Configuring Docker as the container runtime ...
    - env HTTP_PROXY=http://child-prc.intel.com:913
    - env HTTPS_PROXY=http://child-prc.intel.com:913
    - env NO_PROXY=localhost,127.0.0.1,10.96.0.0/12,192.168.99.0/24,192.168.39.0/24
-   Version of container runtime is 18.06.2-ce
:   Waiting for image downloads to complete ...
-   Preparing Kubernetes environment ...
-   Pulling images required by Kubernetes v1.14.0 ...
:   Relaunching Kubernetes v1.14.0 using kubeadm ... 
:   Waiting for pods: apiserver proxy etcd scheduler controller dns
:   Updating kube-proxy configuration ...
-   Verifying component health ......
+   kubectl is now configured to use "minikube"
=   Done! Thank you for using minikube!

运行 kubectl 命令

cmd : kubectl cluster-info
response:

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

kubectl get nodes

NAME       STATUS   ROLES    AGE     VERSION
minikube   Ready    master   2m46s   v1.14.0

Logo

开源、云原生的融合云平台

更多推荐