安装minikube

下载安装 kubectl

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

下载minikube

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

sudo install minikube-linux-amd64 /usr/local/bin/minikube

依赖环境

minikube需要VirtualBox环境

安装 VirtualBox

# 下载地址
https://download.virtualbox.org/virtualbox/6.1.34/VirtualBox-6.1-6.1.34_150636_el7-2.x86_64.rpm

# 安装
sudo rpm -ivh VirtualBox-6.1-6.1.34_150636_el7-2.x86_64.rpm
# 报错的话就是依赖环境没安装 安装完下面的重新尝试安装VirtualBox
sudo yum install compat-libstdc++-33 SDL
sudo yum install gcc kernel-devel make libGL qt qt-devel libXmu

启动minikube

这是重新执行 minikube start 还是报错

[zlf@zlf nzb]$ minikube start
😄  minikube v1.25.2 on Centos 7.9.2009
👎  Unable to pick a default driver. Here is what was considered, in preference order:
    ▪ docker: Not healthy: "docker version --format {{.Server.Os}}-{{.Server.Version}}" 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
    ▪ docker: Suggestion: Add your user to the 'docker' group: 'sudo usermod -aG docker $USER && newgrp docker' <https://docs.docker.com/engine/install/linux-postinstall/>
    ▪ virtualbox: Not healthy: warning from virtualbox WARNING: The vboxdrv kernel module is not loaded. Either there is no module
         available for the current kernel (3.10.0-1160.25.1.el7.x86_64) or it failed to
         load. Please recompile the kernel module and install it by

           sudo /sbin/vboxconfig

         You will not be able to start VMs until this problem is fixed.
6.1.34r150636

    ▪ virtualbox: Suggestion: Read the docs for resolution <https://minikube.sigs.k8s.io/docs/reference/drivers/virtualbox/>
💡  Alternatively you could install one of these drivers:
    ▪ 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

❌  Exiting due to DRV_NOT_HEALTHY: Found driver(s) but none were healthy. See above for suggestions how to fix installed drivers.

我们执行 minikube start --driver=docker,还是报错,但是错误少了。

[zlf@zlf nzb]$ minikube start --driver=docker
😄  minikube v1.25.2 on Centos 7.9.2009
✨  Using the docker driver based on user configuration

💣  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
💡  Suggestion: Add your user to the 'docker' group: 'sudo usermod -aG docker $USER && newgrp docker'
📘  Documentation: https://docs.docker.com/engine/install/linux-postinstall/

执行 sudo usermod -aG docker $USER && newgrp docker 将当前用户加入docker组

当我们执行 minikube start 看到下述报错时

docker: Error response from daemon: Get https://registry-1.docker.io/v2/: x509: certificate is valid for *.toasttab.com, not registry-1.docker.io.

执行下面的即可

minikube start --image-mirror-country='cn' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'

在这里插入图片描述
查看状态
minikube status,表示启动成功
在这里插入图片描述

启动minikube dashboard

执行minikube dashboard
如果出现如下报错

[zlf@zlf nzb]$ minikube dashboard
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
🎉  Opening http://127.0.0.1:44973/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
START /bin/firefox "http://127.0.0.1:44973/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/"
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Running without a11y support!
Error: no DISPLAY environment variable specified
xdg-open: no method available for opening 'http://127.0.0.1:44973/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/'

❌  Exiting due to HOST_BROWSER: failed to open browser: exit status 3

采用一下方式进行启动

nohup  kubectl proxy --port=10888 --address='192.168.8.128' --accept-hosts='^.*' > ./nohup.out &

访问http://192.168.8.128:10888/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ 即可看到如下页面
在这里插入图片描述

测试小案例

创建部署

kubectl create deployment hello-minikube --image=registry.aliyuncs.com/google_containers/echoserver:1.10
# 将该pod 暴露他的端口为8080 
kubectl expose deployment hello-minikube --type=NodePort --port=8080

查看状态

[zlf@zlf ~]$ kubectl get pod
NAME                              READY   STATUS    RESTARTS   AGE
hello-minikube-6899fcbcf5-4rx8m   1/1     Running   0          15s

查看该service的url

[zlf@zlf ~]$ minikube service hello-minikube --url
http://192.168.49.2:31013

将端口转发到本机的端口,这样供给外界访问

## 端口转发,将pod的8080端口流量转发到本机7080端口
## --address 0.0.0.0  这个参数用于设置监听地址,默认值是localhost。如果设置为localhost,那么k8s会监听127.0.0.1和::1这两个地址,所以我们要设置为0.0.0.0 不设置的话外界pc无法访问

kubectl port-forward --address 0.0.0.0 service/hello-minikube  7080:8080

访问成功
在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值