kube-ps1

Kubernetes prompt info for bash and zsh
授权协议 Apache-2.0 License
开发语言 SHELL
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 呼延沈义
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

kube-ps1: Kubernetes prompt for bash and zsh

A script that lets you add the current Kubernetes context and namespaceconfigured on kubectl to your Bash/Zsh prompt strings (i.e. the $PS1).

Inspired by several tools used to simplify usage of kubectl.

Installing

MacOS

Homebrew package manager:

$ brew update
$ brew install kube-ps1

From Source

  1. Clone this repository
  2. Source the kube-ps1.sh in your ~/.zshrc or your ~/.bashrc

Arch Linux

AUR Package available at https://aur.archlinux.org/packages/kube-ps1/.

Zsh

source /path/to/kube-ps1.sh
PROMPT='$(kube_ps1)'$PROMPT

Bash

source /path/to/kube-ps1.sh
PS1='[\u@\h \W $(kube_ps1)]\$ '

Zsh Plugin Managers

Using zplugin

Update .zshrc with:

zplugin light jonmosco/kube-ps1
PROMPT='$(kube_ps1)'$PROMPT

Requirements

The default prompt assumes you have the kubectl command line utility installed.Official installation instructions and binaries are available:

Install and Set up kubectl

If using this with OpenShift, the oc tool needs installed. It can be obtainedfrom brew ports:

brew install openshift-cli

or the source can be downloaded:

OC Client Tools

Set the binary to oc with the following environment variable:

KUBE_PS1_BINARY=oc

If neither binary is available, the prompt will print the following:

(<symbol>|BINARY-N/A:N/A)

Helper utilities

There are several great tools that make using kubectl very enjoyable:

Tmux port

I have begun porting kube-ps1 to tmux as a status line plugin. If you prefertmux, and like the functionality provided by kube-ps1, checkout thekube-tmux project

Prompt Structure

The default prompt layout is:

(<symbol>|<context>:<namespace>)

If the current-context is not set, kube-ps1 will return the following:

(<symbol>|N/A:N/A)

Enabling/Disabling

If you want to stop showing Kubernetes status on your prompt string temporarilyrun kubeoff. To disable the prompt for all shell sessions, run kubeoff -g.You can enable it again in the current shell by running kubeon, and globallywith kubeon -g.

kubeon     : turn on kube-ps1 status for this shell.  Takes precedence over
             global setting for current session
kubeon -g  : turn on kube-ps1 status globally
kubeoff    : turn off kube-ps1 status for this shell. Takes precedence over
             global setting for current session
kubeoff -g : turn off kube-ps1 status globally

Customization

The default settings can be overridden in ~/.bashrc or ~/.zshrc by settingthe following environment variables:

Variable Default Meaning
KUBE_PS1_BINARY kubectl Default Kubernetes binary
KUBE_PS1_NS_ENABLE true Display the namespace. If set to false, this will also disable KUBE_PS1_DIVIDER
KUBE_PS1_PREFIX ( Prompt opening character
KUBE_PS1_SYMBOL_ENABLE true Display the prompt Symbol. If set to false, this will also disable KUBE_PS1_SEPARATOR
KUBE_PS1_SYMBOL_PADDING true Adds a space (padding) after the symbol to prevent clobbering prompt characters
KUBE_PS1_SYMBOL_DEFAULT Default prompt symbol. Unicode \u2388
KUBE_PS1_SYMBOL_USE_IMG false ☸️ , Unicode \u2638 as the prompt symbol
KUBE_PS1_SEPARATOR | Separator between symbol and context name
KUBE_PS1_DIVIDER : Separator between context and namespace
KUBE_PS1_SUFFIX ) Prompt closing character
KUBE_PS1_CLUSTER_FUNCTION No default, must be user supplied Function to customize how cluster is displayed
KUBE_PS1_NAMESPACE_FUNCTION No default, must be user supplied Function to customize how namespace is displayed

For terminals that do not support UTF-8, the symbol will be replaced with thestring k8s.

To disable a feature, set it to an empty string:

KUBE_PS1_SEPARATOR=''

Colors

The default colors are set with the following environment variables:

Variable Default Meaning
KUBE_PS1_PREFIX_COLOR null Set default color of the prompt prefix
KUBE_PS1_SYMBOL_COLOR blue Set default color of the Kubernetes symbol
KUBE_PS1_CTX_COLOR red Set default color of the context
KUBE_PS1_SUFFIX_COLOR null Set default color of the prompt suffix
KUBE_PS1_NS_COLOR cyan Set default color of the namespace
KUBE_PS1_BG_COLOR null Set default color of the prompt background

Blue was used for the default symbol to match the Kubernetes color as closelyas possible. Red was chosen as the context name to stand out, and cyan for thenamespace.

Set the variable to an empty string if you do not want color for eachprompt section:

KUBE_PS1_CTX_COLOR=''

Names are usable for the following colors:

black, red, green, yellow, blue, magenta, cyan

256 colors are available by specifying the numerical value as the variableargument.

Customize display of cluster name and namespace

You can change how the cluster name and namespace are displayed using theKUBE_PS1_CLUSTER_FUNCTION and KUBE_PS1_NAMESPACE_FUNCTION variablesrespectively.

For the following examples let's assume the following:

cluster name: sandbox.k8s.example.comnamespace: alpha

If you're using domain style cluster names, your prompt will get quite longvery quickly. Let's say you only want to display the first portion of thecluster name (sandbox), you could do that by adding the following:

function get_cluster_short() {
  echo "$1" | cut -d . -f1
}

KUBE_PS1_CLUSTER_FUNCTION=get_cluster_short

The same pattern can be followed to customize the display of the namespace.Let's say you would prefer the namespace to be displayed in all uppercase(ALPHA), here's one way you could do that:

function get_namespace_upper() {
    echo "$1" | tr '[:lower:]' '[:upper:]'
}

export KUBE_PS1_NAMESPACE_FUNCTION=get_namespace_upper

In both cases, the variable is set to the name of the function, and you must have defined the function in your shell configuration before kube_ps1 is called. The function must accept a single parameter and echo out the final value.

Bug Reports and shell configuration

Due to the vast ways of customizing the shell, please try the prompt with aminimal configuration before submitting a bug report.

This can be done as follows for each shell before loading kube-ps1:

Bash:

bash --norc

Zsh:

zsh -f
or
zsh --no-rcs

Contributors

  •  下载配置kube-ps1 git clone https://github.com/jonmosco/kube-ps1.git source /path/to/kube-ps1.sh PS1='[\u@\h \W $(kube_ps1)]\$ ' 开启 kubeon  关闭 kubeoff  

 相关资料
  • Kube 足够的简单,足够小,具有很强的自适应能力,是个响应式的 CSS 框架。它拥有最新最炫的网格和漂亮的字体排版,没有任何样式绑定,给用户以绝对的自由。 支持的浏览器包括: Latest Chrome Latest Firefox Latest Safari Latest Opera IE 8+ 手机浏览器

  • Kube-OVN 将基于 OVN/OVS 的网络虚拟化方案带入 Kubernetes,提供了针对企业应用场景的高级容器网络编排功能。 主要功能: 基于Namespace的子网划分,以及网络控制 容器固定 IP IPv6支持 细粒度网络策略 动态 QoS 分布式和集中式网关 内嵌负载均衡器 支持集群内外网络直通 控制平面的灾备及高可用 丰富的监控和链路追踪工具 未来计划: 基于 XDP/DPDK/O

  • kube-eventer 是一个事件发射器,它将 Kubernetes 事件发送到接收器(例如,DingTalk、SLS、Kafka 等)。 监控是保障系统稳定性的重要组成部分,在 Kubernetes 开源生态中,资源类的监控工具与组件百花齐放,但是,只有资源类的监控是远远不够的,因为资源监控存在如下两个主要的缺欠: 监控的实时性与准确性不足 监控的场景覆盖范围不足 Kubernetes 的核心

  • kube-backup Quick 'n dirty kubernetes state backup script, designed to be ran as kubernetes Job. Think of it like RANCID for kubernetes. Props to @gianrubio for coming up with the idea. Setup Use the

  • �� Provision a Kubernetes / CoreOS Cluster on Linode Automatically provision a scalable CoreOS/Kubernetes cluster on Linode with zero configuration. The cluster will comprise of a single Kubernetes ma

  • kube-fzf Shell commands using kubectl and fzf for command-line fuzzy searching of Kubernetes Pods. It helps to interactively: search for a Pod tail a container of a Pod exec in to a container of a Pod