-
Notifications
You must be signed in to change notification settings - Fork 48
Add a kubeconfig command #94
Description
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):
- Copy the portable kubeconfig from the default machine's kubectl context (e.g.,
/etc/kubernetes/admin.confor~/.kube/config). - Execute a well-known script (e.g.,
/usr/local/bin/kubeconfig.sh) if present, to support clusters that generate configs dynamically.
- Copy the portable kubeconfig from the default machine's kubectl context (e.g.,
- 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-forwardorexpose portto 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, andsshcommands already solve the underlying primitives — this command orchestrates config extraction and endpoint exposure on top of them.