Comprehensive Guide: Installing and Configuring K9s on Ubuntu Server
Introduction
K9s is a powerful terminal-based UI for managing Kubernetes clusters. It provides an intuitive interface to navigate, observe, and manage your Kubernetes resources in real-time.
Prerequisites
- Ubuntu Server (this guide works for all recent versions)
- A working Kubernetes cluster configuration (
kubectlinstalled and configured) - Terminal access to your Ubuntu server
curlorwgetfor downloading files
Installation Methods
Method 1: Using Homebrew (Recommended)
- Install Homebrew if not already installed:
bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"- Add Homebrew to your PATH (if not automatically added):
bash
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.profile
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"- Install K9s:
bash
brew install derailed/k9s/k9sMethod 2: Using Binary Release
Check the K9s releases page for the latest version
Download the appropriate binary:
bash
# Replace X.Y.Z with the latest version
wget https://github.com/derailed/k9s/releases/download/v0.40.10/k9s_Linux_x86_64.tar.gz
wget https://github.com/derailed/k9s/releases/download/v0.40.10/k9s_Linux_arm64.tar.gz- Extract the archive:
bash
tar -xzvf k9s_Linux_arm64.tar.gz- Move the binary to a directory in your PATH:
bash
sudo mv k9s /usr/local/bin/- Make it executable:
bash
sudo chmod +x /usr/local/bin/k9sMethod 3: Using Snap
bash
sudo snap install k9sBasic Configuration
K9s uses your existing Kubernetes configuration file (~/.kube/config) by default.
- Create a K9s configuration directory:
bash
mkdir -p ~/.config/k9s- Create a basic configuration file:
bash
cat <<EOF > ~/.config/k9s/config.yml
k9s:
refreshRate: 2
maxConnRetry: 5
enableMouse: true
headless: false
logoless: false
crumbsless: false
readOnly: false
noIcons: false
logger:
tail: 100
buffer: 5000
sinceSeconds: 60
fullScreenLogs: false
textWrap: false
showTime: false
EOFUsing K9s
- Launch K9s:
bash
k9sBasic navigation:
- Use arrow keys to navigate
- Press
:to access command mode - Type
helpor press?for help - Press
Escto go back or exit command mode - Press
Ctrl+Cto exit K9s
Common commands in command mode:
:namespaceor:ns- change namespace:podsor:po- view pods:deploymentsor:dp- view deployments:servicesor:svc- view services:contextsor:ctx- switch contexts
Advanced Configuration
Custom Skins
Create a custom skin file:
bash
mkdir -p ~/.config/k9s/skins
cat <<EOF > ~/.config/k9s/skins/mytheme.yml
# Custom K9s skin
k9s:
body:
fgColor: white
bgColor: black
logoColor: blue
prompt:
fgColor: white
bgColor: black
suggestColor: blue
info:
fgColor: green
sectionColor: white
dialog:
fgColor: white
bgColor: black
buttonFgColor: black
buttonBgColor: white
buttonFocusFgColor: white
buttonFocusBgColor: blue
labelFgColor: white
frame:
title:
fgColor: blue
bgColor: black
highlightColor: red
border:
fgColor: blue
focusColor: red
views:
table:
fgColor: white
bgColor: black
cursorFgColor: black
cursorBgColor: blue
EOFTo use your skin, add this to your config:
bash
cat <<EOF >> ~/.config/k9s/config.yml
ui:
skin: mytheme
EOFCustomize Hotkeys
You can define custom hotkeys:
bash
cat <<EOF >> ~/.config/k9s/config.yml
hotKey:
shift-0:
shortCut: Shift-0
description: View all pods
command: pods
shift-1:
shortCut: Shift-1
description: View deployments
command: deployments
shift-2:
shortCut: Shift-2
description: View services
command: services
EOFTroubleshooting
Common Issues
K9s cannot connect to cluster
- Verify your kubectl configuration works:
kubectl get nodes - Check permissions on your kubeconfig file:
ls -l ~/.kube/config
- Verify your kubectl configuration works:
Missing resources in K9s
- Ensure you have the right permissions:
kubectl auth can-i list pods - Check if you're in the correct namespace with
:namespace
- Ensure you have the right permissions:
K9s crashes or performs slowly
- Increase refresh rate in config (higher number = slower refresh)
- Set readOnly mode to true if you're only monitoring
Logs and Debugging
K9s logs are stored at:
~/.log/k9s.logUpdating K9s
For Homebrew installation:
bash
brew upgrade derailed/k9s/k9sFor binary installation:
Follow the same download procedure with the latest version.
For snap installation:
bash
sudo snap refresh k9s