k3s-io / k3s

Lightweight Kubernetes
https://k3s.io
Apache License 2.0
27.94k stars 2.33k forks source link

[Release-1.27] - Not able to connect to kubelet when using bind-address flag #10479

Closed brandond closed 3 months ago

brandond commented 3 months ago

Backport fix for Not able to connect to kubelet when using bind-address flag

aganesh-suse commented 3 months ago

Validated on release-1.27 branch with commit 5b9a3fced6f8b98fa2fd469c0c23685498208f40

Environment Details

Infrastructure

Node(s) CPU architecture, OS, and Version:

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.2 LTS"

$ uname -m
x86_64

Cluster Configuration:

HA: 3 server/ 1 agent

Config.yaml:

token: xxxx
cluster-init: true
bind-address: 172.31.23.250
write-kubeconfig-mode: "0644"
node-external-ip: 1.1.1.1
node-label:
- k3s-upgrade=server

Testing Steps

  1. Copy config.yaml
    $ sudo mkdir -p /etc/rancher/k3s && sudo cp config.yaml /etc/rancher/k3s
  2. Install k3s
    curl -sfL https://get.k3s.io | sudo INSTALL_K3S_COMMIT='5b9a3fced6f8b98fa2fd469c0c23685498208f40' sh -s - server
  3. Verify Cluster Status:
    kubectl get nodes -o wide
    kubectl get pods -A
  4. Verify we can perform 'kubectl logs' and 'kubectl exec' actions.

Replication Results:

$ sudo ss -lpn 'sport = :10250' 
Netid State  Recv-Q Send-Q Local Address:Port  Peer Address:PortProcess
tcp   LISTEN 0      4096   172.31.23.250:10250      0.0.0.0:*    users:(("k3s-server",pid=2840,fd=175))

$ sudo /usr/local/bin/kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml logs pod/metrics-server-c44988498-k7tbh -n kube-system | grep 'v1beta1.metrics.k8s.io failed' 
Error from server: Get "https://172.31.23.250:10250/containerLogs/kube-system/metrics-server-c44988498-k7tbh/metrics-server": proxy error from 172.31.23.250:6443 while dialing 172.31.23.250:10250, code 502: 502 Bad Gateway

$ sudo /usr/local/bin/kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml exec --namespace=kube-system local-path-provisioner-5c6c7f7cd-x7w2x -- sh -c 'ls' 
Error from server: error dialing backend: proxy error from 172.31.23.250:6443 while dialing 172.31.23.250:10250, code 502: 502 Bad Gateway

Validation Results:

$ sudo ss -lpn 'sport = :10250' 
Netid State  Recv-Q Send-Q Local Address:Port  Peer Address:PortProcess
tcp   LISTEN 0      4096   172.31.23.250:10250      0.0.0.0:*    users:(("k3s-server",pid=9199,fd=175))
$ sudo /usr/local/bin/kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml logs pod/metrics-server-c44988498-5qd6k -n kube-system | grep 'v1beta1.metrics.k8s.io failed'
$ sudo /usr/local/bin/kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml exec --namespace=kube-system local-path-provisioner-6fbb7c76c5-gghvs -- sh -c 'ls' 
bin
dev
etc
home
lib
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var