How to set correct port for "kubectl port-forward" (strangely goes to localhost:8080)

1000 views Asked by At

I install kubernetes by kubeadm and shut down and boot again. Then only kubectl port-forward does not work.

The following command works.

kubectl top nodes

But kubectl port-forward fails. Is there any suggestion? It seems only port-forward goes to localhost:8080. Does not work

sudo kubectl port-forward -n istio-system svc/istio-ingressgateway 80:80 --address 0.0.0.0

Logs are following for normal mode.

The connection to the server localhost:8080 was refused - did you specify the right host or port?

For debug mode log

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 is follows

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

As a reference, working kubectl top nodes debug mode is follows, (Log is too long, I attached header only)

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'
0

There are 0 answers