centos7使用Minikube“快速搭建“出Kubernetes本地實驗環境(踩坑集錦及解決方案)

MrOldx發表於2020-09-13

先決條件(先假設你做完這兩步驟)

grep -E --color 'vmx|svm' /proc/cpuinfo

判斷是否成功安裝kubectl

kubectl version

在這裡插入圖片描述

安裝Minikube

Linux

curl -Lo minikube https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.13.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

啟動

minikube start

當你執行minkube start會出現這個錯誤,大概意思是需要加個 --driver=none的引數

錯誤一:

  • * 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/
    
    X Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.
    

加了引數以後那就恐怖了

[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/
1.[WARNING Swap]: running with swap on is not supported. Please disable swap

2.[WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'

 71489 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
error execution phase preflight: [preflight] Some fatal errors occurred:
	[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`

警告1.關閉Swap緩衝區(running with swap on is not supported. Please disable swap)

# 關閉Swap,機器重啟後不生效

swapoff -a

# 修改/etc/fstab永久關閉Swap

cp -p /etc/fstab /etc/fstab.bak$(date '+%Y%m%d%H%M%S')

# Redhat

sed -i "s/\/dev\/mapper\/rhel-swap/\#\/dev\/mapper\/rhel-swap/g" /etc/fstab

# CentOS

sed -i "s/\/dev\/mapper\/centos-swap/\#\/dev\/mapper\/centos-swap/g" /etc/fstab

# 修改後重新掛載全部掛載點

mount -a

# 檢視Swap

free -m
cat /proc/swaps
systemctl daemon-reload
systemctl restart kubelet

警告2.kubelet service is not enabled, please run 'systemctl enable kubelet.service'

//啟動kubelet服務
systemctl enable kubelet.service

錯誤3. FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1

echo "1" >/proc/sys/net/bridge/bridge-nf-call-iptables

現在終於沒啥錯了

啟動minikube

為了訪問海外的資源,阿里雲提供了一系列基礎設施,請按照如下引數進行配置。其中常見引數

  • --driver=*** 從1.5.0版本開始,Minikube預設使用本地最好的驅動來建立Kubernetes本地環境,測試過的版本 docker, kvm
  • --image-mirror-country cn 將預設利用 registry.cn-hangzhou.aliyuncs.com/google_containers 作為安裝Kubernetes的容器映象倉庫 (阿里雲版本可選)
  • --iso-url=*** 利用阿里雲的映象地址下載相應的 .iso 檔案 (阿里雲版本可選)
  • --registry-mirror=***為了拉取Docker Hub映象,需要為 Docker daemon 配置映象加速,參考阿里雲映象服務
  • --cpus=2: 為minikube虛擬機器分配CPU核數
  • --memory=2048mb: 為minikube虛擬機器分配記憶體數
  • --kubernetes-version=***: minikube 虛擬機器將使用的 kubernetes 版本
minikube start --image-mirror-country cn     --iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.5.0.iso  --registrymirror=https://pe3ox7bd.mirror.aliyuncs.com     --driver="none"     --memory=2048

不出意外應該是這樣的

在這裡插入圖片描述

啟動minikube dashboard

minikube dashboard

在這裡插入圖片描述

dashboard 給出了一個訪問地址,可以看出這個地址和埠只是k8s的虛擬地址,只能本機訪問如果要想從電腦上訪問伺服器上虛擬機器上的dashboard 你應該

新增叢集對外訪問代理:

nohub kubectl proxy  --port=[需要暴露的埠號] --address='[伺服器IP]' --accept-hosts='^[外部訪問伺服器的IP]$'  >/dev/null 2>&1& 

例如:

nohup kubectl proxy  --port=41111 --address='192.168.56.165' --accept-hosts='^192.168.56.165$'  >/dev/null 2>&1& 

訪問地址為:

http://192.168.56.165:41111/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/overview?namespace=default

相關文章