使用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) <docker@docker.com>"
 指纹       : 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
启动dashboard

$ minikube dashboard

[mini@ecs-88500735 ~]$ 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:35967/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
👉  http://127.0.0.1:35967/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
以后台运行的方式启动dashboard
[mini@ecs-88500735 ~]$ nohup minikube dashboard > minikube.dashboard.log &
[1] 989942
[mini@ecs-88500735 ~]$ nohup: 忽略输入重定向错误到标准输出端

[mini@ecs-88500735 ~]$ tail -f minikube.dashboard.log
* 正在开启 dashboard ...
  - Using image kubernetesui/dashboard:v2.3.1
  - Using image kubernetesui/metrics-scraper:v1.0.7
* 正在验证 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     <none>        443/TCP          26h
tomcat-1100   LoadBalancer   10.98.86.92   <pending>     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
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/10.0.20</h3></body></html>[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

当前使用的tomcat镜像webapp没有部署任何应用,所以访问资源404 是正常的。
在这里插入图片描述
在这里插入图片描述

部署 mysql 8.0 单点
[root@ecs-88500735 mini]# yum install nfs-utils
[root@ecs-88500735 mini]# yum install rpcbind
[root@ecs-88500735 ~]# systemctl start nfs-server 
[root@ecs-88500735 ~]# systemctl start rpcbind
1. 查询minikube对应的server主机ip

在这里插入图片描述

[root@ecs-88500735 ~]# ifconfig -a
br-f9f273f75650: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.49.1  netmask 255.255.255.0  broadcast 192.168.49.255
        inet6 fe80::42:4cff:fee8:356a  prefixlen 64  scopeid 0x20<link>
        ether 02:42:4c:e8:35:6a  txqueuelen 0  (Ethernet)
        RX packets 2588797  bytes 3813498052 (3.5 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2376163  bytes 259234969 (247.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:86ff:fe2f:aadd  prefixlen 64  scopeid 0x20<link>
        ether 02:42:86:2f:aa:dd  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3  bytes 266 (266.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.6  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::f816:3eff:fea2:35fc  prefixlen 64  scopeid 0x20<link>
        ether fa:16:3e:a2:35:fc  txqueuelen 1000  (Ethernet)
        RX packets 2588797  bytes 3813498052 (3.5 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2376163  bytes 259234969 (247.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 533152  bytes 61652049 (58.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 533152  bytes 61652049 (58.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethfb25029: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::7442:c5ff:fe3a:feb0  prefixlen 64  scopeid 0x20<link>
        ether 76:42:c5:3a:fe:b0  txqueuelen 0  (Ethernet)
        RX packets 292346  bytes 399407212 (380.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 303602  bytes 555930033 (530.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@ecs-88500735 ~]# 

br-f9f273f75650: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.49.1 netmask 255.255.255.0 broadcast 192.168.49.255

2 nfs server
[root@ecs-88500735 ~]# mkdir -p /nfsdata/mysql/single
[root@ecs-88500735 ~]# chmod -R 777 /nfsdata/mysql/single
[root@ecs-88500735 ~]# vi /etc/exports

/nfsdata/mysql/single 192.168.49.0/24(rw,sync,no_root_squash)
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
~                                                                                                                                   
"/etc/exports" 1L, 62C
[root@ecs-88500735 ~]# systemctl restart rpcbind && systemctl enable rpcbind
[root@ecs-88500735 ~]# systemctl restart nfs-server && systemctl enable nfs-server
[root@ecs-88500735 single]# rpcinfo -p localhost
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
[root@ecs-88500735 ~]# exportfs -v
/nfsdata/mysql/single
		192.168.49.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
创建命名空间
[mini@ecs-88500735 single]$ su mini
[mini@ecs-88500735 single]$ minikube kubectl create namespace dev
namespace/dev created
定义PersistentVolumeClaim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-mysql-single
  namespace: dev
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: nfs
定义PersistentVolume.yaml
# 定义持久卷信息
apiVersion: v1
kind: PersistentVolume
metadata:
  # pv是没有namespace属性的,它是一种跨namespace的共享资源
  name: pv-mysql-single
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  # 存储类,具有相同存储类名称的pv和pvc才能进行绑定
  storageClassName: nfs
  nfs:
    path:  /nfsdata/mysql/single
    server: 192.168.49.1

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

定义 Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: mysql-single-pod
  name: mysql-single-pod
  namespace: dev
spec:
  selector:
    matchLabels:
      app: mysql-single-pod
  template:
    metadata:
      labels:
        app: mysql-single-pod
    spec:
      containers:
      - image: mysql:8.0
        name: mysql-single-pod
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"
        # - name: MYSQL_ALLOW_EMPTY_PASSWORD
        #   value: "1"
        ports:
        - containerPort: 3306
        volumeMounts:
        - name: mysql-single-pod-volume
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-single-pod-volume
        persistentVolumeClaim:
          claimName: pvc-mysql-single

在这里插入图片描述

在这里插入图片描述

定义Service.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: mysql-single-pod
  name: mysql-single-pod
  namespace: dev
spec:
  selector:
    app: mysql-single-pod
  type: NodePort
  ports:
  - port: 3306
    protocol: TCP
    targetPort: 3306
    nodePort: 32767

在这里插入图片描述
在这里插入图片描述

测试mysql8.0
[root@ecs-88500735 ~]# mysql -h 192.168.49.2 -P 32767
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory

ALTER USER ‘root’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
FLUSH PRIVILEGES;

在这里插入图片描述

[root@ecs-88500735 ~]# mysql -h 192.168.49.2 -P 32767 -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.29 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> exit
Bye
[root@ecs-88500735 ~]# 
[root@ecs-88500735 ~]# mysql -h 127.0.0.1 -P 32767 -uroot -p123456
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
[root@ecs-88500735 ~]# mysql -h 36.133.79.76 -P 32767 -uroot -p123456
ERROR 2003 (HY000): Can't connect to MySQL server on '36.133.79.76' (111)
nginx代理mysql
[root@ecs-88500735 ~]# vi /etc/nginx/nginx.conf
stream {
   upstream mysql-single {
	  server 192.168.49.2:32767;
   }
   server {
      listen 32767;
      proxy_pass mysql;
   }
}
[root@ecs-88500735 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@ecs-88500735 ~]# nginx -s reload
[root@ecs-88500735 ~]# 
[root@ecs-88500735 ~]# mysql -h 36.133.79.76 -P 32767 -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 8.0.29 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> exit
Bye
[root@ecs-88500735 ~]# mysql -h 127.0.0.1 -P 32767 -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 8.0.29 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐