单核小鸡上的 Minikube 实践(一)
零,写在前面
首发自我的博客得寸进尺。刚刚开始试着坚持写博客,欢迎大家也去逛逛。
先大概说一下这次用来实验的服务器的状态:
服务器是白嫖的国内某厂商的一个月试用版,申请之后一直也没有排上用场,今天想着闲着也是闲着就拿来试试之前自己在黑苹果>上失败了无数次的 minikube 的安装...
服务器的配置入下:
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:30:48]
$ uname -a
Linux VM-253eb12c-e466-4202-b8eb-7892ae3ed8db 4.9.0-4-amd64 #1 SMP Debian 4.9.51-1 (2017-09-28) x86_64 GNU/Linux
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:31:06]
$ head -n 1 /etc/issue
Debian GNU/Linux 9 \n \l
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:31:10]
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 79
model name : Intel(R) Xeon(R) CPU E5-2683 v4 @ 2.10GHz
stepping : 1
microcode : 0xb00002a
cpu MHz : 2098.882
cache size : 40960 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm rdseed adx smap xsaveopt arat
bugs :
bogomips : 4199.99
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management:
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:31:14]
$ free -m
total used free shared buff/cache available
Mem: 978 763 58 0 156 80
Swap: 4095 383 3712
接下来就开始安装 minikube 了
docker 相关的安装,大家应该都很熟悉这次就不写了
一,安装 Minukube
1.安装 kubectl
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools [17:50:52] C:130
$ wget "https://storage.googleapis.com/kubernetes-release/release/v1.18.1/bin/linux/amd64/kubectl" -O "/usr/local/bin/kubectl"
--2020-04-13 17:50:57-- https://storage.googleapis.com/kubernetes-release/release/v1.18.1/bin/linux/amd64/kubectl
Resolving storage.googleapis.com (storage.googleapis.com)... 34.64.4.112, 2404:6800:4008:801::2010
Connecting to storage.googleapis.com (storage.googleapis.com)|34.64.4.112|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 44027904 (42M) [application/octet-stream]
Saving to: ‘/usr/local/bin/kubectl’
/usr/local/bin/kubectl 100%[==================================================================>] 41.99M 2.38MB/s in 31s
2020-04-13 17:51:29 (1.37 MB/s) - ‘/usr/local/bin/kubectl’ saved [44027904/44027904]
这个地方如果使用的是 debian 系的 Linux 发行版,也可以选择使用
$ sudo snap install kubectl --classic
来安装kubectl
2.下载 minikube
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools [17:54:11] C:1
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
> && chmod +x minikube
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:13 --:--:-- 0^C
讲道理应该会有不少人像我第一次一样,在 minikube 二进制文件的获取过程中就会被高高的某堵墙拦截下来(国内服务器)
这时候我选择的方法是在本地用自己的电脑下下载下来然后传到服务器上
# 重命名二进制文件
mv minikube-linux-amd64 minikube
# 赋予可执行权限
chmod +x minikube
# 移动安装minikube到path中
sudo mkdir -p /usr/local/bin/
sudo install minikube /usr/local/bin/
二,启动 minikube
接下来我就把我今天安装中踩过的坑一个一个记录下来,给看到这篇文章的小伙伴一个参考:
2.1 直接启动
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:03:52]
$ minikube start
* minikube v1.9.2 on Debian 9.12
* Automatically selected the docker driver
* The "docker" driver should not be used with root privileges.
* If you are running minikube within a VM, consider using --driver=none:
* https://minikube.sigs.k8s.io/docs/reference/drivers/none/
可以看到我们在默认的 Hypervisor 环境下是不能以 root 权限运行 minikube 的,下面摘引一段官方的 Hypervisor 教程
安装 Hypervisor
如果还没有装过 hypervisor,请选择以下方式之一进行安装:
• KVM,也使用了 QEMU
• VirtualBox
Minikube 还支持使用一个 --vm-driver=none 选项,让 Kubernetes 组件运行在主机中,而不是在 VM 中。 使用这种驱动方式需要 Docker 和 Linux 环境,但不需要 hypervisor。
如果你在 Debian 系的 OS 中使用了 none 这种驱动方式,请使用 .deb 包安装 Docker,不要使用 snap 包的方式,Minikube 不支持这种方式。 你可以从 Docker 下载 .deb 包。
警告:
none VM 驱动方式存在导致安全和数据丢失的问题。 使用 --vm-driver=none 之前,请参考这个文档获取详细信息。
Minikube 还支持另外一个类似于 Docker 驱动的方式 vm-driver=podman。 使用超级用户权限(root 用户)运行 Podman 可以最好的确保容器具有足够的权限使用你操作系统上的所有特性。
警告:
Podman 驱动方式需要以 root 用户身份运行容器,因为普通用户帐户没有足够的权限使用容器运行可能需要的操作系统上的所有特性。
最后我选择直接用 --vm-driver = none 启动 minikube(其实就是懒得装 Hypervisor 了......)
2.2 start --driver=none
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:06:22] C:69
$ minikube start --driver=none
* minikube v1.9.2 on Debian 9.12
* Using the none driver based on user configuration
X Sorry, Kubernetes v1.18.0 requires conntrack to be installed in root's path
根据提示安装 conntrack
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:06:38] C:78
$ apt install conntrack
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
conntrack
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 32.9 kB of archives.
After this operation, 104 kB of additional disk space will be used.
Get:1 http://mirrors.163.com/debian stretch/main amd64 conntrack amd64 1:1.4.4+snapshot20161117-5 [32.9 kB]
Fetched 32.9 kB in 0s (723 kB/s)
Selecting previously unselected package conntrack.
(Reading database ... 72364 files and directories currently installed.)
Preparing to unpack .../conntrack_1%3a1.4.4+snapshot20161117-5_amd64.deb ...
Unpacking conntrack (1:1.4.4+snapshot20161117-5) ...
Setting up conntrack (1:1.4.4+snapshot20161117-5) ...
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:08:16]
$ minikube start --driver=none
* minikube v1.9.2 on Debian 9.12
* Using the none driver based on user configuration
* Starting control plane node in cluster minikube
* Running on localhost (CPUs=1, Memory=978MB, Disk=35784MB) ...
* OS release is Debian GNU/Linux 9 (stretch)
* Preparing Kubernetes v1.18.0 on Docker 19.03.8 ...
! This bare metal machine is having trouble accessing https://k8s.gcr.io
* To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
> kubectl.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
> kubelet.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
> kubeadm.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
> kubeadm: 37.96 MiB / 37.96 MiB [---------------] 100.00% 1.39 MiB p/s 28s
> kubectl: 41.98 MiB / 41.98 MiB [---------------] 100.00% 1.09 MiB p/s 39s
> kubelet: 108.01 MiB / 108.01 MiB [-------------] 100.00% 1.95 MiB p/s 56s
! initialization failed, will try again: run: /bin/bash -c "sudo env PATH=/var/lib/minikube/binaries/v1.18.0:$PATH kubeadm init --config /var/tmp/minikube/kubeadm.yaml --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,DirAvailable--var-lib-minikube-etcd,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap,SystemVerification": exit status 1
stdout:
[init] Using Kubernetes version: v1.18.0
[preflight] Running pre-flight checks
stderr:
W0413 18:09:22.694854 112079 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[WARNING Swap]: running with swap on is not supported. Please disable swap
[WARNING FileExisting-ebtables]: ebtables not found in system path
[WARNING FileExisting-ethtool]: ethtool not found in system path
[WARNING FileExisting-socat]: socat not found in system path
[WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR NumCPU]: the number of available CPUs 1 is less than the required 2
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
*
X Error starting cluster: run: /bin/bash -c "sudo env PATH=/var/lib/minikube/binaries/v1.18.0:$PATH kubeadm init --config /var/tmp/minikube/kubeadm.yaml --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,DirAvailable--var-lib-minikube-etcd,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap,SystemVerification": exit status 1
stdout:
[init] Using Kubernetes version: v1.18.0
[preflight] Running pre-flight checks
stderr:
W0413 18:09:24.195084 112217 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[WARNING Swap]: running with swap on is not supported. Please disable swap
[WARNING FileExisting-ebtables]: ebtables not found in system path
[WARNING FileExisting-ethtool]: ethtool not found in system path
[WARNING FileExisting-socat]: socat not found in system path
[WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR NumCPU]: the number of available CPUs 1 is less than the required 2
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
*
* minikube is exiting due to an error. If the above message is not useful, open an issue:
- https://github.com/kubernetes/minikube/issues/new/choose
根据错误提示发现必须有两个 cpu 才能使用启动 minikube,穷逼怎么办呢,好在官方还是支持强行一个 cpu 启动的
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:09:25] C:70
$ minikube start --driver=none --extra-config=kubeadm.ignore-preflight-errors=NumCPU --force --cpus 1
* minikube v1.9.2 on Debian 9.12
* Using the none driver based on existing profile
! The 'none' driver does not respect the --cpus flag
* Starting control plane node in cluster minikube
* Restarting existing none bare metal machine for "minikube" ...
* OS release is Debian GNU/Linux 9 (stretch)
* Preparing Kubernetes v1.18.0 on Docker 19.03.8 ...
- kubeadm.ignore-preflight-errors=NumCPU
! This bare metal machine is having trouble accessing https://k8s.gcr.io
* To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
好吧,又出现了经典得网络问题,上代理
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:13:20] C:130
$ minikube start --driver=none --extra-config=kubeadm.ignore-preflight-errors=NumCPU --force --cpus 1 --image-repository=registry.cn-hangzhou.a
liyuncs.com/google_containers
* minikube v1.9.2 on Debian 9.12
* Using the none driver based on existing profile
! The 'none' driver does not respect the --cpus flag
* Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
* Starting control plane node in cluster minikube
* Updating the running none "minikube" bare metal machine ...
* OS release is Debian GNU/Linux 9 (stretch)
* Preparing Kubernetes v1.18.0 on Docker 19.03.8 ...
- kubeadm.ignore-preflight-errors=NumCPU
* Enabling addons: default-storageclass, storage-provisioner
* Configuring local host environment ...
*
! The 'none' driver is designed for experts who need to integrate with an existing VM
* Most users should use the newer 'docker' driver instead, which does not require root!
* For more information, see: https://minikube.sigs.k8s.io/docs/reference/drivers/none/
*
! kubectl and minikube configuration will be stored in /root
! To use kubectl or minikube commands as your own user, you may need to relocate them. For example, to overwrite your own settings, run:
*
- sudo mv /root/.kube /root/.minikube $HOME
- sudo chown -R $USER $HOME/.kube $HOME/.minikube
*
* This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
* Done! kubectl is now configured to use "minikube"
* For best results, install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/
至此,minikube 便成功启动起来了,我们简单验证一下
三,检查 minikube 安装状态
# root @ VM-253eb12c-e466-4202-b8eb-7892ae3ed8db in /home/tools/k8s [18:17:44] C:126
$ minikube status
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
嗯没有问题,下一篇我们再来基于 minikube 做一些 k8s 的实战。
版权声明: 本文为 InfoQ 作者【摩登土狗】的原创文章。
原文链接:【http://xie.infoq.cn/article/d98cb98443834a27cc1e7919a】。文章转载请联系作者。
摩登土狗
还未添加个人签名 2019.07.23 加入
还未添加个人简介
评论