lima icon indicating copy to clipboard operation
lima copied to clipboard

kubernetes node join param url wrong in documentation

Open lethargosapatheia opened this issue 2 months ago • 9 comments

Description

It looks like the instructions for Lima v2.1 to add a kubernetes node to a cluster are wrong, and namely the param url: it shouldn't contain https://. So the correct way to do it is this:

limactl start --name k8s-1 --network lima:user-v2 template:k8s \
              --param url="<ADDRESS_FROM_ABOVE>" --param token="<TOKEN_FROM_ABOVE>" \
              --param discoveryTokenCaCertHash="<DISCOVERY_TOKEN_CA_CERT_HASH_FROM_ABOVE>"

And the discovery token should also contain sha256, just like in the join command printed on the main node – not that the documentation necessarily says differently :)

lethargosapatheia avatar Sep 30 '26 18:09 lethargosapatheia

It was cryptically hidden as "ADDRESS_FROM_ABOVE", as opposed to "URL_FROM_ABOVE" (that k3s.yaml is using)

The whole thing is a bit on the ridiculously complicated side, actually. It should be just one simple line, not three. e.g. save the join command to a file or something (or just the parameters in it, like the url and the token - etc)

More similar to how the KUBECONFIG is transported, for when you want to connect to it from the host kubectl.

afbjorklund avatar Sep 30 '26 18:09 afbjorklund

I think the template could just filter out any "https://" prefix, before feeding it to the "endpoint" parameter:

    discovery:
      bootstrapToken:
        apiServerEndpoint: "{{.Param.url}}"
        token: "{{.Param.token}}"
        caCertHashes:
        - "{{.Param.discoveryTokenCaCertHash}}"

Then the contents of the parameters would be more obvious (i.e. match the key!), and it would be more smooth.

It is less convoluted (less YAML and crud) on the k3s side: K3S_URL={{.Param.url}} K3S_TOKEN={{.Param.token}}

VERSION="{{.Param.version}}"

kubernetesVersion: "${VERSION}"

API_SERVER_ENDPOINT=$(echo "{{.Param.url}}" | sed -e "s|https://||")

        apiServerEndpoint: "${API_SERVER_ENDPOINT}"

afbjorklund avatar Sep 30 '26 18:09 afbjorklund

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.5.15:6443 --token 8oakoy.a9e04lcq66mka7vt \
	--discovery-token-ca-cert-hash sha256:76ef93fc5e21ae0aec32758045566158af629c9c39d2d89800016cfcf66d2ffb 

The copying of kubeconfig and the pod network are already taken care of...

But the join command? "(The parameters for the start command printed here)"

So we could then print out a "https://" and we could add some comments for the params.

param:
  # url ("https://<IP>:6443")
  url: "https://192.168.5.15:6443"
  # --token ("...")
  token: "8oakoy.a9e04lcq66mka7vt"
  # --discovery-token-ca-cert-hash ("sha256:...")
  discoveryTokenCaCertHash: "sha256:76ef93fc5e21ae0aec32758045566158af629c9c39d2d89800016cfcf66d2ffb"

afbjorklund avatar Sep 30 '26 19:09 afbjorklund

I removed the https:// prefix from the URL parameter in the Kubernetes example to match the IP:port format expected by kubeadm join. (PR: #5559)

Sarthak-Shreshtha01 avatar Oct 02 '26 16:10 Sarthak-Shreshtha01

But then it is not an url anymore (but an "api server endpoint" or whatever). I mean it could still be a bug, but I don't like the fix.

afbjorklund avatar Oct 03 '26 07:10 afbjorklund

Then maybe switch the param name to 'address'? :)

lethargosapatheia avatar Oct 03 '26 07:10 lethargosapatheia

Maybe my comments above were not clear, but I wanted it to match the k3s behaviour - since k8s just uses a "join command"

afbjorklund avatar Oct 03 '26 07:10 afbjorklund

Anyway, it's bad if doesn't work - and we should test our code.

Problem is that we don't really compile the comments or docs...


So it was fixed in one place, and left in the other. And BATS a third.

templates/k3s.yaml:#                 --param url="<URL_FROM_ABOVE>" --param token="<TOKEN_FROM_ABOVE>"
templates/k8s.yaml:#                 --param url="<ADDRESS_FROM_ABOVE>" --param token="<TOKEN_FROM_ABOVE>" \
website/content/en/docs/examples/containers/kubernetes/_index.md:              --param url="https://<ADDRESS_FROM_ABOVE>" --param token="<TOKEN_FROM_ABOVE>" \
website/content/en/docs/examples/containers/kubernetes/_index.md:              --param url="<URL_FROM_ABOVE>" --param token="<TOKEN_FROM_ABOVE>"

So eventually it would be nice, if the whole thing was more simple?

                # Get the join command from the first node
                join_command=$(limactl shell "${NAME}-0" sudo kubeadm token create --print-join-command)
                # kubeadm join ADDRESS --token TOKEN --discovery-token-ca-cert-hash DISCOVERY_TOKEN_CA_CERT_HASH
                read -ra words <<< "$join_command"
                assert_equal "${words[1]} ${words[3]} ${words[5]}" "join --token --discovery-token-ca-cert-hash"
                params=".param.url=\"${words[2]}\"|.param.token=\"${words[4]}\"|.param.discoveryTokenCaCertHash=\"${words[6]}\""

afbjorklund avatar Oct 03 '26 07:10 afbjorklund

Agreed, I reworked #5559 that way: url stays a URL like in k3s, and the k8s template strips the https:// itself before writing apiServerEndpoint (a bare address still works too). The template comment and the BATS test now use https://<ADDRESS>, so the documented form is the one being tested.

I checked it with limactl template validate templates/k8s.yaml and by running the rendered join step with --param url="https://192.168.5.15:6443": the generated JoinConfiguration has apiServerEndpoint: "192.168.5.15:6443". I have not run the multi-node BATS test itself, since it needs the VMs.

Is this approach fine, or would you like anything else in this PR? I left the one-line join out to keep it small.

Sarthak-Shreshtha01 avatar Oct 03 '26 09:10 Sarthak-Shreshtha01