kubernetes

Tips

Comparing and editing objects with vim -d

Comparing:

vim -d \
  <(kubectl get pods thingB -o yaml) \
  <(kubectl get pods thingA -o yaml)

Editing, with diff (for when you need to copy configuration from object to another):

EDITOR="vim -c 'read ! kubectl get -o yaml pods thingB' -d buff" \
  kubectl edit pods thingA

I bet there is a nicer way to do this, but my vim magic isn't quite there yet.

Tools

KinD

Playground for testing out clusters.

Kustomize

Little templating. Couple nice features but is completely superseded by helm.

Helm

Go templating engine with k8s integration. De-facto deployment tool.

Backends

k8s

The thing.

k3s

Simpler and more light-weight solution, contained in a single binary. Looks preferable for personal workloads.

Notes

K8s sets up some elaborate system for inter-container communication. In some cases, e.g. multi-cloud deployment, it won't work out the box - if that happens to you be ready to set up your own network, e.g. wireguard.

Examples

Commands

To get all images for all deployments in a namespace you can do something like this:

kubectl -n namespace get deployments.apps -o json \
 | jq -r '.items.[] | .spec.template.spec.containers.[] | .image'

For helm templates it's slightly different:

helm template -n namespace chart ./chart -f ./values.yml \
 | yq -r 'select(.kind == "Deployment") | .spec.template.spec.containers.[] | .image'

Which is pretty neat.