Shell Integration Setup
About 750 wordsAbout 3 min
2025-01-27
Set up seamless shell integration so tka login automatically updates your shell environment without manual export commands.
Overview
By default, TKA cannot modify your shell's environment variables because subprocesses cannot change the parent shell's state. Shell integration solves this by installing a wrapper function that intercepts TKA commands and automatically evaluates environment exports.
Supported Shells
- Bash
- Zsh
- Fish
- PowerShell
Installation
Generate Integration Code
First, generate the shell integration code for your shell:
tka generate integration [bash|zsh|fish|powershell]Install Integration
bashAdd to your shell's configuration file:
# add to ~/.bashrc or ~/.bash_profile eval "$(tka generate integration bash)"Then reload your shell:
source ~/.bashrczshAdd to your shell's configuration file:
# add to ~/.zshrc eval "$(tka generate integration zsh)"Then reload your shell:
source ~/.zshrcFishAdd to your Fish configuration:
# Add to ~/.config/fish/config.fish tka generate integration fish | sourceReload Fish:
source ~/.config/fish/config.fishPowerShellAdd to your PowerShell profile:
# Find your profile location $PROFILE # Add this line to your profile tka generate integration powershell | Out-String | Invoke-ExpressionReload PowerShell or run:
. $PROFILE
Usage After Integration
Once installed, TKA commands work seamlessly:
Automatic Environment Updates
Before
$ tka login
✓ sign-in successful!
╭───────────────────────────────────────╮
│ User: [email protected] │
│ Role: cluster-admin │
│ Until: Mon, 27 Jan 2025 18:30:00 CET │
╰───────────────────────────────────────╯
✓ kubeconfig written to: /tmp/kubeconfig-123456.yaml
→ To use this session, run: export KUBECONFIG=/tmp/kubeconfig-123456.yaml
$ export KUBECONFIG=/tmp/kubeconfig-123456.yaml
$ kubectl get pods
...After
$ tka login
# Your KUBECONFIG is automatically set!
$ kubectl get pods
# Works immediatelyNote
The shell integration is roughly equal to
eval "$(command ts-k8s-auth login --quiet)"To learn more, I encourage you to checkout the source code or check out the Developer Documentation: Shell Integration Details
Supported Commands
The wrapper automatically handles these commands:
tka login- Sets$KUBECONFIGafter successful authenticationtka refresh/tka reauthenticate- Updates$KUBECONFIGwith refreshed credentialstka logout- Unsets$KUBECONFIGand cleans up temp files
Bypass Integration
To see full output without environment updates:
tka login --no-evalThis shows the traditional output with manual export instructions.
Troubleshooting
Integration Not Working
Verify Installation:
type tka # Should show it's a function, not a binaryCheck Path:
which tka # Should show the binary pathReload Shell:
source ~/.bashrc # or your shell's config file
Multiple TKA Installations
If you have multiple TKA binaries:
# Specify full path in integration
eval "$(/usr/local/bin/tka generate integration bash)"Permission Issues
Ensure the TKA binary is executable:
chmod +x /path/to/tkaEnvironment Not Updating
- Check Integration Code: Re-run the integration command to see if there are syntax errors
- Manual Test: Try
tka login --no-evaland manually export the KUBECONFIG - Shell Compatibility: Ensure you're using a supported shell version
Fish-Specific Issues
Fish uses different syntax. If you see errors:
# Check Fish version
fish --version
# Verify integration code works
tka generate integration fish | fish_indentPowerShell-Specific Issues
For PowerShell execution policy issues:
# Check execution policy
Get-ExecutionPolicy
# If needed, set policy (run as administrator)
Set-ExecutionPolicy RemoteSignedAdvanced Configuration
Custom Wrapper Location
Store the wrapper in a custom location:
# Generate and save wrapper
tka generate integration bash > ~/.local/share/tka/wrapper.sh
# Source from your shell config
source ~/.local/share/tka/wrapper.shConditional Loading
Load integration only when TKA is available:
# In ~/.bashrc or ~/.zshrc
if command -v tka >/dev/null 2>&1; then
eval "$(tka generate integration bash)" # or zsh
fiMultiple Environments
For different TKA configurations per project:
# Project-specific wrapper
alias tka-prod='TKA_TAILSCALE_TAILNET=prod.ts.net tka'
alias tka-dev='TKA_TAILSCALE_TAILNET=dev.ts.net tka'Uninstalling Integration
Remove from Shell Config
Edit your shell configuration file
Remove or comment out the integration line:
# eval "$(tka generate integration bash)"Reload your shell
Clean Up Temporary Files
# Remove any remaining temp kubeconfig files
rm -f /tmp/kubeconfig-*.yaml
# Unset environment variables
unset KUBECONFIGSecurity Considerations
- The wrapper only evaluates specific TKA output patterns
- Temporary kubeconfig files are created with restricted permissions (600)
- Integration code can be reviewed before installation
- No sensitive data is stored in shell history
