AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
`Port Forward`是直接将本地端口与 Pod 端口绑定,通常用于调试服务。 当客户端发送请求到 kubectl 监听的本地端口后,kubectl 会将数据发送给 apiServer,apiServer 与 kubelet 建立连接,然后通过目标 Pod 端口以及 Pod 内部指定的容器端口,最终将请求送达。 我们直接使用命令创建一个 nginx Pod 进行查看: ~~~bash $ kubectl run --generator=run-pod/v1 nginx --image nginx:1.7.9 --port=80 pod/nginx created ~~~ 查看 nginx Pod 监听的端口: ~~~bash $ kubectl get pods nginx --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}' 80 ~~~ 现在将本地的 3000 端口转发到 nginx Pod 的 80 端口: ~~~bash $ kubectl port-forward nginx 3000:80 Forwarding from 127.0.0.1:3000 -> 80 ~~~ 新开一个终端访问`127.0.0.1:3000`地址: ~~~bash $ curl 127.0.0.1:3000 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> ~~~