kubectl port-forward bind: address already in use unable

前言

本地的 8080 映射到 Pod 的 80,kubectl 会把这个端口的所有数据都转发给集群内部的 Pod

kubectl port-forward wp-pod 8080:80 &

在命令的末尾使用了一个 & 符号,让端口转发工作在后台进行

发生报错:

Unable to listen on port 8080: Listeners failed to create with the following errors: [unable to create listener: Error listen tcp4 127.0.0.1:8080: bind: address already in use unable to create listener: Error listen tcp6 [::1]:8080: bind: address already in use]
error: unable to listen on any of the requested ports: [{8080 80}]

这是因为 kubectl 没有释放其端口绑定,你可以通过以下命令手动终止 pid(示例基于尝试向前运行8080端口)

lsof -i :8080

获得 pid 后,你可以通过标准的 kill-9 12345 将其杀死

posted @ 2023-03-04 09:42  牛奔  阅读(74)  评论(0编辑  收藏  举报