jonmosco / kube-ps1

Kubernetes prompt info for bash and zsh
Apache License 2.0
3.52k stars 351 forks source link

Need some help setting up #157

Closed swright-eti closed 2 years ago

swright-eti commented 2 years ago

I am trying to set this up in bash for Ubuntu and I am not sure what I am doing wrong.

I have this in my .bashrc file:

source ~/load-k8s-configs.sh
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$HOME/.kube/plugins:$PATH"

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

I source the .bashrc file and my existing color set goes away, but I dont see any context information added to my prompt.

I have kubectl. CTX, and NS installed.

[swright@swright-dev-09 ~ ]$ k ctx
clstr2.dev
cluster01.dev
k3s1.dev
n01.dev
triad60.demo
triad60.dev
triadgfm.dev
web.dev

Can you please let me know where I am going wrong? Thanks.

cs8898 commented 2 years ago

Same here...

It Seems as if there was a call missing to _kube_ps1_get_context_ns

swright-eti commented 2 years ago

You are right. I added _kube_ps1_get_context_ns to the kube_ps1() function and it started working.

# Build our prompt
kube_ps1() {

  _kube_ps1_get_context_ns

  [[ "${KUBE_PS1_ENABLED}" == "off" ]] && return
  [[ -z "${KUBE_PS1_CONTEXT}" ]] && [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]] && return

...
cs8898 commented 2 years ago

Oh seems i forgot to add an other comment.

For me it got also working after adding the .kube/config file.

I was using k3s but somewhere in the Update Cache Methode there is a Check for the KubeConfig File... That file was missing because k3s uses it's own from /etc ...

Could be a bit more performant

jonmosco commented 2 years ago

The application uses the kubectl configuration conventions, so it will expect either the environment variable KUBECONFIG to be set, or the existence of a .kube/config file. Accounting for the locations of various config files would be beyond the scope of the application, but this could be solved by setting your KUBECONFIG to the location of the file regardless which distribution of Kubernetes you have running.

jonmosco commented 2 years ago

This issue seems to be resolved.