centos7使用Minikube“快速搭建“出Kubernetes本地实验环境(踩坑集锦及解决方案)

先决条件(先假设你做完这两步骤)

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  --registry-mirror=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
posted @ 2020-09-13 21:58  MrOldx  阅读(2303)  评论(0编辑  收藏  举报