install incl agent ready
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
set fallback := true
|
||||
|
||||
export LOCAL_K8S_HOST := env("LOCAL_K8S_HOST", "")
|
||||
export K8S_CONTEXT := env("K8S_CONTEXT", "")
|
||||
export K8S_MASTER_NODE_NAME := env("K8S_MASTER_NODE_NAME", "")
|
||||
export EXTERNAL_K8S_HOST := env("EXTERNAL_K8S_HOST", "")
|
||||
export KEYCLOAK_HOST := env("KEYCLOAK_HOST", "")
|
||||
export KEYCLOAK_REALM := env("KEYCLOAK_REALM", "buunstack")
|
||||
export K8S_OIDC_CLIENT_ID := env('K8S_OIDC_CLIENT_ID', "k8s")
|
||||
export K3S_ENABLE_REGISTRY := env("K3S_ENABLE_REGISTRY", "true")
|
||||
export K3S_ENABLE_REGISTRY := env("K3S_ENABLE_REGISTRY", "false")
|
||||
export SERVER_IP := env("K3S_SERVER_IP","192.168.178.45")
|
||||
export AGENT_IP := env("K3S_AGENT_IP","192.168.178.75")
|
||||
export USER := env("K3S_USER","basti")
|
||||
@@ -26,20 +27,16 @@ install:
|
||||
gum input --prompt="KUBECONFIG file: " --value="${HOME}/.kube/config" --width=100
|
||||
)
|
||||
context=$(
|
||||
gum input --prompt="Context name: " --value="${LOCAL_K8S_HOST}" --width=100
|
||||
gum input --prompt="Context name: " --value="${K8S_CONTEXT}" --width=100
|
||||
)
|
||||
fi
|
||||
|
||||
args=(
|
||||
"install"
|
||||
"--host" "${LOCAL_K8S_HOST}"
|
||||
"--ip" "${SERVER_IP}"
|
||||
"--tls-san" "${EXTERNAL_K8S_HOST}"
|
||||
"--context" "${K8S_CONTEXT}"
|
||||
"--host" "${K8S_MASTER_NODE_NAME}"
|
||||
"--user" "${username}"
|
||||
)
|
||||
if [ -n "${context}" ]; then
|
||||
args+=("--context" "${context}")
|
||||
fi
|
||||
|
||||
if [ -n "${kubeconfig}" ]; then
|
||||
mkdir -p "$(dirname "${kubeconfig}")"
|
||||
@@ -74,31 +71,33 @@ install:
|
||||
echo " localhost:30500"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " export DOCKER_HOST=ssh://${LOCAL_K8S_HOST}"
|
||||
echo " export DOCKER_HOST=ssh://${K8S_MASTER_NODE_NAME}"
|
||||
echo " docker build -t localhost:30500/myapp:latest ."
|
||||
echo " docker push localhost:30500/myapp:latest"
|
||||
echo " kubectl run myapp --image=localhost:30500/myapp:latest"
|
||||
fi
|
||||
|
||||
echo "k3s cluster installed on ${LOCAL_K8S_HOST}."
|
||||
echo "k3s cluster installed on ${K8S_MASTER_NODE_NAME}."
|
||||
|
||||
|
||||
uninstall:
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
if gum confirm "Uninstall k3s from ${LOCAL_K8S_HOST}?"; then
|
||||
if gum confirm "Uninstall k3s from ${K8S_MASTER_NODE_NAME}?"; then
|
||||
|
||||
echo "Removing content of Agent node..."
|
||||
ssh "${AGENT_IP}" "/usr/local/bin/k3s-agent-uninstall.sh"
|
||||
if gum confirm "Also remove Agent node at ${AGENT_IP}?"; then
|
||||
echo "Removing Agent node at ${AGENT_IP}..."
|
||||
ssh "${AGENT_IP}" "/usr/local/bin/k3s-agent-uninstall.sh"
|
||||
fi
|
||||
|
||||
echo "Removing content of Server node..."
|
||||
ssh "${SERVER_IP}" "/usr/local/bin/k3s-uninstall.sh"
|
||||
ssh "${K8S_MASTER_NODE_NAME}" "/usr/local/bin/k3s-uninstall.sh"
|
||||
echo "Cleaning up kubeconfig entries..."
|
||||
cluster_name=$(kubectl config view -o json | jq -r ".contexts[] | select(.name == \"${LOCAL_K8S_HOST}\") | .context.cluster // empty")
|
||||
user_name=$(kubectl config view -o json | jq -r ".contexts[] | select(.name == \"${LOCAL_K8S_HOST}\") | .context.user // empty")
|
||||
if kubectl config get-contexts "${LOCAL_K8S_HOST}" &>/dev/null; then
|
||||
kubectl config delete-context "${LOCAL_K8S_HOST}"
|
||||
echo "Deleted context: ${LOCAL_K8S_HOST}"
|
||||
cluster_name=$(kubectl config view -o json | jq -r ".contexts[] | select(.name == \"${K8S_CONTEXT}\") | .context.cluster // empty")
|
||||
user_name=$(kubectl config view -o json | jq -r ".contexts[] | select(.name == \"${K8S_CONTEXT}\") | .context.user // empty")
|
||||
if kubectl config get-contexts "${K8S_CONTEXT}" &>/dev/null; then
|
||||
kubectl config delete-context "${K8S_CONTEXT}"
|
||||
echo "Deleted context: ${K8S_CONTEXT}"
|
||||
fi
|
||||
if [ -n "${cluster_name}" ] && kubectl config get-clusters | grep -q "^${cluster_name}$"; then
|
||||
kubectl config delete-cluster "${cluster_name}"
|
||||
@@ -108,7 +107,7 @@ uninstall:
|
||||
kubectl config delete-user "${user_name}"
|
||||
echo "Deleted user: ${user_name}"
|
||||
fi
|
||||
echo "k3s cluster uninstalled from ${LOCAL_K8S_HOST}."
|
||||
echo "k3s cluster uninstalled from ${K8S_CONTEXT}."
|
||||
else
|
||||
echo "Uninstallation cancelled." >&2
|
||||
exit 1
|
||||
@@ -131,4 +130,6 @@ add-agent:
|
||||
|
||||
|
||||
echo "Running: k3sup ${args[*]}"
|
||||
k3sup "${args[@]}"
|
||||
echo "Agent node at ${new_agent_ip} added to cluster."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user