下载安装 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-amd64sudo 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 moduleavailable for the current kernel (3.10.0-1160.25.1.el7.x86_64) or it failed toload. Please recompile the kernel module and install it bysudo /sbin/vboxconfigYou 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
访问成功