minikube是启动一个虚拟机来模拟单节点环境,容器运行在单独的网络环境
可以看到192.168.49.2:8443是api server地址,是虚拟的ip
(base) [root@localhost access]# kubectl config view
apiVersion: v1
clusters:
- cluster:certificate-authority: /root/.minikube/ca.crtextensions:- extension:last-update: Fri, 19 Apr 2024 14:52:06 CSTprovider: minikube.sigs.k8s.ioversion: v1.32.0name: cluster_infoserver: https://192.168.49.2:8443name: minikube
contexts:
- context:cluster: minikubeextensions:- extension:last-update: Fri, 19 Apr 2024 14:52:06 CSTprovider: minikube.sigs.k8s.ioversion: v1.32.0name: context_infonamespace: defaultuser: minikubename: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikubeuser:client-certificate: /root/.minikube/profiles/minikube/client.crtclient-key: /root/.minikube/profiles/minikube/client.key
只能在本机访问,所以无法远程访问
(base) [root@localhost ~]# docker port minikube
22/tcp -> 127.0.0.1:32792
2376/tcp -> 127.0.0.1:32791
5000/tcp -> 127.0.0.1:32790
8443/tcp -> 127.0.0.1:32789
32443/tcp -> 127.0.0.1:32788
需要通过参数--listen-address=0.0.0.0 --apiserver-ips=主机ip地址参数来重启minikube才能远程访问:
1、如果已经创建了minikube,需要先minikube delete删除
2、重新启动minikube start --listen-address=0.0.0.0 --apiserver-ips=本机ip地址
3、启动成功后,检查监听网络。看到8443/tcp -> 0.0.0.0:32769对应的本机的端口是32769,那么远程通过本机ip地址:32769来访问api server
(base) [root@localhost access]# docker port minikube
22/tcp -> 0.0.0.0:32772
2376/tcp -> 0.0.0.0:32771
5000/tcp -> 0.0.0.0:32770
8443/tcp -> 0.0.0.0:32769
32443/tcp -> 0.0.0.0:32768
4、配置远程访问的kubectl参数,需要config(就是kubectl config view命令的输出),修改config中的server地址为第3步的ip端口;config文件中指定的ca.crt、client.crt和client.key三个文件,就可以在远程访问minikube的k8s了。
E:\k8s>kubectl.exe --kubeconfig C:\Users\Administrator\.kube\config get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 24m v1.28.3
参考:
Remote access minikube service problem when I minikube start --listen-address='0.0.0.0', it not works, no any local address listening · Issue #14364 · kubernetes/minikube · GitHub