Preface
社区版的kubernetes自己去安装实在是太恼火了,好在有替代方案—-minikube。可以在minikube上体验kubernetes的相关功能。所以我们直接在本地实验环境来安装minikube,来入门学习kubernetes相关的知识;
安装前准备
推荐在linux主机上安装,我本地用的是 deepin/ubuntu。
安装minikube的主机必要配置:
- 2 CPUs or more
- 2GB of free memory
- 20GB of free disk space
- Internet connection
- Container or virtual machine manager, such as: Docker, Hyperkit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMware
Container 容器我本地安装是docker;
from : Docker_apt安装 - 简书 (jianshu.com)
如果之前有安装过docker,可以先卸载:
apt-get remove docker docker-engine http://docker.io更新apt安装包索引
apt-get update安装软件包以允许apt通过HTTPS
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common添加Docker官方的GPG密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -安装稳定版仓库
sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”安装docker
apt-get install http://docker.io启动docker服务
systemctl start docker
此时可以通过docker version
命令来验证docker是否安装成功。
注:由于国内访问docker镜像库很是缓慢,所以建议配置阿里云的代理,通过修改daemon配置文件/etc/docker/daemon.json来使用加速器:
1 | $ cd /etc/docker |
安装minikube
安装步骤
minikube的官网:minikube start | minikube (k8s.io)
官网上的安装minikube网速实在太慢了,推荐使用阿里云的镜像来进行安装minikube,更多信息见:Minikube - Kubernetes本地实验环境-阿里云开发者社区 (aliyun.com)
- 直接安装minikube
curl -Lo minikube https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.23.1/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/ - 启动minikube
# 默认会使用docker容器。
minikube start - 让minikube下载kubectl客户端命令工具
minikube kubectl – get po -A
此时就可以使用kubectl命令来进行各种kubernetes的操作了。
开启控制台
执行以下命令开启控制台
直接点击上面的url,即可看到控制台页面:
直接使用
此时的minikube kubectl --
就相当于k8s里的kubectl
命令,当然我们实际不会这样使用,我们可以minikube的命令给alias一下:
1 | $ alias kubectl="minikube kubectl --" |
此时再直接运行kubectl
命令:
1 | $ kubectl |
好了,就可以愉快的k8s玩耍了。
一些常见问题
- 执行
minikube start
出现 The “docker” driver should not be used with root privileges 的报错.
如果是本地测试环境,根本就不需要考虑那么多,直接执行以下命令,强制使用docker:
1 | minikube start --force --driver=docker |
- 执行
istioctl install
命令时一直出现如下问题:
1 | Processing resources for Istiod. Waiting for Deployment/service-mesh-system/istiod |
此时使用kubectl get pods -n istio-system
命令发现istio-egressgateway
和istio-ingressgateway
都处于ContainerCreateing
状态。
我当时的解决方式:等了很久(10分钟左右),自动就好了。原因暂时未知,google说可能是node的问题。
附录
使用阿里云代理http://k8s.gcr.io镜像仓库
- 国内根本访问不了k8s的镜像库:
k8s.gsc.io
。比如下载k8s.gcr.io/coredns
:1.6.5镜像,在国内默认是下载失败的!
1 | [root@k8s-vm03 ~]``# docker pull k8s.gcr.io/coredns:1.6.5 |
- 这时候去指定国内的阿里云镜像代理仓库进行下载
1 | [root@k8s-vm03 ~]``# docker pull registry.aliyuncs.com/google_containers/coredns:1.6.5 |
- 然后打tag,并删除之前从代理仓库下载的镜像
1 | [root@k8s-vm03 ~]``# docker tag registry.aliyuncs.com/google_containers/coredns:1.6.5 k8s.gcr.io/coredns:1.6.5 |
1 | [root@k8s-vm03 ~]``# docker rmi registry.aliyuncs.com/google_containers/coredns:1.6.5 |
1 | [root@k8s-vm03 ~]``# docker images |
1 | 最终发现我们想要的k8s.gcr.io``/coredns``:1.6.5镜像被成功下载下来了! |
1 | 最后要记得: |
参考资料
Minikube - Kubernetes本地实验环境-阿里云开发者社区 (aliyun.com)