added some comments and refactored idempotency

This commit is contained in:
root 2023-07-23 21:53:37 -06:00
parent 318f6adc5d
commit f5faecaae4
2 changed files with 36 additions and 33 deletions

View File

@ -5,37 +5,47 @@ export PATH=$PATH:$(go env GOPATH)/bin
reg_name="kind-registry" reg_name="kind-registry"
reg_port="5001" reg_port="5001"
# Build utility image if it doesn't already exist
if [ "$(podman image list --format='{{.Repository}}:{{.Tag}}' 2>/dev/null | cut -d/ -f2 | tr '[:upper:]' '[:lower:]' | egrep 'utility:latest')" != 'utility:latest' ]; then
podman build -t utility .
fi
# Deploy local registry container
if [ "$(podman inspect -f '{{.State.Running}}' ${reg_name} 2>/dev/null || true)" != 'true' ]; then if [ "$(podman inspect -f '{{.State.Running}}' ${reg_name} 2>/dev/null || true)" != 'true' ]; then
podman run -d -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" registry:2 podman run -d -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" registry:2
fi fi
kind get clusters -q | egrep '^ek-demo$' >/dev/null || cat <<EOF | kind create cluster -n ek-demo --image kindest/node:v1.24.15 --kubeconfig .kube/config --config=- # Create cluster, with ingress and registry patches
kind: Cluster if [ ! "$(kind get clusters -q | egrep '^ek-demo$' >/dev/nulli)" ]; then
apiVersion: kind.x-k8s.io/v1alpha4 cat <<-EOF | kind create cluster -n ek-demo --image kindest/node:v1.24.15 --kubeconfig .kube/config --config=-
containerdConfigPatches: kind: Cluster
- |- apiVersion: kind.x-k8s.io/v1alpha4
[plugins."io.containerd.grpc.v1.cri".registry] containerdConfigPatches:
config_path = "/etc/containerd/certs.d" - |-
nodes: [plugins."io.containerd.grpc.v1.cri".registry]
- role: control-plane config_path = "/etc/containerd/certs.d"
kubeadmConfigPatches: nodes:
- | - role: control-plane
kind: InitConfiguration kubeadmConfigPatches:
nodeRegistration: - |
kubeletExtraArgs: kind: InitConfiguration
node-labels: "ingress-ready=true" nodeRegistration:
extraPortMappings: kubeletExtraArgs:
- containerPort: 80 node-labels: "ingress-ready=true"
hostPort: 80 extraPortMappings:
protocol: TCP - containerPort: 80
- containerPort: 443 hostPort: 80
hostPort: 443 protocol: TCP
protocol: TCP - containerPort: 443
- role: worker hostPort: 443
- role: worker protocol: TCP
- role: worker - role: worker
EOF - role: worker
- role: worker
EOF
fi
# Add registry to each node
REGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}" REGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}"
for node in $(kind get nodes -q --name staticweb); do for node in $(kind get nodes -q --name staticweb); do
podman exec "${node}" mkdir -p "${REGISTRY_DIR}" podman exec "${node}" mkdir -p "${REGISTRY_DIR}"

View File

@ -1,7 +0,0 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker