Repository navigation
Expand file tree
/
Copy pathdeploy-from-nas.sh
More file actions
executable file
·144 lines (122 loc) · 4.57 KB
/
Copy pathdeploy-from-nas.sh
File metadata and controls
executable file
·144 lines (122 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
# ==============================================================================
# In-Memory NAS / Local Secret App Deployer (Zero Disk Footprint)
# ==============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/common.sh
source "${SCRIPT_DIR}/common.sh"
SOURCE_PATH=""
SERVER_HOST=""
SSH_USER="server"
SSH_PORT="22"
usage() {
cat <<EOF
Usage: $0 --source <path-to-nas-apps> [options]
Options:
--source <path> Local/NAS directory containing app manifests or secrets
--server <host> Server IP or hostname (to pipe securely via SSH)
--user <ssh-user> SSH user on the server (default: server)
--port <ssh-port> SSH port (default: 22)
--local Apply directly using local kubectl (requires local kubeconfig)
-h, --help Show this help message
How it works:
This script streams manifests directly from your NAS/encrypted disk into
the Kubernetes API in-memory (stdin).
ZERO plain-text files are ever written to the VPS disk.
Examples:
# Stream manifests from NAS to server over encrypted SSH pipe:
$0 --source /Volumes/NAS/cluster-apps --server 123.45.67.89
# Apply directly using local workstation kubectl:
$0 --source /Volumes/NAS/cluster-apps --local
EOF
exit 0
}
USE_LOCAL=false
while [[ $# -gt 0 ]]; do
case "$1" in
--source)
SOURCE_PATH="$2"
shift 2
;;
--server)
SERVER_HOST="$2"
shift 2
;;
--user)
SSH_USER="$2"
shift 2
;;
--port)
SSH_PORT="$2"
shift 2
;;
--local)
USE_LOCAL=true
shift
;;
-h|--help)
usage
;;
*)
warn "Unknown argument: $1"
shift
;;
esac
done
if [[ -z "${SOURCE_PATH}" ]]; then
fatal "Missing required argument: --source <path-to-nas-apps>."
fi
if [[ ! -e "${SOURCE_PATH}" ]]; then
fatal "Source path does not exist: ${SOURCE_PATH}"
fi
# ==============================================================================
# Method A: Local kubectl stream
# ==============================================================================
if [[ "${USE_LOCAL}" == "true" ]]; then
if ! command -v kubectl &>/dev/null; then
fatal "Local kubectl not found. Run inside 'nix develop' or install kubectl."
fi
info "Applying manifests directly from ${SOURCE_PATH} via local kubectl..."
if [[ -d "${SOURCE_PATH}" ]]; then
kubectl apply -R -f "${SOURCE_PATH}"
else
kubectl apply -f "${SOURCE_PATH}"
fi
success "All manifests applied directly into Kubernetes memory!"
exit 0
fi
# ==============================================================================
# Method B: In-Memory Stream over SSH Pipe (Zero Disk Footprint on VPS)
# ==============================================================================
if [[ -z "${SERVER_HOST}" ]]; then
echo -e "${YELLOW}Please enter the server IP or hostname to stream manifests to:${NC}"
read -r -p "Server Host: " SERVER_HOST
fi
if [[ -z "${SERVER_HOST}" ]]; then
fatal "Server host is required for remote SSH streaming."
fi
info "Connecting to ${SSH_USER}@${SERVER_HOST}:${SSH_PORT}..."
# Test SSH connectivity
if ! ssh -p "${SSH_PORT}" -o BatchMode=yes -o ConnectTimeout=5 "${SSH_USER}@${SERVER_HOST}" "true" 2>/dev/null; then
fatal "Cannot connect to ${SSH_USER}@${SERVER_HOST}:${SSH_PORT}. Verify SSH key and user."
fi
info "Streaming manifests from ${SOURCE_PATH} directly into remote kubectl stdin..."
if [[ -d "${SOURCE_PATH}" ]]; then
info "Collecting all .yaml manifests in ${SOURCE_PATH}..."
(
while IFS= read -r -d '' file; do
echo "---"
cat "${file}"
echo ""
done < <(find "${SOURCE_PATH}" -type f \( -name "*.yaml" -o -name "*.yml" \) -print0)
) | ssh -p "${SSH_PORT}" "${SSH_USER}@${SERVER_HOST}" 'sudo /usr/local/bin/kubectl apply -f -'
else
# Stream single file directly
ssh -p "${SSH_PORT}" "${SSH_USER}@${SERVER_HOST}" \
'sudo /usr/local/bin/kubectl apply -f -' < "${SOURCE_PATH}"
fi
success "=========================================================================="
success " Manifests and secrets successfully deployed to the cluster!"
success " In-memory streaming complete: ZERO secret files were written to VPS disk."
success "=========================================================================="