From ce9593f402c43665d5138545fe711ca048059082 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 10 Apr 2024 17:37:19 +0000 Subject: [PATCH 1/3] Draft k8s Tools Post --- 2024-04-10_Kubernetes-Tools.md | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 2024-04-10_Kubernetes-Tools.md diff --git a/2024-04-10_Kubernetes-Tools.md b/2024-04-10_Kubernetes-Tools.md new file mode 100644 index 0000000..d6782fa --- /dev/null +++ b/2024-04-10_Kubernetes-Tools.md @@ -0,0 +1,48 @@ +--- +date: 2024-04-10 +title: Setting Up Kubernetes Tools +tags: + - homelab + - linux + - bash + - development + - kubernetes +--- + +At work, I somewhat recently transitioned from using the Kubernetes Dashboard to using [k9s](https://k9scli.io/) +as DigitalOcean deprecated their hosted Dashboard on their DOKS instances. Today, I found that I needed to modify +a `Secret` and that `k9s`` has no native tools to do this. I also found that I didn't have bash completion set up +since upgrading to a new dev machine, so I took the opportunity to set things up better by using my +[Shell Customizations](https://blog.mcknight.tech/2024/03/27/Shell-Customizations/) so I don't need to configure +bash completion every time I set up a new computer. + +## Shell Customizations + +Existing +```shell +export EDITOR=nano +alias k9=k9s +``` + +New +```shell +which kubectl 1> /dev/null && source <(kubectl completion bash) +which helm 1> /dev/null && source <(helm completion bash) +[ -d "${KREW_ROOT:-$HOME/.krew}/bin" ] && export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" +``` + +## k9s and helm Installation +- Get from https://github.com/derailed/k9s/releases +- Check versions +- `k9s info` + +## krew and the kubectl-modify-secret plugin +https://krew.sigs.k8s.io/docs/user-guide/setup/install/ +https://github.com/rajatjindal/kubectl-modify-secret?tab=readme-ov-file + +## k9s Plugin Configuration +https://k9scli.io/topics/plugins/ + + +## Future Plans +- Automate or script package installation -- GitLab From 84d6ea18c45a11030b76e5658c1399d2b9a03470 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Sat, 20 Apr 2024 05:22:25 +0000 Subject: [PATCH 2/3] Finish post --- 2024-04-10_Kubernetes-Tools.md | 72 ++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/2024-04-10_Kubernetes-Tools.md b/2024-04-10_Kubernetes-Tools.md index d6782fa..2ce9351 100644 --- a/2024-04-10_Kubernetes-Tools.md +++ b/2024-04-10_Kubernetes-Tools.md @@ -11,38 +11,86 @@ tags: At work, I somewhat recently transitioned from using the Kubernetes Dashboard to using [k9s](https://k9scli.io/) as DigitalOcean deprecated their hosted Dashboard on their DOKS instances. Today, I found that I needed to modify -a `Secret` and that `k9s`` has no native tools to do this. I also found that I didn't have bash completion set up +a `Secret` and that `k9s` has no native tools to do this. I also found that I didn't have bash completion set up since upgrading to a new dev machine, so I took the opportunity to set things up better by using my -[Shell Customizations](https://blog.mcknight.tech/2024/03/27/Shell-Customizations/) so I don't need to configure +[Shell Customizations](https://blog.mcknight.tech/2024/03/27/Shell-Customizations/). Now I won't need to configure bash completion every time I set up a new computer. ## Shell Customizations +Rather than adding shell completion to the system config as is often suggested in documentation, I chose to keep +everything in my `.bashrc` so its portable between environments. -Existing +I already had some k8s-related content: ```shell export EDITOR=nano alias k9=k9s ``` -New +I added: ```shell which kubectl 1> /dev/null && source <(kubectl completion bash) which helm 1> /dev/null && source <(helm completion bash) [ -d "${KREW_ROOT:-$HOME/.krew}/bin" ] && export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" ``` -## k9s and helm Installation -- Get from https://github.com/derailed/k9s/releases -- Check versions -- `k9s info` +This adds `kubectl` and `helm` completion iff ([not a typo](https://en.wikipedia.org/wiki/If_and_only_if)) +those commands are available. It also appends the [`krew`](https://krew.sigs.k8s.io/) +binary path to `$PATH` if its defined. More on `krew` later. + + +## `k9s` and `helm` Installation +`k9s` has a few installation methods, but I chose to grab the [latest release from GitHub](https://github.com/derailed/k9s/releases) +since I don't have `snap` installed. I ended up updating `k9s` because the configuration file specs have +changed some, and updating means the documentation examples should all work. The currently installed +version can be found with `k9s info`. + +`helm` installation is [documented on their website](https://helm.sh/docs/intro/install/). I prefer to install +via `apt` to simplify updates since (as noted earlier) I don't usually have `snap` installed. + ## krew and the kubectl-modify-secret plugin -https://krew.sigs.k8s.io/docs/user-guide/setup/install/ -https://github.com/rajatjindal/kubectl-modify-secret?tab=readme-ov-file +`krew` is a plugin for `kubectl` that makes it easy to install more plugins. They have an +[installation guide](https://krew.sigs.k8s.io/docs/user-guide/setup/install/) that is very +straight-forward. Note that the change in my `.bashrc` earlier adds the same `KREW_ROOT` +to my `PATH` as they specify in the installation guide. + +With `krew` installed, I'm finally back to what I started this all for; installing a plugin to +modify a secret in `k9s`. The [kubectl-modify-secret plugin](https://github.com/rajatjindal/kubectl-modify-secret?tab=readme-ov-file) +can be installed via +``` +kubectl krew update +kubectl krew install modify-secret +``` + +Now, `kubectl modify-secret ` should open an editor where a secret can be modified in plaintext. ## k9s Plugin Configuration -https://k9scli.io/topics/plugins/ +With the plugin installed, I next configured `k9s` so I can use the plugin to edit secrets the same way I edit configurations and +other specs. The `k9s` plugin configuration is [documented here](https://k9scli.io/topics/plugins/). +My config at `~/.config/k9s/plugins.yaml` looks like: + +```yaml +plugins: + edit-secret: + shortCut: Ctrl-X + confirm: false + description: "Edit Secret" + scopes: + - secrets + command: kubectl + background: false + args: + - modify-secret + - --namespace + - $NAMESPACE + - --context + - $CONTEXT + - $NAME +``` ## Future Plans -- Automate or script package installation +I'm satisfied now with my tools and workflow for interacting with Kubernetes. Ideally, I would like to come up with a method +for backing up and synchronizing configuration between my devices; for now I manually copy my `.bashrc`, `.ssh`, and `.config` +file/directories around. A better solution I think could be a git repository + update script, Nextcloud sync, or something else. +I still have some research to do, but for now the changes are infrequent enough I'm satisfied with manual processes. -- GitLab From 856300d7566f9e0a42c0d88ab3386357c6eb5e33 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Sun, 21 Apr 2024 19:50:49 +0000 Subject: [PATCH 3/3] Finalize post and update date --- ...Tools.md => 2024-04-21_Kubernetes-Tools.md | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) rename 2024-04-10_Kubernetes-Tools.md => 2024-04-21_Kubernetes-Tools.md (72%) diff --git a/2024-04-10_Kubernetes-Tools.md b/2024-04-21_Kubernetes-Tools.md similarity index 72% rename from 2024-04-10_Kubernetes-Tools.md rename to 2024-04-21_Kubernetes-Tools.md index 2ce9351..3091ace 100644 --- a/2024-04-10_Kubernetes-Tools.md +++ b/2024-04-21_Kubernetes-Tools.md @@ -1,5 +1,5 @@ --- -date: 2024-04-10 +date: 2024-04-21 title: Setting Up Kubernetes Tools tags: - homelab @@ -10,11 +10,11 @@ tags: --- At work, I somewhat recently transitioned from using the Kubernetes Dashboard to using [k9s](https://k9scli.io/) -as DigitalOcean deprecated their hosted Dashboard on their DOKS instances. Today, I found that I needed to modify -a `Secret` and that `k9s` has no native tools to do this. I also found that I didn't have bash completion set up -since upgrading to a new dev machine, so I took the opportunity to set things up better by using my +as DigitalOcean deprecated their hosted Dashboard for DOKS. Today, I found that I needed to modify +a `Secret` and that `k9s` and `kubectl` have no native tools to do this. I also found that I didn't have bash +completion set up since upgrading to a new dev machine, so I took the opportunity to set things up better by using my [Shell Customizations](https://blog.mcknight.tech/2024/03/27/Shell-Customizations/). Now I won't need to configure -bash completion every time I set up a new computer. +bash completion for helm/kubectl every time I set up a new computer. ## Shell Customizations Rather than adding shell completion to the system config as is often suggested in documentation, I chose to keep @@ -35,14 +35,14 @@ which helm 1> /dev/null && source <(helm completion bash) This adds `kubectl` and `helm` completion iff ([not a typo](https://en.wikipedia.org/wiki/If_and_only_if)) those commands are available. It also appends the [`krew`](https://krew.sigs.k8s.io/) -binary path to `$PATH` if its defined. More on `krew` later. +binary path to `$PATH` if its defined (more on `krew` later). ## `k9s` and `helm` Installation `k9s` has a few installation methods, but I chose to grab the [latest release from GitHub](https://github.com/derailed/k9s/releases) -since I don't have `snap` installed. I ended up updating `k9s` because the configuration file specs have -changed some, and updating means the documentation examples should all work. The currently installed -version can be found with `k9s info`. +since I don't have `snap` installed and usually run Linux Mint. I ended up updating `k9s` because the configuration file specs have +changed some since I originally got k9s, and updating means the example configurations in docs and other resources should all work. +The currently installed version can be determined with `k9s info`. `helm` installation is [documented on their website](https://helm.sh/docs/intro/install/). I prefer to install via `apt` to simplify updates since (as noted earlier) I don't usually have `snap` installed. @@ -54,10 +54,10 @@ via `apt` to simplify updates since (as noted earlier) I don't usually have `sna straight-forward. Note that the change in my `.bashrc` earlier adds the same `KREW_ROOT` to my `PATH` as they specify in the installation guide. -With `krew` installed, I'm finally back to what I started this all for; installing a plugin to +With `krew` installed, I'm finally back to what I started this all for: installing a plugin to modify a secret in `k9s`. The [kubectl-modify-secret plugin](https://github.com/rajatjindal/kubectl-modify-secret?tab=readme-ov-file) -can be installed via -``` +can be installed via: +```shell kubectl krew update kubectl krew install modify-secret ``` @@ -88,9 +88,11 @@ plugins: - $NAME ``` +This adds a `ctrl`+`x` shortcut to edit a `Secret`, similar to how `e` would edit a `ConfigMap`; `ctrl`+`e` is already used to +show/hide the information at the top of `k9s`, otherwise I'd have used that. ## Future Plans I'm satisfied now with my tools and workflow for interacting with Kubernetes. Ideally, I would like to come up with a method -for backing up and synchronizing configuration between my devices; for now I manually copy my `.bashrc`, `.ssh`, and `.config` +for synchronizing configuration between my devices automatically; for now, I manually copy my `.bashrc`, `.ssh`, and `.config` file/directories around. A better solution I think could be a git repository + update script, Nextcloud sync, or something else. I still have some research to do, but for now the changes are infrequent enough I'm satisfied with manual processes. -- GitLab