阿里云安装 minikube v1.9.2
2020-05-06 本文已影响0人
世界而世界
日期:2020年5月6日
一、环境
阿里云 centos8 2c4g
二、安装docker
- centos官方安装教程 https://docs.docker.com/engine/install/centos/
- 国内阿里云centos8安装参考资料 https://yq.aliyun.com/articles/748412
- 安装完后可做的操作 https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user
问题1:yum/dnf error: Failed to download metadata for repo
dnf clean all && rm -r /var/cache/dnf && dnf upgrade -y && dnf update -y
参考网址:
https://stackoverflow.com/questions/59993633/yum-dnf-error-failed-to-download-metadata-for-repo
问题2:containerd.io版本过低
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
yum install containerd.io-1.2.6-3.3.el7.x86_64.rpm #安装containerd.io
#再次重新安装docker
yum install docker-ce docker-ce-cli containerd.io
三、下载 minikube
- 官方安装 https://minikube.sigs.k8s.io/docs/start/
- 阿里云安装教程 https://github.com/AliyunContainerService/minikube/wiki
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-1.9.2-0.x86_64.rpm
sudo rpm -ivh minikube-1.9.2-0.x86_64.rpm
四、启动 minikube
- 启动时需要创建新用户,用户组可以加入到docker组,用户、用户组可以加入sudoers列表
例如:
sudo useradd k8s
sudo passwd k8s
sudo usermod -aG docker k8s
chmod u+w /etc/sudoers
vim /etc/sudoers
chmod u-w /etc/sudoers
- 国内启动镜像需要一些参数支持,启动命令如下
minikube start \
--image-mirror-country=cn \
--registry-mirror=https://xxx.mirror.aliyuncs.com \
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers \
--iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.9.0.iso
- 可以使用 minikube start -h 查询参数说明
- registry-mirror 设置为自己的阿里云镜像加速器
- iso-url 指定阿里云做的国内iso镜像 官宣
- image-repository 指定使用阿里云的镜像仓库
- 参考网址 普大喜奔,官方Minikube提供了完整对国内用户支持 https://github.com/AliyunContainerService/minikube
- 成功命令行示例
😄 minikube v1.9.2 on Centos 8.1.1911
✨ Using the docker driver based on existing profile
✅ Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
👍 Starting control plane node m01 in cluster minikube
🚜 Pulling base image ...
💾 Downloading Kubernetes v1.18.0 preload ...
🤷 docker "minikube" container is missing, will recreate.
🔥 Creating Kubernetes in docker container with (CPUs=2) (2 available), Memory=2200MB (3637MB available) ...
🐳 Preparing Kubernetes v1.18.0 on Docker 19.03.2 ...
▪ kubeadm.pod-network-cidr=10.244.0.0/16
🏄 Done! kubectl is now configured to use "minikube"
问题1:Unable to find image 'gcr.io/k8s-minikube/kicbase:v0.0.8@sha256:2f3380ebf1bb0c75b0b47160fd4e61b7b8fef0f1f32f9def108d3eada50a7a81'
- 找可以fq的服务器(例如自己电脑),下一个镜像,然后打包上传到服务器
docker pull gcr.io/k8s-minikube/kicbase:v0.0.8
docker save gcr.io/k8s-minikube/kicbase:v0.0.8 | gzip > kicbase.tar.gz
scp kicbase.tar.gz root@xxx
docker load < kicbase.tar.gz
- 缺失RepoDigest时,修改该镜像RepoDigest
vim /var/lib/docker/image/overlay2/repositories.json
{"Repositories":{"gcr.io/k8s-minikube/kicbase":{"gcr.io/k8s-minikube/kicbase:v0.0.8":"sha256:11589cdc9ef4b67a64cc243dd3cf013e81ad02bbed105fc37dc07aa272044680"},"java":{"java:latest":"sha256:d23bdf5b1b1b1afce5f1d0fd33e7ed8afbc084b594b9ccf742a5b27080d8a4a8","java@sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d":"sha256:d23bdf5b1b1b1afce5f1d0fd33e7ed8afbc084b594b9ccf742a5b27080d8a4a8"}}}
# 改为下面
{"Repositories":{"gcr.io/k8s-minikube/kicbase":{"gcr.io/k8s-minikube/kicbase@sha256:2f3380ebf1bb0c75b0b47160fd4e61b7b8fef0f1f32f9def108d3eada50a7a81" : "sha256:11589cdc9ef4b67a64cc243dd3cf013e81ad02bbed105fc37dc07aa272044680","gcr.io/k8s-minikube/kicbase:v0.0.8":"sha256:11589cdc9ef4b67a64cc243dd3cf013e81ad02bbed105fc37dc07aa272044680"},"java":{"java:latest":"sha256:d23bdf5b1b1b1afce5f1d0fd33e7ed8afbc084b594b9ccf742a5b27080d8a4a8","java@sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d":"sha256:d23bdf5b1b1b1afce5f1d0fd33e7ed8afbc084b594b9ccf742a5b27080d8a4a8"}}}
systemctl restart docker
五、启动 minikube dashboard
# 运行命令
minikube dashboard
如何简单外网访问
minikube 会绑定到指定ip上,并在其上暴露端口,可以通过命令查看
minikube ip
ps: 使用 nodeport 类型,会在绑定 ip 上暴露 node 端口哦,请注意。
https://stackoverflow.com/questions/40767164/expose-port-in-minikube
dashboard 使用 proxy 跑起来的,会绑定 ip 127.0.0.1 内网和外网都不可直接访问
- 利用nginx做反向代理
- 本地使用隧道,例如 core tunnel
- 其他代理及负载均衡
ps: 别忘记跨域问题