Skip to content

Instantly share code, notes, and snippets.

@pschichtel
Created August 14, 2024 17:41
Show Gist options
  • Save pschichtel/c1f45409a797d71eeb588e434947721b to your computer and use it in GitHub Desktop.
Save pschichtel/c1f45409a797d71eeb588e434947721b to your computer and use it in GitHub Desktop.
This is a script that creates a single-node k0s cluster, deploys the minio operator and a single tenant with a single pool with a single disk. It then displays a couple of commands that show how to interact with the setup. Depending on your internet connection the setup might take a couple of minutes to become ready. Most, but not all data will …
#!/usr/bin/env bash
# Required binaries:
# * k0s
# * kubectl
# * helm
# * cut
# * grep
# * ip
# * hostname
# * mktemp
# * cat
# * hostname
# * sudo (the user must also be a sudoer!)
set -euo pipefail
datadir="$(mktemp -d)"
config="$datadir/k0s.yaml"
log="$datadir/k0s.log"
kubeconfig="$datadir/kubeconfig"
minio_namespace="default"
minio_operator_values="$datadir/minio-operator.yaml"
minio_tenant_values="$datadir/minio-tenant.yaml"
minio_tenant_volume_config="$datadir/minio-volume.yaml"
minio_tenant_volume="$datadir/minio-data"
minio_chart_version='6.0.2'
minio_image_old="quay.io/minio/minio:RELEASE.2024-07-16T23-46-41Z"
minio_image_new="quay.io/minio/minio:RELEASE.2024-07-26T20-48-21Z"
# if this fails to properly detect the LAN IP, just simply replace it with your IP manually
ip="$(ip route get 1.1.1.1 | grep 1.1.1.1 | cut -d' ' -f 7)"
hostname="$(hostname)"
cat <<EOL > "$config"
apiVersion: k0s.k0sproject.io/v1beta1
kind: ClusterConfig
metadata:
name: minio-reproducer
spec:
api:
address: $ip
k0sApiPort: 9443
port: 6443
sans:
- 127.0.0.1
- $ip
extensions:
storage: {}
installConfig:
network:
calico: null
dualStack: {}
kubeProxy:
mode: iptables
kuberouter:
autoMTU: true
mtu: 0
# removing these will break networking
peerRouterASNs: ""
peerRouterIPs: ""
podCIDR: 10.244.0.0/16
provider: kuberouter
serviceCIDR: 10.96.0.0/12
storage:
etcd:
externalCluster: null
peerAddress: $ip
type: etcd
EOL
cat <<EOL > "$minio_operator_values"
operator:
replicaCount: 1
EOL
minio_tenant_name="repro"
minio_pool_name="first"
minio_pvc_name="data0-${minio_tenant_name}-${minio_pool_name}-0"
cat <<EOL > "$minio_tenant_values"
secrets:
name: credentials
tenant:
image:
repository: $(cut -d':' -f1 <<< "$minio_image_old")
tag: $(cut -d':' -f2 <<< "$minio_image_old")
name: $minio_tenant_name
configuration:
name: credentials
pools:
- name: $minio_pool_name
servers: 1
volumesPerServer: 1
storageClassName: ''
size: 50G
certificate:
requestAutoCert: true
env:
- name: MINIO_OPERATOR_TLS_ENABLE
value: "off"
- name: MINIO_DOMAIN
value: "example.org"
- name: MINIO_BROWSER_REDIRECT_URL
value: "https://console.example.org"
- name: MINIO_SERVER_URL
value: "https://example.org"
log:
disabled: true
prometheus:
disabled: true
EOL
cat <<EOL > "$minio_tenant_volume_config"
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-${minio_namespace}-${minio_pvc_name}
spec:
storageClassName: ''
claimRef:
name: $minio_pvc_name
namespace: $minio_namespace
local:
path: $minio_tenant_volume
capacity:
storage: 50G
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- $hostname
EOL
mkdir -p "$minio_tenant_volume"
echo "data-dir: $datadir"
touch "$log"
sudo k0s controller --config="$config" --data-dir="$datadir" --enable-worker=true --kubelet-extra-args=--node-ip="$ip" --no-taints=true > "$log" 2>&1 &
k0s_pid="$!"
while ! sudo k0s --data-dir="$datadir" kubectl get nodes 2>/dev/null | grep -q ' Ready '
do
echo "Node not ready yet..."
sleep 1
done
sudo k0s --data-dir="$datadir" kubeconfig admin > "$kubeconfig"
chmod 600 "$kubeconfig"
export KUBECONFIG="$kubeconfig"
kubectl apply -f "$minio_tenant_volume_config"
helm upgrade --install --repo 'https://operator.min.io/' --version "$minio_chart_version" --namespace "$minio_namespace" minio-operator operator -f "$minio_operator_values"
helm upgrade --install --repo 'https://operator.min.io/' --version "$minio_chart_version" --namespace "$minio_namespace" minio-tenant tenant -f "$minio_tenant_values"
echo
echo 'Commands:'
echo "export KUBECONFIG='$kubeconfig'"
echo "tail -f '$log'"
echo "kubectl logs -f pod/$minio_tenant_name-$minio_pool_name-0"
echo "kubectl edit tenant/$minio_tenant_name"
echo "kubectl logs -f deployment/minio-operator"
echo "kubectl patch tenant/$minio_tenant_name --type='json' -p='[{\"op\":\"replace\",\"path\":\"/spec/image\",\"value\":\"${minio_image_new}\"}]'"
echo "sudo k0s --data-dir='$datadir' reset"
wait "$k0s_pid"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment