Skip to content

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 (kubectl installed and configured)
  • Terminal access to your Ubuntu server
  • curl or wget for downloading files

Installation Methods

  1. Install Homebrew if not already installed:
bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. 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)"
  1. Install K9s:
bash
brew install derailed/k9s/k9s

Method 2: Using Binary Release

  1. Check the K9s releases page for the latest version

  2. 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
  1. Extract the archive:
bash
tar -xzvf k9s_Linux_arm64.tar.gz
  1. Move the binary to a directory in your PATH:
bash
sudo mv k9s /usr/local/bin/
  1. Make it executable:
bash
sudo chmod +x /usr/local/bin/k9s

Method 3: Using Snap

bash
sudo snap install k9s

Basic Configuration

K9s uses your existing Kubernetes configuration file (~/.kube/config) by default.

  1. Create a K9s configuration directory:
bash
mkdir -p ~/.config/k9s
  1. 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
EOF

Using K9s

  1. Launch K9s:
bash
k9s
  1. Basic navigation:

    • Use arrow keys to navigate
    • Press : to access command mode
    • Type help or press ? for help
    • Press Esc to go back or exit command mode
    • Press Ctrl+C to exit K9s
  2. Common commands in command mode:

    • :namespace or :ns - change namespace
    • :pods or :po - view pods
    • :deployments or :dp - view deployments
    • :services or :svc - view services
    • :contexts or :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
EOF

To use your skin, add this to your config:

bash
cat <<EOF >> ~/.config/k9s/config.yml
  ui:
    skin: mytheme
EOF

Customize 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
EOF

Troubleshooting

Common Issues

  1. K9s cannot connect to cluster

    • Verify your kubectl configuration works: kubectl get nodes
    • Check permissions on your kubeconfig file: ls -l ~/.kube/config
  2. 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
  3. 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.log

Updating K9s

For Homebrew installation:

bash
brew upgrade derailed/k9s/k9s

For binary installation:

Follow the same download procedure with the latest version.

For snap installation:

bash
sudo snap refresh k9s

Additional Resources