Project Icon

k9s

Kubernetes集群管理的终端用户界面工具

K9s是一个为Kubernetes提供终端用户界面的集群管理工具。它实时监控集群变化,提供丰富的资源操作命令,简化了集群的导航、观察和管理流程。K9s支持多种安装方式,兼容主流操作系统,并允许自定义配置。作为开源项目,K9s为用户提供了直观高效的Kubernetes集群管理体验。

k9s

K9s - Kubernetes CLI To Manage Your Clusters In Style!

K9s provides a terminal UI to interact with your Kubernetes clusters. The aim of this project is to make it easier to navigate, observe and manage your applications in the wild. K9s continually watches Kubernetes for changes and offers subsequent commands to interact with your observed resources.


Note...

K9s is not pimped out by a big corporation with deep pockets. It is a complex OSS project that demands a lot of my time to maintain and support. K9s will always remain OSS and therefore free! That said, if you feel k9s makes your day to day Kubernetes journey a tad brighter, saves you time and makes you more productive, please consider sponsoring us! Your donations will go a long way in keeping our servers lights on and beers in our fridge!

Thank you!


Go Report Card golangci badge codebeat badge Build Status Docker Repository on Quay release License Releases


Screenshots

  1. Pods
  2. Logs
  3. Deployments

Demo Videos/Recordings


Documentation

Please refer to our K9s documentation site for installation, usage, customization and tips.

Slack Channel

Wanna discuss K9s features with your fellow K9sers or simply show your support for this tool?

Installation

K9s is available on Linux, macOS and Windows platforms. Binaries for Linux, Windows and Mac are available as tarballs in the release page.

  • Via Homebrew for macOS or Linux

    brew install derailed/k9s/k9s
    
  • Via MacPorts

    sudo port install k9s
    
  • Via snap for Linux

    snap install k9s --devmode
    
  • On Arch Linux

    pacman -S k9s
    
  • On OpenSUSE Linux distribution

    zypper install k9s
    
  • On FreeBSD

    pkg install k9s
    
  • Via Winget for Windows

    winget install k9s
    
  • Via Scoop for Windows

    scoop install k9s
    
  • Via Chocolatey for Windows

    choco install k9s
    
  • Via a GO install

    # NOTE: The dev version will be in effect!
    go install github.com/derailed/k9s@latest
    
  • Via Webi for Linux and macOS

    curl -sS https://webinstall.dev/k9s | bash
    
  • Via pkgx for Linux and macOS

    pkgx k9s
    
  • Via Webi for Windows

    curl.exe -A MS https://webinstall.dev/k9s | powershell
    
  • As a Docker Desktop Extension (for the Docker Desktop built in Kubernetes Server)

    docker extension install spurin/k9s-dd-extension:latest
    

Building From Source

K9s is currently using GO v1.21.X or above. In order to build K9s from source you must:

  1. Clone the repo

  2. Build and run the executable

    make build && ./execs/k9s
    

Running with Docker

Running the official Docker image

You can run k9s as a Docker container by mounting your KUBECONFIG:

docker run --rm -it -v $KUBECONFIG:/root/.kube/config quay.io/derailed/k9s

For default path it would be:

docker run --rm -it -v ~/.kube/config:/root/.kube/config quay.io/derailed/k9s

Building your own Docker image

You can build your own Docker image of k9s from the Dockerfile with the following:

docker build -t k9s-docker:v0.0.1 .

You can get the latest stable kubectl version and pass it to the docker build command with the --build-arg option. You can use the --build-arg option to pass any valid kubectl version (like v1.18.0 or v1.19.1).

KUBECTL_VERSION=$(make kubectl-stable-version 2>/dev/null)
docker build --build-arg KUBECTL_VERSION=${KUBECTL_VERSION} -t k9s-docker:0.1 .

Run your container:

docker run --rm -it -v ~/.kube/config:/root/.kube/config k9s-docker:0.1

PreFlight Checks

  • K9s uses 256 colors terminal mode. On `Nix system make sure TERM is set accordingly.

    export TERM=xterm-256color
    
  • In order to issue resource edit commands make sure your EDITOR and KUBE_EDITOR env vars are set.

    # Kubectl edit command will use this env var.
    export KUBE_EDITOR=my_fav_editor
    
  • K9s prefers recent kubernetes versions ie 1.28+


K8S Compatibility Matrix

k9sk8s client
>= v0.27.01.26.1
v0.26.7 - v0.26.61.25.3
v0.26.5 - v0.26.41.25.1
v0.26.3 - v0.26.11.24.3
v0.26.0 - v0.25.191.24.2
v0.25.18 - v0.25.31.22.3
v0.25.2 - v0.25.01.22.0
<= v0.241.21.3

The Command Line

# List current version
k9s version

# To get info about K9s runtime (logs, configs, etc..)
k9s info

# List all available CLI options
k9s help

# To run K9s in a given namespace
k9s -n mycoolns

# Start K9s in an existing KubeConfig context
k9s --context coolCtx

# Start K9s in readonly mode - with all cluster modification commands disabled
k9s --readonly

Logs And Debug Logs

Given the nature of the ui k9s does produce logs to a specific location. To view the logs and turn on debug mode, use the following commands:

# Find out where the logs are stored
k9s info
 ____  __.________
|    |/ _/   __   \______
|      < \____    /  ___/
|    |  \   /    /\___ \
|____|__ \ /____//____  >
        \/            \/

Version:           vX.Y.Z
Config:            /Users/fernand/.config/k9s/config.yaml
Logs:              /Users/fernand/.local/state/k9s/k9s.log
Dumps dir:         /Users/fernand/.local/state/k9s/screen-dumps
Benchmarks dir:    /Users/fernand/.local/state/k9s/benchmarks
Skins dir:         /Users/fernand/.local/share/k9s/skins
Contexts dir:      /Users/fernand/.local/share/k9s/clusters
Custom views file: /Users/fernand/.local/share/k9s/views.yaml
Plugins file:      /Users/fernand/.local/share/k9s/plugins.yaml
Hotkeys file:      /Users/fernand/.local/share/k9s/hotkeys.yaml
Alias file:        /Users/fernand/.local/share/k9s/aliases.yaml

View K9s logs

tail -f /Users/fernand/.local/data/k9s/k9s.log

Start K9s in debug mode

k9s -l debug

Customize logs destination

You can override the default log file destination either with the --logFile argument:

k9s --logFile /tmp/k9s.log
less /tmp/k9s.log

Or through the K9S_LOGS_DIR environment variable:

K9S_LOGS_DIR=/var/log k9s
less /var/log/k9s.log

Key Bindings

K9s uses aliases to navigate most K8s resources.

ActionCommandComment
Show active keyboard mnemonics and help?
Show all available resource aliasctrl-a
To bail out of K9s:quit, :q, ctrl-c
To go up/back to the previous viewescIf you have crumbs on, this will go to the previous one
View a Kubernetes resource using singular/plural or short-name:pod⏎accepts singular, plural, short-name or alias ie pod or pods
View a Kubernetes resource in a given namespace:pod ns-x⏎
View filtered pods (New v0.30.0!):pod /fred⏎View all pods filtered by fred
View labeled pods (New v0.30.0!):pod app=fred,env=dev⏎View all pods with labels matching app=fred and env=dev
View pods in a given context (New v0.30.0!):pod @ctx1⏎View all pods in context ctx1. Switches out your current k9s context!
Filter out a resource view given a filter/filter⏎Regex2 supported ie `fred
Inverse regex filter/! filter⏎Keep everything that doesn't match.
Filter resource view by labels/-l label-selector⏎
Fuzzy find a resource given a filter/-f filter⏎
Bails out of view/command/filter mode<esc>
Key mapping to describe, view, edit, view logs,...d,v, e, l,...
To view and switch to another Kubernetes context (Pod view):ctx⏎
To view and switch directly to another Kubernetes context (Last used view):ctx context-name⏎
To view and switch to another Kubernetes namespace:ns⏎
To view all saved resources:screendump or sd⏎
To delete a resource (TAB and ENTER to confirm)ctrl-d
To kill a resource (no confirmation dialog, equivalent to kubectl delete --now)ctrl-k
Launch pulses view:pulses or pu⏎
Launch XRay view:xray RESOURCE [NAMESPACE]⏎RESOURCE can be one of po, svc, dp, rs, sts, ds, NAMESPACE is optional
Launch Popeye view:popeye or pop⏎See popeye

K9s Configuration

K9s keeps its configurations as YAML files inside of a k9s directory and the location depends on your operating system. K9s leverages XDG to load its various configurations files. For information on the default locations for your OS please see this link. If you are still confused a quick k9s info will reveal where k9s is loading its configurations from. Alternatively, you can set K9S_CONFIG_DIR to tell K9s the directory location to pull its configurations from.

UnixmacOSWindows
~/.config/k9s~/Library/Application Support/k9s%LOCALAPPDATA%\k9s

NOTE: This is still in flux and will change while in pre-release stage!

You can now override the context portForward default address configuration by setting an env variable that can override all clusters portForward local address using K9S_DEFAULT_PF_ADDRESS=a.b.c.d

# $XDG_CONFIG_HOME/k9s/config.yaml
k9s:
  # Enable periodic refresh of resource browser windows. Default false
  liveViewAutoRefresh: false
  # The path to screen dump. Default:
项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

白日梦AI

白日梦AI提供专注于AI视频生成的多样化功能,包括文生视频、动态画面和形象生成等,帮助用户快速上手,创造专业级内容。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

讯飞绘镜

讯飞绘镜是一个支持从创意到完整视频创作的智能平台,用户可以快速生成视频素材并创作独特的音乐视频和故事。平台提供多样化的主题和精选作品,帮助用户探索创意灵感。

Project Cover

讯飞文书

讯飞文书依托讯飞星火大模型,为文书写作者提供从素材筹备到稿件撰写及审稿的全程支持。通过录音智记和以稿写稿等功能,满足事务性工作的高频需求,帮助撰稿人节省精力,提高效率,优化工作与生活。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

Trae

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号