栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

kubernetes使用minikube工具运行一个单节点的kubernetes集群

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

kubernetes使用minikube工具运行一个单节点的kubernetes集群

使用minikube工具在移动云ECS上运行一个单节点的kubernetes集群

minikube

https://minikube.sigs.k8s.io/docs/start/

安装minikube

通过二进制安装,需要查询操作系统CPU的架构

[root@ecs-88500735 ~]# hostnamectl
   Static hostname: ecs-88500735
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 2d373eb792a749f68374f19577cd62be
           Boot ID: ab5554bbd5494cb385c4bc23012ef416
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1160.25.1.el7.x86_64
      Architecture: x86-64


执行以下shell命令

curl -LO
https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

[root@ecs-88500735 ~]# curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 69.2M  100 69.2M    0     0   845k      0  0:01:23  0:01:23 --:--:-- 1013k
[root@ecs-88500735 ~]# sudo install minikube-linux-amd64 /usr/local/bin/minikube
[root@ecs-88500735 ~]# 
2 Start your cluster


不要使用root用户登录命令终端来启动minikube

[root@ecs-88500735 ~]# minikube start
  Centos 7.9.2009 (amd64) 上的 minikube v1.25.2
  Unable to pick a default driver. Here is what was considered, in preference order:
  Alternatively you could install one of these drivers:
    ▪ docker: Not installed: exec: "docker": executable file not found in $PATH
    ▪ kvm2: Not installed: exec: "virsh": executable file not found in $PATH
    ▪ vmware: Not installed: exec: "docker-machine-driver-vmware": executable file not found in $PATH
    ▪ podman: Not installed: exec: "podman": executable file not found in $PATH
    ▪ virtualbox: Not installed: unable to find VBoxManage in $PATH

❌  Exiting due to DRV_NOT_DETECTED: No possible driver was detected. Try specifying --driver, or see https://minikube.sigs.k8s.io/docs/start/

安装docker

https://docs.docker.com/engine/install/centos/

$ sudo yum install -y yum-utils
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

[root@ecs-88500735 ~]# sudo yum install -y yum-utils
已加载插件:fastestmirror, versionlock
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 yum-utils.noarch.0.1.1.31-54.el7_8 将被 安装
--> 正在处理依赖关系 python-kitchen,它被软件包 yum-utils-1.1.31-54.el7_8.noarch 需要
--> 正在处理依赖关系 libxml2-python,它被软件包 yum-utils-1.1.31-54.el7_8.noarch 需要
--> 正在检查事务
---> 软件包 libxml2-python.x86_64.0.2.9.1-6.el7_9.6 将被 安装
---> 软件包 python-kitchen.noarch.0.1.1.1-5.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package              架构         版本                     源             大小
================================================================================
正在安装:
 yum-utils            noarch       1.1.31-54.el7_8          base          122 k
为依赖而安装:
 libxml2-python       x86_64       2.9.1-6.el7_9.6          updates       247 k
 python-kitchen       noarch       1.1.1-5.el7              base          267 k

事务概要
================================================================================
安装  1 软件包 (+2 依赖软件包)

总下载量:636 k
安装大小:3.2 M
Downloading packages:
(1/3): libxml2-python-2.9.1-6.el7_9.6.x86_64.rpm           | 247 kB   00:00     
(2/3): python-kitchen-1.1.1-5.el7.noarch.rpm               | 267 kB   00:00     
(3/3): yum-utils-1.1.31-54.el7_8.noarch.rpm                | 122 kB   00:01     
--------------------------------------------------------------------------------
总计                                               516 kB/s | 636 kB  00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : libxml2-python-2.9.1-6.el7_9.6.x86_64                       1/3 
  正在安装    : python-kitchen-1.1.1-5.el7.noarch                           2/3 
  正在安装    : yum-utils-1.1.31-54.el7_8.noarch                            3/3 
  验证中      : python-kitchen-1.1.1-5.el7.noarch                           1/3 
  验证中      : yum-utils-1.1.31-54.el7_8.noarch                            2/3 
  验证中      : libxml2-python-2.9.1-6.el7_9.6.x86_64                       3/3 

已安装:
  yum-utils.noarch 0:1.1.31-54.el7_8                                            

作为依赖被安装:
  libxml2-python.x86_64 0:2.9.1-6.el7_9.6  python-kitchen.noarch 0:1.1.1-5.el7 

完毕!
[root@ecs-88500735 ~]# 
[root@ecs-88500735 ~]# sudo yum-config-manager 
>     --add-repo 
>     https://download.docker.com/linux/centos/docker-ce.repo
已加载插件:fastestmirror, versionlock
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@ecs-88500735 ~]# 
安装Docker Engine

$ sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

[root@ecs-88500735 ~]# sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
已加载插件:fastestmirror, versionlock
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.ustc.edu.cn
docker-ce-stable                                         | 3.5 kB     00:00     
(1/2): docker-ce-stable/7/x86_64/updateinfo                |   55 B   00:00     
(2/2): docker-ce-stable/7/x86_64/primary_db                |  78 kB   00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.6.4-3.1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 containerd.io-1.6.4-3.1.el7.x86_64 需要
--> 正在处理依赖关系 libseccomp,它被软件包 containerd.io-1.6.4-3.1.el7.x86_64 需要
---> 软件包 docker-ce.x86_64.3.20.10.16-3.el7 将被 安装
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-20.10.16-3.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.20.10.16-3.el7 将被 安装
--> 正在处理依赖关系 docker-scan-plugin(x86-64),它被软件包 1:docker-ce-cli-20.10.16-3.el7.x86_64 需要
---> 软件包 docker-compose-plugin.x86_64.0.2.5.0-3.el7 将被 安装
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.119.2-1.911c772.el7_8 将被 安装
---> 软件包 docker-ce-rootless-extras.x86_64.0.20.10.16-3.el7 将被 安装
--> 正在处理依赖关系 fuse-overlayfs >= 0.7,它被软件包 docker-ce-rootless-extras-20.10.16-3.el7.x86_64 需要
--> 正在处理依赖关系 slirp4netns >= 0.4,它被软件包 docker-ce-rootless-extras-20.10.16-3.el7.x86_64 需要
---> 软件包 docker-scan-plugin.x86_64.0.0.17.0-3.el7 将被 安装
---> 软件包 libseccomp.x86_64.0.2.3.1-4.el7 将被 安装
--> 正在检查事务
---> 软件包 fuse-overlayfs.x86_64.0.0.7.2-6.el7_8 将被 安装
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.2)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.0)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3()(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
---> 软件包 slirp4netns.x86_64.0.0.4.3-4.el7_8 将被 安装
--> 正在检查事务
---> 软件包 fuse3-libs.x86_64.0.3.6.1-4.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package                架构   版本                      源                大小
================================================================================
正在安装:
 containerd.io          x86_64 1.6.4-3.1.el7             docker-ce-stable  33 M
 docker-ce              x86_64 3:20.10.16-3.el7          docker-ce-stable  22 M
 docker-ce-cli          x86_64 1:20.10.16-3.el7          docker-ce-stable  29 M
 docker-compose-plugin  x86_64 2.5.0-3.el7               docker-ce-stable 7.0 M
为依赖而安装:
 container-selinux      noarch 2:2.119.2-1.911c772.el7_8 extras            40 k
 docker-ce-rootless-extras
                        x86_64 20.10.16-3.el7            docker-ce-stable 8.2 M
 docker-scan-plugin     x86_64 0.17.0-3.el7              docker-ce-stable 3.7 M
 fuse-overlayfs         x86_64 0.7.2-6.el7_8             extras            54 k
 fuse3-libs             x86_64 3.6.1-4.el7               extras            82 k
 libseccomp             x86_64 2.3.1-4.el7               base              56 k
 slirp4netns            x86_64 0.4.3-4.el7_8             extras            81 k

事务概要
================================================================================
安装  4 软件包 (+7 依赖软件包)

总下载量:104 M
安装大小:419 M
Is this ok [y/d/N]: y
Downloading packages:
(1/11): container-selinux-2.119.2-1.911c772.el7_8.noarch.r |  40 kB   00:00     
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.16-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
docker-ce-20.10.16-3.el7.x86_64.rpm 的公钥尚未安装
(2/11): docker-ce-20.10.16-3.el7.x86_64.rpm                |  22 MB   00:58     
(3/11): containerd.io-1.6.4-3.1.el7.x86_64.rpm             |  33 MB   01:06     
(4/11): docker-ce-rootless-extras-20.10.16-3.el7.x86_64.rp | 8.2 MB   00:16     
(5/11): docker-compose-plugin-2.5.0-3.el7.x86_64.rpm       | 7.0 MB   00:14     
(6/11): fuse3-libs-3.6.1-4.el7.x86_64.rpm                  |  82 kB   00:00     
(7/11): libseccomp-2.3.1-4.el7.x86_64.rpm                  |  56 kB   00:00     
(8/11): slirp4netns-0.4.3-4.el7_8.x86_64.rpm               |  81 kB   00:00     
(9/11): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm            |  54 kB   00:08     
(10/11): docker-scan-plugin-0.17.0-3.el7.x86_64.rpm        | 3.7 MB   00:10     
(11/11): docker-ce-cli-20.10.16-3.el7.x86_64.rpm           |  29 MB   01:00     
--------------------------------------------------------------------------------
总计                                               901 kB/s | 104 MB  01:58     
从 https://download.docker.com/linux/centos/gpg 检索密钥
导入 GPG key 0x621E9F35:
 用户ID     : "Docker Release (CE rpm) "
 指纹       : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 来自       : https://download.docker.com/linux/centos/gpg
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : libseccomp-2.3.1-4.el7.x86_64                              1/11 
  正在安装    : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch         2/11 
setsebool:  SELinux is disabled.
  正在安装    : containerd.io-1.6.4-3.1.el7.x86_64                         3/11 
  正在安装    : slirp4netns-0.4.3-4.el7_8.x86_64                           4/11 
  正在安装    : 1:docker-ce-cli-20.10.16-3.el7.x86_64                      5/11 
  正在安装    : docker-scan-plugin-0.17.0-3.el7.x86_64                     6/11 
  正在安装    : fuse3-libs-3.6.1-4.el7.x86_64                              7/11 
  正在安装    : fuse-overlayfs-0.7.2-6.el7_8.x86_64                        8/11 
  正在安装    : 3:docker-ce-20.10.16-3.el7.x86_64                          9/11 
  正在安装    : docker-ce-rootless-extras-20.10.16-3.el7.x86_64           10/11 
  正在安装    : docker-compose-plugin-2.5.0-3.el7.x86_64                  11/11 
  验证中      : fuse3-libs-3.6.1-4.el7.x86_64                              1/11 
  验证中      : docker-ce-rootless-extras-20.10.16-3.el7.x86_64            2/11 
  验证中      : fuse-overlayfs-0.7.2-6.el7_8.x86_64                        3/11 
  验证中      : docker-compose-plugin-2.5.0-3.el7.x86_64                   4/11 
  验证中      : containerd.io-1.6.4-3.1.el7.x86_64                         5/11 
  验证中      : slirp4netns-0.4.3-4.el7_8.x86_64                           6/11 
  验证中      : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch         7/11 
  验证中      : libseccomp-2.3.1-4.el7.x86_64                              8/11 
  验证中      : docker-scan-plugin-0.17.0-3.el7.x86_64                     9/11 
  验证中      : 1:docker-ce-cli-20.10.16-3.el7.x86_64                     10/11 
  验证中      : 3:docker-ce-20.10.16-3.el7.x86_64                         11/11 

已安装:
  containerd.io.x86_64 0:1.6.4-3.1.el7                                          
  docker-ce.x86_64 3:20.10.16-3.el7                                             
  docker-ce-cli.x86_64 1:20.10.16-3.el7                                         
  docker-compose-plugin.x86_64 0:2.5.0-3.el7                                    

作为依赖被安装:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8                            
  docker-ce-rootless-extras.x86_64 0:20.10.16-3.el7                             
  docker-scan-plugin.x86_64 0:0.17.0-3.el7                                      
  fuse-overlayfs.x86_64 0:0.7.2-6.el7_8                                         
  fuse3-libs.x86_64 0:3.6.1-4.el7                                               
  libseccomp.x86_64 0:2.3.1-4.el7                                               
  slirp4netns.x86_64 0:0.4.3-4.el7_8                                            

完毕!
[root@ecs-88500735 ~]# 
[root@ecs-88500735 ~]# minikube start --driver=docker
  Centos 7.9.2009 (amd64) 上的 minikube v1.25.2
✨  根据用户配置使用 docker 驱动程序

  Exiting due to PROVIDER_DOCKER_NOT_RUNNING: "docker version --format -" exit status 1: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
  建议:Start the Docker service
  文档:https://minikube.sigs.k8s.io/docs/drivers/docker/
[root@ecs-88500735 ~]# systemctl start docker.service
[root@ecs-88500735 ~]# minikube start --driver=docker
  Centos 7.9.2009 (amd64) 上的 minikube v1.25.2
✨  根据用户配置使用 docker 驱动程序
  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/

❌  Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.
切换用户
[root@ecs-88500735 ~]# useradd mini
[root@ecs-88500735 ~]# passwd mini
更改用户 mini 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@ecs-88500735 ~]# su mini
[mini@ecs-88500735 root]$ clear
[mini@ecs-88500735 root]$ minikube start --driver=docker
  Centos 7.9.2009 (amd64) 上的 minikube v1.25.2
✨  根据用户配置使用 docker 驱动程序

  Exiting due to PROVIDER_DOCKER_NEWGRP: "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.24/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/

Add your user to the ‘docker’ group: ‘sudo usermod -aG docker $USER && newgrp docker’

添加用户到 docker group
[mini@ecs-88500735 root]$ su root
密码:
[root@ecs-88500735 ~]# sudo usermod -aG docker mini && newgrp docker
[root@ecs-88500735 ~]# 

回到mini用户 并执行minikube start

minikube start --driver=docker

[root@ecs-88500735 ~]# su mini
[mini@ecs-88500735 root]$ minikube start --driver=docker
  Centos 7.9.2009 (amd64) 上的 minikube v1.25.2
✨  根据用户配置使用 docker 驱动程序
  Starting control plane node minikube in cluster minikube
  Pulling base image ...
  Downloading Kubernetes v1.23.3 preload ...
    > preloaded-images-k8s-v17-v1...: 505.68 MiB / 505.68 MiB  100.00% 906.95 K
    > index.docker.io/kicbase/sta...: 379.06 MiB / 379.06 MiB  100.00% 542.67 K
❗  minikube was unable to download gcr.io/k8s-minikube/kicbase:v0.0.30, but successfully downloaded docker.io/kicbase/stable:v0.0.30 as a fallback image
  Creating docker container (CPUs=2, Memory=2200MB) ... 
 
❗  This container is having trouble accessing https://k8s.gcr.io
  To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
  正在 Docker 20.10.12 中准备 Kubernetes v1.23.3…
    ▪ kubelet.housekeeping-interval=5m
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
  Enabled addons: default-storageclass, storage-provisioner
  kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
3 Interact with your cluster

$ minikube kubectl – get pods -A

[mini@ecs-88500735 root]$ minikube kubectl -- get pods -A
    > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl: 44.43 MiB / 44.43 MiB [-------------] 100.00% 923.85 KiB p/s 49s
NAMESPACE     NAME                               READY   STATUS    RESTARTS       AGE
kube-system   coredns-64897985d-k449z            1/1     Running   0              3m43s
kube-system   etcd-minikube                      1/1     Running   0              3m58s
kube-system   kube-apiserver-minikube            1/1     Running   0              3m58s
kube-system   kube-controller-manager-minikube   1/1     Running   0              3m58s
kube-system   kube-proxy-cjvmw                   1/1     Running   0              3m44s
kube-system   kube-scheduler-minikube            1/1     Running   0              3m58s
kube-system   storage-provisioner                1/1     Running   1 (3m8s ago)   3m48s

$ minikube dashboard

[mini@ecs-88500735 root]$ minikube dashboard
  正在开启 dashboard ...
    ▪ Using image kubernetesui/metrics-scraper:v1.0.7
    ▪ Using image kubernetesui/dashboard:v2.3.1
樂  正在验证 dashboard 运行情况 ...
  Launching proxy ...
樂  正在验证 proxy 运行状况 ...
  Opening http://127.0.0.1:35499/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
  http://127.0.0.1:35499/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
用nginx反向代理127.0.0.1:35499

新开命令终端

[root@ecs-88500735 ~]# cd /etc/nginx/
[root@ecs-88500735 nginx]# ls
conf.d          mime.types  nginx.conf      scgi_params
fastcgi_params  modules     nginx.conf.bak  uwsgi_params
[root@ecs-88500735 nginx]# vi nginx.conf
server {
	listen 7080;
	server_name 36.133.79.76;
	
	location / {
		root html;
		index index.htm index.html;
		proxy_pass http://127.0.0.1:35499;
	}
}
[root@ecs-88500735 nginx]# lsof -i:7080
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   92871  root    7u  IPv4 642810      0t0  TCP *:empowerid (LISTEN)
nginx   92872 nginx    7u  IPv4 642810      0t0  TCP *:empowerid (LISTEN)
nginx   92873 nginx    7u  IPv4 642810      0t0  TCP *:empowerid (LISTEN)
在浏览器访问

http://36.133.79.76:7080/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

简单测试环境是否OK

部署tomcat和redis应用





容器启动正常

再发布一个tomcat-1100 端口 1100-8080

获取对外发布的服务
[mini@ecs-88500735 root]$ minikube kubectl get service
NAME          TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
kubernetes    ClusterIP      10.96.0.1             443/TCP          26h
tomcat-1100   LoadBalancer   10.98.86.92        1100:30056/TCP   75s
[mini@ecs-88500735 root]$ minikube service tomcat-1100 --url
http://192.168.49.2:30056
[mini@ecs-88500735 root]$ su root
密码:
[root@ecs-88500735 ~]# curl  http://192.168.49.2:30056
HTTP Status 404 – Not FoundHTTP Status 404 – Not Found

Type Status Report

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.


Apache Tomcat/10.0.20[root@ecs-88500735 ~]#
[root@ecs-88500735 ~]# vi /etc/nginx/nginx.conf
server {
   listen 1100;
   server_name 36.133.79.76;
   location / {
      root html;
      index index.htm index.html;
      proxy_pass http://192.168.49.2:30056;
   }
}
[root@ecs-88500735 ~]# nginx -s reload


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/893280.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号