安装k8s和docker
我的测试系统是centos5.8的国内服务器
参考文档:https://developer.aliyun.com/article/221687
首先先安装k8s 1.19.2版本
1 2 3 4 5 6 7 8 9 10 | # 1.19.x 版本的安装 # 腾讯云 docker hub 镜像 # export REGISTRY_MIRROR="https://mirror.ccs.tencentyun.com" # DaoCloud 镜像 # export REGISTRY_MIRROR="http://f1361db2.m.daocloud.io" # 华为云镜像 # export REGISTRY_MIRROR="https://05f073ad3c0010ea0f4bc00b7105ec20.mirror.swr.myhuaweicloud.com" # 阿里云 docker hub 镜像 export REGISTRY_MIRROR=https://registry.cn-hangzhou.aliyuncs.com curl -sSL https://kuboard.cn/install-script/v1.19.x/install_kubelet.sh | sh -s 1.19.2 |
在安装k8s的时候会顺便把匹配的版本也安装好
安装minikube
1 | 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/ |
其实就是下载一个文件,也可以直接到对应的github中找branches版本然后下载到本地再上传到服务器上
启动minikube start的坑点
问题1:无法使用root启动
1 2 3 4 5 6 7 8 | [root@VM-16-14-centos bin]# minikube start * Centos 7.8.2003 上的 minikube v1.13.0 * Automatically selected the docker driver * 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. |
问题1:解决方法
因为我是用root账号登录操作的。所以提示不能用root账号启动,得用别的账号。所以要创建一个新的账号进行操作,创建一个test账号进行启动
1 2 | adduser test passwd test |
问题2:minikube需要docker组启动
1 2 3 4 5 6 7 | [test@VM-16-14-centos ~]$ minikube start --driver=docker * Centos 7.8.2003 上的 minikube v1.13.0 * 根据用户配置使用 docker 驱动程序 X Exiting due to PROVIDER_DOCKER_ERROR: "docker version --format -" exit status 1: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/version: dial unix /var/run/docker.sock: connect: permission denied * 建议:Add your user to the 'docker' group: 'sudo usermod -aG docker $USER && newgrp docker' * 文档:https://docs.docker.com/engine/install/linux-postinstall/ |
问题2:解决方法
1 2 3 4 5 6 | #创建docker组 sudo groupadd docker #将您的用户添加到该docker组 sudo usermod -aG docker $USER #在Linux上,运行以下命令来激活对组的更改 newgrp docker |
问题3:root账号启动docker导致无法启动
还是问题2的显示
问题3:解决办法:
先用root用户关闭docker,然后用test用户启动docker即可
docker启动和关闭命令
1 2 | systemctl start docker systemctl stop docker |
启动minikube,举例启动一个nginx
先准备一个nginx的yaml文件,名字为nginx-deployment.yaml
内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 |
启动minikube并且启动nginx
1 2 3 4 5 6 | minikube start --driver=docker kubectl create -f nginx-deployment.yaml [test@VM-16-14-centos ~]$ kubectl get pods -l app=nginx NAME READY STATUS RESTARTS AGE nginx-deployment-5d59d67564-k6q76 1/1 Running 0 84s nginx-deployment-5d59d67564-sgzjw 1/1 Running 0 84s |