How ahmetb/kubectx works
kubectx and kubens are command-line tools for managing the active Kubernetes context and namespace. Users invoke a command to inspect or change kubeconfig settings; kubens can also query namespaces from the active cluster. kubectx additionally supports context rename/delete, interactive selection, and isolated or read-only shells. The graph follows documented capabilities and sampled entry points; some command-to-helper wiring is inferred from the file layout, so uncertain internal calls are omitted.
Main entry points: kubeconfigloader.go Load kubeconfig · kubectx/main.go kubectx CLI · shell_session.go Shell session · kubens/main.go kubens CLI
Components 24
kubectx
- kubectx CLI
cmd/kubectx/main.go - Switch context
cmd/kubectx/switch.go - List contexts
cmd/kubectx/list.go - Rename context
cmd/kubectx/rename.go - Delete context
cmd/kubectx/delete.go - Show context
cmd/kubectx/current.go - Context picker
cmd/kubectx/fzf.go
kubens
- kubens CLI
cmd/kubens/main.go - Switch namespace
cmd/kubens/switch.go - List namespaces
cmd/kubens/list.go - Show namespace
cmd/kubens/current.go - Namespace picker
cmd/kubens/fzf.go
Kubeconfig core
- Load kubeconfig
internal/kubeconfig/kubeconfigloader.go - Context access
internal/kubeconfig/contexts.go - Context updates
internal/kubeconfig/contextmodify.go - Namespace access
internal/kubeconfig/namespace.go - Current context
internal/kubeconfig/currentcontext.go
Shell modes
- Shell session
cmd/kubectx/shell_session.go - Read-only proxy
internal/proxy/readonly.go
Other components
- User
- Kubeconfig files
- Interactive shell
- Kubernetes API
- fzf
Connections 42
- User → kubectx CLI: invokes
- User → kubens CLI: invokes
- kubectx CLI → Switch context: dispatches
- kubectx CLI → List contexts: dispatches
- kubectx CLI → Rename context: dispatches
- kubectx CLI → Delete context: dispatches
- kubectx CLI → Show context: dispatches
- kubectx CLI → Context picker: dispatches
- kubectx CLI → Shell session: starts shell
- kubens CLI → Switch namespace: dispatches
- kubens CLI → List namespaces: dispatches
- kubens CLI → Show namespace: dispatches
- kubens CLI → Namespace picker: dispatches
- Switch context → Load kubeconfig: loads config
- Switch context → Context updates: updates context
- List contexts → Load kubeconfig: loads config
- List contexts → Context access: reads contexts
- Rename context → Load kubeconfig: loads config
- Rename context → Context updates: renames context
- Delete context → Load kubeconfig: loads config
- Delete context → Context updates: deletes context
- Show context → Load kubeconfig: loads config
- Show context → Current context: reads current
- Context picker → fzf: runs picker
- List namespaces → Load kubeconfig: loads config
- List namespaces → Current context: reads context
- List namespaces → Namespace access: reads namespace
- List namespaces → Kubernetes API: queries namespaces
- Switch namespace → Load kubeconfig: loads config
- Switch namespace → Namespace access: updates namespace
- Show namespace → Load kubeconfig: loads config
- Show namespace → Namespace access: reads namespace
- Namespace picker → fzf: runs picker
- Shell session → Load kubeconfig: loads config
- Shell session → Context access: checks context
- Shell session → Current context: reads current
- Shell session → Interactive shell: launches
- Shell session → Read-only proxy: configures proxy
- Interactive shell → Kubeconfig files: uses isolated config
- Read-only proxy → Kubernetes API: proxies allowed requests
- Load kubeconfig → Kubeconfig files: reads config
- Context updates → Kubeconfig files: writes config