I’m using k3s a lot on my home network. Although I use k9s, i like to script up the deployment of all of my apps. I also keep all of my .yaml files in a self hosted git repository on my local network. I keep those .yaml files in a hierarchy of folders, and i prefix them with numbers to denote the order in which to deploy them.
So, with that in mind, i’d like to explain the handful of commands that i’ve been working on.
The first command is ka (for “k3s apply”). It’s job is to traverse that folder structure looking for .yaml files, and executing kubectl apply -f on those files. It can also look for urls in .url files, and recently i’ve added the ability to turn a folder of files into a ConfigMap.
In contrast to ka, there’s also kd which reverses the order in which it traverses the folder hierarchy, and executes kubectl delete -f on those files.
Those two commands both also honour a -r switch to recurse the hierarchy. With them I can tear down or build up my whole collection of applications. Until recently, my approach was to create my own container images, push them into my self-hosted repository, and then submit a .yaml file that used that image. On @Entropic 's advice i’ve been shifting to ConfigMaps and deployments that use generic images, which has been going brilliantly.
There have also been a few recent additions to those two main commands. ks is my version of ps (or docker ps) in that it lists deployments and pods, along with their states. kl is “k3s log” which honours the -f switch for following the logs of a container. Finally ke runs kubectl exec -ti against a container, which is handy to spawn a bash shell in a running container.
Of course, all of these results can be accomplished with either kubectl or k9s, but while i’ve been transitioning to ConfigMaps, it’s been handy for me to be able to kd -r, ka -r and kl sys backup for example. In that example i have a pod called backup in my sys namespace.
I’m pretty happy with these little scrips for now, but i wouldn’t be surprised if something more comprehensive and mature already exists. Please school me if i’ve reinvented the wheel.