Skip to content

Add a kubeconfig command #94

@sagikazarmark

Description

@sagikazarmark

labctl has no built-in way to obtain a usable kubeconfig from a running Kubernetes playground. Users who want to run kubectl locally must manually SSH in to extract the config, separately expose or forward the API server port, and then rewrite the server address to match. A dedicated labctl kubeconfig command should automate this: extract the config from the playground machine, expose the API server endpoint, and output a kubeconfig with the server address pointed at the locally-reachable endpoint.

Motivation

labctl already bridges the local/remote gap for shells (ssh), editors (ide), and network access (port-forward, expose port). Kubernetes playgrounds are a core use case, yet kubectl access — the most common interaction — still requires manual plumbing across multiple commands. Closing this gap makes the Kubernetes learning and experimentation workflow seamless from the terminal.

Proposed Approach

  • Establish a convention for locating kubeconfig inside the playground VM. Two candidates (try in order):
    1. Copy the portable kubeconfig from the default machine's kubectl context (e.g., /etc/kubernetes/admin.conf or ~/.kube/config).
    2. Execute a well-known script (e.g., /usr/local/bin/kubeconfig.sh) if present, to support clusters that generate configs dynamically.
  • Make the API server reachable locally and rewrite the server: field in the retrieved config to match.
  • Support --machine <name> flag for multi-machine playgrounds where the control plane is not on the default machine.

Additional Context

  • Open design question: should the command use port-forward or expose port to make the API server reachable? Trade-offs around persistence, auth, and HTTPS handling differ between the two.
  • Open question: how to discover the API server port reliably when different Kubernetes distributions (kubeadm, k3s, kind) use different defaults.
  • The existing port-forward, expose port, and ssh commands already solve the underlying primitives — this command orchestrates config extraction and endpoint exposure on top of them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions