Skip to content

[QUESTION/HELP] Is there a way to have the HOSTNAME variable in k3d pods to match the node names if changed using k3s's "--node-name" #1599

@abullock66

Description

@abullock66

Question / Where do you need Help?

I was using the following yaml config to create a simple cluster and pass in the KUBECONFIG environment variable to remove the following messages in the docker logs

E0722 16:11:57.389363  143578 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0722 16:11:57.389756  143578 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0722 16:11:57.391202  143578 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0722 16:11:57.391531  143578 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
The connection to the server localhost:8080 was refused - did you specify the right host or port?

This error stems from the following line in the /bin/k3d-entrypoint.sh file

until kubectl uncordon "$HOSTNAME"; do sleep 3; done

My config.yaml

kind: Simple
apiVersion: k3d.io/v1alpha5
metadata:
  name: nodenames
servers: 1
agents: 1
kubeAPI:
  hostPort: "6443"
  host: "xxx.xxx.xxx.xxx"
network: k3d-edu
env:
  - envVar: KUBECONFIG=/var/lib/rancher/k3s/agent/k3scontroller.kubeconfig
    nodeFilters:
      - agent:*
options:
  k3d:
    wait: true
    disableLoadbalancer: false
    disableImageVolume: false
    disableRollback: false
    loadbalancer:
      configOverrides:
        - settings.workerConnections=2048
  k3s:
    extraArgs:
    - arg: --node-name=server-0
      nodeFilters:
      - server:0
    - arg: --node-name=node-0
      nodeFilters:
      - agent:0
  kubeconfig:
    updateDefaultKubeconfig: true
    switchCurrentContext: true
  runtime: {}

It seems that if the k3s --node-name arg is used, the HOSTNAME environment variable is still set to the default node name in which case it is unknown

root@server:~# docker exec -it k3d-nodenames-agent-0 sh
~ # hostname
k3d-nodenames-agent-0
~ # kubectl get nodes
NAME       STATUS   ROLES                  AGE   VERSION
node-0     Ready    <none>                 72s   v1.31.5+k3s1
server-0   Ready    control-plane,master   80s   v1.31.5+k3s1
~ # kubectl uncordon k3d-nodenames-agent-0
Error from server (NotFound): nodes "k3d-nodenames-agent-0" not found
~ # hostname
k3d-nodenames-agent-0
~ # kubectl uncordon $HOSTNAME
Error from server (NotFound): nodes "k3d-nodenames-agent-0" not found

Removing the k3s arg --node-name works

root@server:~# docker exec -it k3d-nonodenames-agent-0 sh
~ # kubectl get nodes
NAME                       STATUS   ROLES                  AGE   VERSION
k3d-nonodenames-agent-0    Ready    <none>                 53m   v1.31.5+k3s1
k3d-nonodenames-server-0   Ready    control-plane,master   53m   v1.31.5+k3s1
~ # until kubectl uncordon "$HOSTNAME"; do sleep 3; done
node/k3d-nonodenames-agent-0 already uncordoned

Is there a way to have the node names configured in the k3s Args to be used as the hostname ?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions