Mac上使用minikube搭建单机k8s集群

2019-07-22

Mac上使用minikube搭建单机k8s集群

最近由于项目需要搭建一个测试环境,于是mentor决定用minikube搭建一个本地的测试环境,于是我也就接触到了k8s这样的技术,这里记录一下搭建过程。

1. mac环境搭建

由于使用minikube需要安装virtualbox,在公司电脑的虚拟机里安装virtualbox总是失败,花了一下午也没有解决,因此一怒之下选了自己的mac搭建环境,不得不说Mac上搭建还是很简单的。

curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.18.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

​ 查看version,可以确定是否安装成功;

minikube version
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl

2. minikube搭建k8s集群

3. 公司内网搭建

本来环境搭得挺顺利,但是突然有一天晚上发现minikube报错了,查看log发现应该是有镜像pull的时候报错,也就是网络出问题了;突然发现原来是我当前网络变成公司内网了,无法访问外部的镜像源,所以我开始了改代理之旅。

4. 用yaml文件创建服务


突然,发生了一连串的问题问题

Error from server (BadRequest): error when creating "yunsou_web_service.yaml": Deployment in version "v1" cannot be handled as a Deployment: no kind "Deployment" is registered for version "apps/v1"

于是卸载kubectl,即删除/usr/local/bin里的kubectl文件,安装最新版

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl \
	&& chmod +x kubectl \
	&& mv kubectl /usr/local/bin/
Error from server (NotFound): the server could not find the requested resource

于是卸载minikube,即删除/usr/local/bin里的minikube文件

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64 \
  && chmod +x minikube \
  && mv minikube /usr/local/bin/
Error response from daemon: Get https://docker.oa.com/v2/: Gateway Time-out

登陆之前, 需要设置证书

minikube ssh
sudo mkdir -p /etc/docker/certs.d/docker.oa.com; 
sudo mkdir -p /etc/docker/certs.d/registry.oa.com; 
sudo wget docker.oa.com/cert/gaia.crt -O /etc/docker/certs.d/docker.oa.com/ca.crt ;  
sudo cp /etc/docker/certs.d/docker.oa.com/ca.crt /etc/docker/certs.d/registry.oa.com/ ;

然后登录:

docker login docker.xxx.com
Username:
Password:

参考

点击查看评论

所有文章