Skip to content

Instantly share code, notes, and snippets.

@brandonros
Created April 1, 2022 01:44
Show Gist options
  • Save brandonros/68a2552cd5fa8fe763ab0ad0455041ca to your computer and use it in GitHub Desktop.
Save brandonros/68a2552cd5fa8fe763ab0ad0455041ca to your computer and use it in GitHub Desktop.

k8s Adventure

Context

  • Running Mac OS X on Apple M1 (arm64)

kubectl

brew install kubernetes-cli

QEMU

brew install qemu

Flatcar Linux

mkdir flatcar-amd64
cd flatcar-amd64
# make hard disk
qemu-img create -f qcow2 flatcar.qcow2 32G
# get latest flatcar bootable images
wget https://stable.release.flatcar-linux.net/amd64-usr/3033.2.4/flatcar_production_pxe.vmlinuz
wget https://stable.release.flatcar-linux.net/amd64-usr/3033.2.4/flatcar_production_pxe_image.cpio.gz
# start qemu system
qemu-system-x86_64 \
  -M q35 \
  -m 4G \
  -smp 4 \
  -cpu qemu64 \
  -accel tcg \
  -kernel flatcar_production_pxe.vmlinuz \
  -initrd flatcar_production_pxe_image.cpio.gz \
  -append "console=ttyS0 flatcar.first_boot=1 sshkey=\"ssh-rsa REDACTED\"" \
  -netdev user,id=mynet0,hostfwd=tcp::2222-:22,hostfwd=tcp::6443-:6443 \
  -device e1000,netdev=mynet0 \
  -drive file=flatcar.qcow2,format=qcow2 \
  -nographic
# in another terminal from local machine
chmod 400 ~/.ssh/id_rsa
ssh -i ~/.ssh/id_rsa -p 2222 core@localhost
# in ssh session
sudo flatcar-install -d /dev/sda -C stable
sudo poweroff
# boot again
qemu-system-x86_64 \
  -M q35 \
  -m 4G \
  -smp 4 \
  -cpu qemu64 \
  -accel tcg \
  -kernel flatcar_production_pxe.vmlinuz \
  -initrd flatcar_production_pxe_image.cpio.gz \
  -append "console=ttyS0 root=LABEL=ROOT sshkey=\"ssh-rsa REDACTED\"" \
  -netdev user,id=mynet0,hostfwd=tcp::2222-:22,hostfwd=tcp::6443-:6443 \
  -device e1000,netdev=mynet0 \
  -drive file=flatcar.qcow2,format=qcow2 \
  -nographic

k3sup

wget https://github.com/alexellis/k3sup/releases/download/0.11.3/k3sup-darwin
chmod +x k3sup-darwin
./k3sup-darwin install --ip 127.0.0.1 --ssh-port 2222 --user core
mkdir ~/.kube
mv kubeconfig ~/.kube/config
kubectl config set-context default

postgresql-operator

kubectl create namespace pgo
kubectl apply -f https://raw.githubusercontent.com/CrunchyData/postgres-operator/v4.7.5/installers/kubectl/postgres-operator.yml
kubectl wait --for=condition=complete --timeout=300s -n pgo job/pgo-deploy
kubectl get all --all-namespaces
kubectl get events --all-namespaces --sort-by='.metadata.creationTimestamp'
curl https://raw.githubusercontent.com/CrunchyData/postgres-operator/v4.7.5/installers/kubectl/client-setup.sh > client-setup.sh
chmod +x client-setup.sh
./client-setup.sh
export PGOUSER="${HOME}/.pgo/pgo/pgouser"
export PGO_CA_CERT="${HOME}/.pgo/pgo/client.crt"
export PGO_CLIENT_CERT="${HOME}/.pgo/pgo/client.crt"
export PGO_CLIENT_KEY="${HOME}/.pgo/pgo/client.key"
export PGO_APISERVER_URL='https://127.0.0.1:8443'
export PGO_NAMESPACE=pgo
kubectl -n pgo port-forward svc/postgres-operator 8443:8443
pgo version
pgo create cluster -n pgo hippo
pgo test -n pgo hippo
pgo show user -n pgo hippo
kubectl -n pgo port-forward svc/hippo 5432:5432
PGPASSWORD=datalake psql -h localhost -p 5432 -U testuser hippo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment