零,寫在前面#
先大概說一下這次用來實驗的伺服器的狀態:
伺服器是白嫖的國內某廠商的一個月試用版,申請之後一直也沒有排上用場,今天想着閒著也是閒著就拿來試試之前自己在黑蘋果 > 上失敗了無數次的 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 相關的安裝,大家應該都很熟悉這次就不寫了
一,安裝 Minikube#
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 的實戰。