WSL2中 使用 minikube 无法访问 pod 中服务的问题

WSL2 使用 minikube 无法访问 pod 中服务的问题

环境:

windows10 wsl2 Ubuntu 20.04

minikube version: v1.25.2

终端命令:
 # 1.启动 minikube
 minikube start --force --driver=docker 
 
 # 2.创建 一个 nginx 容器的 deployment 名为 nginx-deploy
 kubectl create deployment nginx-deploy --image=nginx
 
 # 3.为 nginx-deploy 创建 service,并通过Service的 8001 端口转发至容器的 80 端口上。
 kubectl expose deploy nginx-deploy --port=8001 --target-port=80
 
 # 4.启动网络网络浏览器
 minikube service nginx-deploy 

第四步出错:

service default/nginx-deploy has no node port
Starting tunnel for service nginx-deploy.
Because you are using a Docker driver on linux, the terminal needs to be open to run it.

解决方法:

使用官网介绍的另一种方法,使用 kubectl 转发 端口

官网地址

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

对应上面这个例子就是:

# 5.使用 kubectl  转发 7080 端口到 8001 端口
kubectl port-forward service/nginx-deploy  7080:8001

然后就可以在另一个终端窗口通过 curl 127.0.0.1:7080

或者在浏览器通过地址:http://localhost:7080/ 访问了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值