···11+---
22+title: "Life pro tip: put your active kubernetes context in your prompt"
33+desc: "kube_ps1 is love, kube_ps1 is life"
44+date: 2025-04-05
55+hero:
66+ ai: "Photo by Xe Iaso, Canon EOS R6 Mark ii, 16mm wide angle lens"
77+ file: touch-grass
88+ prompt: "A color-graded photo of a forest in Gatineau Park, the wildlife looks green and lush"
99+---
1010+1111+Today I did an oopsie. I tried to upgrade a service in my homelab cluster (`alrest`) but accidentally upgraded it in the production cluster (`aeacus`). I was upgrading `ingress-nginx` to patch [the security vulnerabilities released a while ago](https://kubernetes.io/blog/2025/03/24/ingress-nginx-cve-2025-1974/). I should have done it sooner, but [things have been rather wild lately](https://arstechnica.com/ai/2025/03/devs-say-ai-crawlers-dominate-traffic-forcing-blocks-on-entire-countries/) and now [kernel.org runs some software I made](https://social.kernel.org/notice/Asir7LiPevX6XcEVJQ).
1212+1313+<Conv name="Cadey" mood="coffee">
1414+ <Picture
1515+ path="notes/2025/kube-ps1/domino-meme"
1616+ desc="A domino effect starting at 'Amazon takes out my git server' ending in 'software running on kernel.org'."
1717+ />
1818+</Conv>
1919+2020+Either way, I found out that [Oh my ZSH](https://ohmyz.sh/) (the ZSH prompt toolkit I use) has a plugin for [kube_ps1](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/kube-ps1/README.md). This lets you put your active Kubernetes context in your prompt so that you're less likely to apply the wrong manifest to the wrong cluster.
2121+2222+To install it, I changed the `plugins` list in my `~/.zshrc`:
2323+2424+```diff
2525+-plugins=(git)
2626++plugins=(git kube-ps1)
2727+```
2828+2929+And then added configuration at the end for kube_ps1:
3030+3131+```sh
3232+export KUBE_PS1_NS_ENABLE=false
3333+export KUBE_PS1_SUFFIX=") "
3434+3535+PROMPT='$(kube_ps1)'$PROMPT
3636+```
3737+3838+This makes my prompt look like this:
3939+4040+```text
4141+(⎈|alrest) ➜ site git:(main) ✗
4242+```
4343+4444+Showing that I'm using the Kubernetes cluster Alrest.
4545+4646+<ConvP>
4747+ <Conv name="Aoi" mood="wut">
4848+ Wouldn't it be better to modify your configuration such that you always have
4949+ to pass a `--context` flag or something?
5050+ </Conv>
5151+ <Conv name="Cadey" mood="coffee">
5252+ Yes, but some of the tools I use don't have that support universally. Until
5353+ I can ensure they all do, I'm willing to settle for tamper-evident instead
5454+ of tamper-resistant.
5555+ </Conv>
5656+</ConvP>
5757+5858+## Why upgrading ingress-nginx broke my HTTP ingress setup
5959+6060+Apparently when I set up the Kubernetes cluster for my website, the [Anubis docs](https://anubis.techaro.lol) and other things like my Headscale server, I did a very creative life decision. I started out with the "baremetal" self-hosted ingress-nginx install flow and then manually edited the `Service` to be a `LoadBalancer` service instead of a `NodePort` service.
6161+6262+I had forgotten about this. So when the upgrade hit the wrong cluster, Kubernetes happily made that `Service` into a `NodePort` service, destroying the cloud's load balancer that had been doing all of my HTTP ingress.
6363+6464+Thankfully, Kubernetes dutifully recorded logs of that entire process, which I have reproduced here for your amusement.
6565+6666+| Event type | Reason | Age | From | Message |
6767+| :--------- | :------------------- | :-- | :----------------- | :----------------------- |
6868+| Normal | Type changed | 13m | service-controller | LoadBalancer -> NodePort |
6969+| Normal | DeletingLoadBalancer | 13m | service-controller | Deleting load balancer |
7070+| Normal | DeletedLoadBalancer | 13m | service-controller | Deleted load balancer |
7171+7272+<ConvP>
7373+ <Conv name="Cadey" mood="facepalm">
7474+ OOPS!
7575+ </Conv>
7676+ <Conv name="Numa" mood="smug">
7777+ Pro tip if you're ever having trouble waking up, take down production.
7878+ That'll wake you up in [a
7979+ jiffy](https://en.wikipedia.org/wiki/Jiffy_(time))!
8080+ </Conv>
8181+</ConvP>
8282+8383+Thankfully, getting this all back up was easy. All I needed to do was change the `Service` type back to LoadBalancer, wait a second for the cloud to converge, and then change the default DNS target from the old IP address to the new one. [external-dns](https://kubernetes-sigs.github.io/external-dns/latest/) updated everything once I changed the IP it was told to use, and now everything should be back to normal.
8484+8585+Well, at least I know how to do that now!