一、安装docker(阿里云镜像安装)
1.卸载旧版本
sudo apt-get remove docker docker-engine docker-ce docker.io
2.添加阿里云GPG秘钥
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
3.设置存储库
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
4.安装docker
sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
5.验证
sudo docker version sudo systemctl status docker,未运行时执行sudo systemctl start docker启动docker sudo docker run hello-world 运行个容器试下 sudo systemctl enable docker # 设置开机自启
6.添加阿里镜像加速
https://cr.console.aliyun.com/cn-shanghai/instances/mirrors
二、安装minikube
1.依赖
sudo apt-get install -y apt-transport-https
2.添加阿里GPG
sudo curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
3.添加阿里apt源
sudo tee /etc/apt/sources.list.d/kubernetes.list <<-'EOF'
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
sudo apt-get update
4.安装kubectl
sudo apt-get install -y kubectl
5.添加用户到docker组
sudo usermod -aG docker $USER && newgrp docker
6.安装mibikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube
7.启动minikube
minikube start --image-mirror-country=cn --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version=1.23.8
注:结合docker使用时,k8s版本最好不要用1.24及以上版本,k8s从1.24版本开始不在直接兼容docker,需要安装cri-docker。
为了方便,设置alias
sudo vim .bashrc
加上 2 条 alias
alias minikube.cn="minikube start --image-mirror-country=cn --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version=1.23.8" alias kubectl="minikube kubectl --"
启动生效
source .bashrc
三、验证
1.查询所有namespace中的 pods
kubectl get po -A
2.安装hello-minikube
kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0 # 创建deploment kubectl expose deployment hello-minikube --type=NodePort --port=8080 # 创建service
过1分钟检查一下:
kubectl get pods
kubectl get services hello-minikube
端口转发访问一下:
kubectl port-forward service/hello-minikube 7080:8080
curl 127.0.0.1:7080
外网访问:
kubectl port-forward --address 0.0.0.0 service/hello-minikube 7080:8080
在桌面用浏览器访问下:http://IP:7080/
参考:
https://www.cnblogs.com/Can-daydayup/p/16472375.html
https://blog.csdn.net/u010953609/article/details/121489147
https://www.rondochen.com/python-redis-demo-in-minikube/
https://minikube.sigs.k8s.io/docs/start/