Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom k3s cluster name inside of the admin kubeconfig #144

Closed
alita1991 opened this issue Nov 9, 2023 · 2 comments
Closed

Custom k3s cluster name inside of the admin kubeconfig #144

alita1991 opened this issue Nov 9, 2023 · 2 comments
Assignees
Labels
kind/documentation Improvements or additions to documentation kind/question Further information is requested
Milestone

Comments

@alita1991
Copy link

alita1991 commented Nov 9, 2023

Hi,

I'm looking for a method to define the cluster name within the k3s admin kubeconfig file, particularly in situations where the kubeconfig is generated through Rancher. This becomes necessary when managing multiple distinct clusters, as the default name isn't sufficient.

At present, the admin kubeconfig contains the user and cluster name set as 'default'. One possible solution might involve substituting the 'default' string within the file with an alternative label. However, this adjustment could inadvertently affect the user value. I'm uncertain whether this could potentially cause any unforeseen issues.

Moreover, in cases where 'generate_ca_certificate = true', the cluster_domain is utilized. Nevertheless, its reliance on 'cluster.local' as a standard value could lead to a lack of uniqueness across clusters, considering it's utilized by k3s as a domain.

Thanks

@xunleii
Copy link
Owner

xunleii commented Nov 9, 2023

Hello,

Sorry, I didn't understand the first part:

I'm looking for a method to set the cluster name in the kubeconfig file of k3s admin, particularly in situations where the kubeconfig is generated by Rancher.

How can the kubeconfig be generated by Rancher using this module?


Apart from this point, my view is that it's an "advanced use" to modify the kubeconfig (even if it's simple) and must be done outside this module. It's entirely possible for the end user to generate a kubeconfig from the values in the kubernetes output, like the following (not tested)

module "k3s" {
  ...
}

local {
  kubeconfig = yamlencode({
    apiVersion      = "v1"
    kind            = "Config"
    current-context = "CLUSTER_NAME"
    contexts = [{
      context = {
        cluster = "CLUSTER_NAME"
        user : "CLUSTER_NAME_ADMIN"
      }
      name = "CLUSTER_NAME"
    }]
    clusters = [{
      cluster = {
        certificate-authority-data = base64encode(module.k3s.kubernetes.cluster_ca_certificate)
        server                     = module.k3s.kubernetes.api_endpoint
      }
      name = "CLUSTER_NAME"
    }]
    users = [{
      user = {
        client-certificate-data : base64encode(module.k3s.kubernetes.client_certificate)
        client-key-data : base64encode(module.k3s.kubernetes.client_key)
      }
      name : "CLUSTER_NAME_ADMIN"
    }]
  })
}

However, is needed to explain how to do this in the documentation.

@xunleii xunleii self-assigned this Nov 9, 2023
@xunleii xunleii added kind/documentation Improvements or additions to documentation kind/question Further information is requested labels Nov 9, 2023
@alita1991
Copy link
Author

Hi @xunleii, regarding the k3s admin kubeconfig, I was looking for a way to tell rancher to generate a local kubeconfig with the correct context (custom cluster name), but probably this is available only with k3d.

For the second problem, your solution could work, thanks for the feedback.

@xunleii xunleii added this to the v3.4.0 milestone Nov 10, 2023
xunleii added a commit that referenced this issue Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Improvements or additions to documentation kind/question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants