当前位置:   article > 正文

Centos7.6部署minikube

Centos7.6部署minikube

1、什么是minikube ?

Minikube是由Kubernetes社区维护的单机版的Kubernetes集群,支持macOS, Linux, and Windows等多种操作系统平台,使用最新的官方stable版本,并支持Kubernetes的大部分功能,从基础的容器编排管理,到高级特性如负载均衡、Ingress,权限控制等。非常适合作为Kubernetes入门,或开发测试环境使用。
安装k8s的麻烦就不用多说了,而且特别容易出错,烦的很,minikube部署简单可以用来测试学习用。

2、minikube安装

1、准备环境

一台装centos7.6的服务器
docker

安装最新 docker

  1. yum install -y yum-utils device-mapper-persistent-data lvm2
  2. yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  3. yum list docker-ce --showduplicates | sort -r
  4. sudo yum -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
  5. sudo systemctl start docker && systemctl enable docker

2 配置镜像源

  1. cat <<EOF > /etc/yum.repos.d/kubernetes.repo
  2. [kubernetes]
  3. name=Kubernetes
  4. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  5. enabled=1
  6. gpgcheck=1
  7. repo_gpgcheck=1
  8. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
  9. EOF

3、安装kubectl

  1. curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  2. chmod +x ./kubectl
  3. mv ./kubectl /usr/local/bin/kubectl

4、安装minukube

  1. curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
  2. chmod +x minikube
  3. mv minikube /usr/local/bin/

5、启动集群

新建一个普通用户,否则会提示The “docker” driver should not be used with root privileges.

  1. useradd ops -G docker
  2. echo "123456" | passwd --stdin ops
  3. #Changing password for user ops.
  4. su ops

启动本地k8s集群

  1. [ops@VM-0-8-centos ~]$ minikube start
  2. * minikube v1.23.2 on Centos 7.6.1908 (amd64)
  3. * Automatically selected the docker driver
  4. * Starting control plane node minikube in cluster minikube
  5. * Pulling base image ...
  6. * Downloading Kubernetes v1.22.2 preload ...
  7. > preloaded-images-k8s-v13-v1...: 511.69 MiB / 511.69 MiB 100.00% 10.70 Mi
  8. > index.docker.io/kicbase/sta...: 355.39 MiB / 355.40 MiB 100.00% 5.06 MiB
  9. ! minikube was unable to download gcr.io/k8s-minikube/kicbase:v0.0.27, but successfully downloaded docker.io/kicbase/stable:v0.0.27 as a fallback image
  10. * Creating docker container (CPUs=2, Memory=2200MB) ...
  11. ! This container is having trouble accessing https://k8s.gcr.io
  12. * To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
  13. * Preparing Kubernetes v1.22.2 on Docker 20.10.8 ...
  14. - Generating certificates and keys ...
  15. - Booting up control plane ...
  16. - Configuring RBAC rules ...
  17. * Verifying Kubernetes components...
  18. - Using image gcr.io/k8s-minikube/storage-provisioner:v5
  19. * Enabled addons: default-storageclass, storage-provisioner
  20. * Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

6、查看minikube状态

  1. [ops@VM-0-8-centos ~]$ minikube status
  2. minikube
  3. type: Control Plane
  4. host: Running
  5. kubelet: Running
  6. apiserver: Running
  7. kubeconfig: Configured

3、配置可视化面板

  1. minikube dashboard --url
  2. * Enabling dashboard ...
  3. * Verifying dashboard health ...
  4. * Launching proxy ...
  5. * Verifying proxy health ...
  6. http://127.0.0.1:33457/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

开启kube-proxy端口映射,使其可以远程访问

kubectl proxy --port=30030 --address='0.0.0.0' --accept-hosts='^.*' &

http://127.0.0.1:30030/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

启动minikube start的坑点

问题1:无法使用root启动

  1. [root@VM-16-14-centos bin]# minikube start
  2. * Centos 7.8.2003 上的 minikube v1.13.0
  3. * Automatically selected the docker driver
  4. * The "docker" driver should not be used with root privileges.
  5. * If you are running minikube within a VM, consider using --driver=none:
  6. *   https://minikube.sigs.k8s.io/docs/reference/drivers/none/
  7. X Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.

问题1:解决方法
因为我是用root账号登录操作的。所以提示不能用root账号启动,得用别的账号。所以要创建一个新的账号进行操作,创建一个test账号进行启动

  1. adduser test
  2. passwd test

问题2:minikube需要docker组启动

  1. [test@VM-16-14-centos ~]$ minikube start --driver=docker
  2. * Centos 7.8.2003 上的 minikube v1.13.0
  3. * 根据用户配置使用 docker 驱动程序
  4. 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
  5. * 建议:Add your user to the 'docker' group: 'sudo usermod -aG docker $USER && newgrp docker'
  6. * 文档:https://docs.docker.com/engine/install/linux-postinstall/

问题2:解决方法

  1. #创建docker组
  2. sudo groupadd docker
  3. #将您的用户添加到该docker组
  4. sudo usermod -aG docker $USER
  5. #在Linux上,运行以下命令来激活对组的更改
  6. newgrp docker

问题3:root账号启动docker导致无法启动

还是问题2的显示

问题3:解决办法:
先用root用户关闭docker,然后用test用户启动docker即可
docker启动和关闭命令

  1. systemctl start docker 
  2. systemctl stop docker

启动minikube,举例启动一个nginx

先准备一个nginx的yaml文件,名字为nginx-deployment.yaml
内容如下:

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: nginx-deployment
  5. spec:
  6. selector:
  7. matchLabels:
  8. app: nginx
  9. replicas: 2
  10. template:
  11. metadata:
  12. labels:
  13. app: nginx
  14. spec:
  15. containers:
  16. - name: nginx
  17. image: nginx:1.7.9
  18. ports:
  19. - containerPort: 80

启动minikube并且启动nginx

  1. minikube start --driver=docker
  2. kubectl create -f nginx-deployment.yaml
  3. [test@VM-16-14-centos ~]$ kubectl get pods -l app=nginx
  4. NAME READY STATUS RESTARTS AGE
  5. nginx-deployment-5d59d67564-k6q76 1/1 Running 0 84s
  6. nginx-deployment-5d59d67564-sgzjw 1/1 Running 0 84s

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/421635
推荐阅读
相关标签
  

闽ICP备14008679号