Skip to content

Commit

Permalink
Move ~/.kube to XDG-compliant locations
Browse files Browse the repository at this point in the history
This commit sets two new environment variables which split and point k8s
config/cache to XDG-compliant locations.

It also adds couple of fixes to relevant make targets:
 - Fixes sed command for the `GRUB_CMDLINE_LINUX_DEFAULT`
 - Adds a default driver config (kvm2) for `minikube`
 - Fixes `kubectl version` printing
 - Increases timeout to wait for a deployment in `make test-k8s`
  • Loading branch information
matyama committed Mar 14, 2024
1 parent 0381314 commit b3c819b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .config/zsh/.zshenv
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ export LIBVIRT_DEFAULT_URI=qemu:///system
# Docker
export DOCKER_CONFIG=${XDG_CONFIG_HOME}/docker

# K9s
# - https://bit.ly/3VcWhCw
# - https://groups.google.com/g/kubernetes-announce/c/LQki8n9ZxCo
export KUBECONFIG=${XDG_CONFIG_HOME}/kube
export KUBECACHEDIR=${XDG_CACHE_HOME}/kube

# Minikube
# - https://wiki.archlinux.org/title/XDG_Base_Directory
# - https://github.com/kubernetes/minikube/issues/4109
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ kvm: core-utils
@virt-host-validate || echo ">>> Consider fixing problematic entries"
@echo ">>> Configuring GRUB_CMDLINE_LINUX_DEFAULT to '$(GRUB_CMDLINE_LINUX_DEFAULT)'"
@sudo sed -i \
's|^GRUB_CMDLINE_LINUX_DEFAULT=.*\\$$|GRUB_CMDLINE_LINUX_DEFAULT="$(GRUB_CMDLINE_LINUX_DEFAULT)"|' \
's|^GRUB_CMDLINE_LINUX_DEFAULT=.*$$|GRUB_CMDLINE_LINUX_DEFAULT=$(GRUB_CMDLINE_LINUX_DEFAULT)|' \
/etc/default/grub
sudo update-grub
@echo ">>> Reboot for the GRUB changes to take effect!"
Expand Down Expand Up @@ -466,6 +466,7 @@ endif
# - [Helm docs](https://helm.sh/docs/)
# - [k8s krew](https://krew.sigs.k8s.io/)
# - [krew install warning](https://github.com/kubernetes-sigs/krew/issues/576)
# - TODO: https://minikube.sigs.k8s.io/docs/tutorials/nvidia
.PHONY: k8s
k8s: KVM2_DRIVER_URL := https://storage.googleapis.com/minikube/releases/latest
k8s: KVM2_DRIVER := docker-machine-driver-kvm2
Expand All @@ -486,6 +487,8 @@ else
@echo ">>> Starting minikube"
minikube start --cpus 2 --memory 2048 --vm-driver kvm2
minikube status
@echo ">>> Configure kvm2 as the default driver for minikube"
@minikube config set driver kvm2
@echo ">>> Installing and initializing helm: https://helm.sh/docs/"
binenv install helm
@echo ">>> Installing helm-operator: https://github.com/fluxcd/helm-operator"
Expand All @@ -496,7 +499,7 @@ else
@echo ">>> Shutting down $$(minikube version --short)"
minikube stop
minikube status || true
@echo ">>> Verified kubectl $$(kubectl version --client --short)"
@echo ">>> Verified kubectl $$(kubectl version --client -o json | jq -r '.clientVersion.gitVersion')"
endif

# FIXME: Cleanup resources if service request fails
Expand All @@ -506,16 +509,17 @@ endif
.PHONY: test-k8s
test-k8s: net-tools
@echo ">>> Testing minikube installation"
minikube start --cpus 2 --memory 2048 --vm-driver kvm2
minikube start --cpus 2 --memory 2048
minikube status
minikube config get driver
kubectl cluster-info
kubectl get nodes
kubectl get pods --all-namespaces
@echo ">>> Running test application in minikube"
kubectl create deployment hello-minikube \
--image=k8s.gcr.io/echoserver:1.10 \
--port=8080
kubectl wait deploy/hello-minikube --for condition=available
kubectl wait deploy/hello-minikube --timeout=90s --for condition=available
@echo ">>> Checking that the VM is running"
@{ \
VM_STATE=$$(virsh list --all | grep " minikube " | awk '{ print $$3}');\
Expand Down Expand Up @@ -546,7 +550,7 @@ test-k8s: net-tools
@echo ">>> Shutting down $$(minikube version --short)"
minikube stop
minikube status || true
@echo ">>> Verified kubectl $$(kubectl version --client --short)"
@echo ">>> Verified kubectl $$(kubectl version --client -o json | jq -r '.clientVersion.gitVersion')"

# Installation resources:
# - https://github.com/devops-works/binenv#linux-bashzsh
Expand Down

0 comments on commit b3c819b

Please sign in to comment.