kubernetes - 如何为“kubectl port-forward”设置正确的端口(奇怪地转到 localhost:8080)
问题描述
我通过 kubeadm 安装 kubernetes 并关闭并再次启动。然后只是kubectl port-forward
不起作用。
以下命令有效。
kubectl top nodes
但是 kubectl 端口转发失败。有什么建议吗?似乎只有端口转发到 localhost:8080。不工作
sudo kubectl port-forward -n istio-system svc/istio-ingressgateway 80:80 --address 0.0.0.0
正常模式下的日志如下。
The connection to the server localhost:8080 was refused - did you specify the right host or port?
对于调试模式日志
I0930 01:44:46.904299 47718 round_trippers.go:423] curl -k -v -XGET -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.17.12 (linux/amd64) kubernetes/5ec4722" 'http://localhost:8080/api?timeout=32s'
I0930 01:44:46.904927 47718 round_trippers.go:443] GET http://localhost:8080/api?timeout=32s in 0 milliseconds
I0930 01:44:46.904948 47718 round_trippers.go:449] Response Headers:
I0930 01:44:46.904987 47718 cached_discovery.go:121] skipped caching discovery info due to Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
I0930 01:44:46.905009 47718 shortcut.go:89] Error loading discovery information: Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
I0930 01:44:46.905067 47718 round_trippers.go:423] curl -k -v -XGET -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.17.12 (linux/amd64) kubernetes/5ec4722" 'http://localhost:8080/api?timeout=32s'
I0930 01:44:46.905222 47718 round_trippers.go:443] GET http://localhost:8080/api?timeout=32s in 0 milliseconds
I0930 01:44:46.905240 47718 round_trippers.go:449] Response Headers:
I0930 01:44:46.905263 47718 cached_discovery.go:121] skipped caching discovery info due to Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
I0930 01:44:46.905325 47718 round_trippers.go:423] curl -k -v -XGET -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.17.12 (linux/amd64) kubernetes/5ec4722" 'http://localhost:8080/api?timeout=32s'
I0930 01:44:46.905465 47718 round_trippers.go:443] GET http://localhost:8080/api?timeout=32s in 0 milliseconds
I0930 01:44:46.905482 47718 round_trippers.go:449] Response Headers:
I0930 01:44:46.905504 47718 cached_discovery.go:121] skipped caching discovery info due to Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
I0930 01:44:46.905556 47718 round_trippers.go:423] curl -k -v -XGET -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.17.12 (linux/amd64) kubernetes/5ec4722" 'http://localhost:8080/api?timeout=32s'
I0930 01:44:46.905695 47718 round_trippers.go:443] GET http://localhost:8080/api?timeout=32s in 0 milliseconds
I0930 01:44:46.905712 47718 round_trippers.go:449] Response Headers:
I0930 01:44:46.905734 47718 cached_discovery.go:121] skipped caching discovery info due to Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
I0930 01:44:46.905759 47718 helpers.go:221] Connection error: Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
F0930 01:44:46.905785 47718 helpers.go:114] The connection to the server localhost:8080 was refused - did you specify the right host or port?
kubectl config view
如下
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://172.31.3.157:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
作为参考,工作kubectl top nodes
调试模式如下,(日志太长,我只附上标题)
I0930 01:46:47.625764 49195 loader.go:375] Config loaded from file: /home/ubuntu/.kube/config
I0930 01:46:47.641064 49195 round_trippers.go:423] curl -k -v -XGET -H "User-Agent: kubectl/v1.17.12 (linux/amd64) kubernetes/5ec4722" -H "Accept: application/json, */*" 'https://172.31.3.157:6443/api?timeout=32s'
I0930 01:46:47.680091 49195 round_trippers.go:443] GET https://172.31.3.157:6443/api?timeout=32s 200 OK in 39 milliseconds
I0930 01:46:47.680116 49195 round_trippers.go:449] Response Headers:
I0930 01:46:47.680123 49195 round_trippers.go:452] Cache-Control: no-cache, private
I0930 01:46:47.680128 49195 round_trippers.go:452] Content-Type: application/json
I0930 01:46:47.680134 49195 round_trippers.go:452] Content-Length: 135
I0930 01:46:47.680139 49195 round_trippers.go:452] Date: Wed, 30 Sep 2020 01:46:47 GMT
I0930 01:46:47.680340 49195 request.go:1017] Response Body: {"kind":"APIVersions","versions":["v1"],"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"172.31.3.157:6443"}]}
I0930 01:46:47.680594 49195 round_trippers.go:423] curl -k -v -XGET -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.17.12 (linux/amd64) kubernetes/5ec4722" 'https://172.31.3.157:6443/apis?timeout=32s'
解决方案
推荐阅读
- gerrit - Gerrit 搜索查询多用户且处于打开状态
- python - python脚本打开页面并点击下载
- php - 如何在 Laravel 中处理具有唯一性的迁移回滚中的现有记录?
- node.js - 完成错误“不支持平台“GOOGLE_HANGOUTS”。”在点击 API 后使用内联编辑器完成我的代码时
- elasticsearch - 如何计算 Elasticsearch 中每个产品的平均评分
- laravel - 在 laravel 中加入两个完全不同的表
- python - 如何使用python在wsl(Linux的Windows子系统)上打开和运行一些命令?
- javascript - Esprima 获取函数和变量声明
- java - java - 如何使用selenium java中的assert检查产品的价格是否在给定范围内
- python - 如何删除带有不均匀数字的空 matplotlib AxesGrid 单元格?