-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-talos-from-bastion.sh
More file actions
executable file
Β·219 lines (195 loc) Β· 6.32 KB
/
deploy-talos-from-bastion.sh
File metadata and controls
executable file
Β·219 lines (195 loc) Β· 6.32 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/env bash
# deploy-talos-from-bastion.sh - Complete Talos deployment from ARM64 bastion host
set -euo pipefail
# Configuration
REGION="eu-west-1"
VPC_ID="vpc-04af837e642c001c6"
SECURITY_GROUP="sg-0e6b4a78092854897"
SUBNET_ID="subnet-07a140ab2b20bf89b"
TALOS_AMI="ami-07898be81f2028262"
CUSTOM_TALOS_IMAGE="ghcr.io/urmanac/cozystack-assets/talos/cozystack-spin-tailscale/talos:latest"
# Instance configuration
INSTANCE_TYPE="c7g.large"
INSTANCE_IP="10.10.1.111"
INSTANCE_NAME="talos-bastion-deploy"
echo "π Deploying Talos ARM64 cluster from bastion host"
echo "π Region: $REGION, VPC: $VPC_ID"
echo "π§ Custom Image: $CUSTOM_TALOS_IMAGE"
# Install dependencies if not present
if ! command -v talosctl &> /dev/null; then
echo "π₯ Installing talosctl for linux-arm64..."
curl -sL https://github.com/siderolabs/talos/releases/download/v1.11.5/talosctl-linux-arm64 -o talosctl
chmod +x talosctl
sudo mv talosctl /usr/local/bin/
fi
if ! command -v jq &> /dev/null; then
echo "π₯ Installing jq..."
sudo apt-get update && sudo apt-get install -y jq
fi
# Clean up any existing configs
rm -f controlplane.yaml worker.yaml talosconfig time-server-patch.yaml
echo "π Creating Talos configuration patch..."
cat > time-server-patch.yaml << 'EOF'
machine:
time:
servers:
- 169.254.169.123
registries:
mirrors:
docker.io:
endpoints:
- http://10.10.1.100:5050
- http://10.10.1.100:5051
- http://10.10.1.100:5052
- http://10.10.1.100:5053
- http://10.10.1.100:5054
ghcr.io:
endpoints:
- http://10.10.1.100:5050
- http://10.10.1.100:5051
- http://10.10.1.100:5052
- http://10.10.1.100:5053
- http://10.10.1.100:5054
config:
10.10.1.100:5050:
tls:
insecureSkipVerify: true
10.10.1.100:5051:
tls:
insecureSkipVerify: true
10.10.1.100:5052:
tls:
insecureSkipVerify: true
10.10.1.100:5053:
tls:
insecureSkipVerify: true
10.10.1.100:5054:
tls:
insecureSkipVerify: true
install:
image: ghcr.io/urmanac/cozystack-assets/talos/cozystack-spin-tailscale/talos:latest
features:
kubernetesTalosAPIAccess:
enabled: true
allowedRoles:
- os:admin
allowedKubernetesNamespaces:
- kube-system
EOF
echo "π Generating Talos configuration..."
# We'll use a placeholder endpoint and update it after launch
CLUSTER_ENDPOINT="https://[::1]:6443"
talosctl gen config talos-cozystack-cluster $CLUSTER_ENDPOINT \
--with-examples=false \
--with-docs=false \
--with-kubespan \
--install-disk /dev/xvda \
--config-patch '@time-server-patch.yaml'
echo "ποΈ Launching Talos instance..."
INSTANCE_ID=$(aws ec2 run-instances \
--region $REGION \
--image-id $TALOS_AMI \
--instance-type $INSTANCE_TYPE \
--security-group-ids $SECURITY_GROUP \
--subnet-id $SUBNET_ID \
--private-ip-address $INSTANCE_IP \
--ipv6-address-count 1 \
--user-data file://controlplane.yaml \
--block-device-mappings '[
{
"DeviceName": "/dev/xvda",
"Ebs": {
"VolumeSize": 20,
"VolumeType": "gp3",
"DeleteOnTermination": true
}
},
{
"DeviceName": "/dev/xvdb",
"Ebs": {
"VolumeSize": 100,
"VolumeType": "gp3",
"DeleteOnTermination": true
}
}
]' \
--tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=$INSTANCE_NAME}]" \
--query 'Instances[0].InstanceId' \
--output text)
echo "β
Created Talos instance: $INSTANCE_ID"
# Wait for instance to be running
echo "β³ Waiting for instance to start..."
aws ec2 wait instance-running --region $REGION --instance-ids $INSTANCE_ID
# Get the instance's IPv6 address
IPV6_ADDRESS=$(aws ec2 describe-instances \
--region $REGION \
--instance-ids $INSTANCE_ID \
--query 'Reservations[0].Instances[0].NetworkInterfaces[0].Ipv6Addresses[0].Ipv6Address' \
--output text)
echo "π Instance IPv6: $IPV6_ADDRESS"
# Update the cluster configuration with the real endpoint
REAL_CLUSTER_ENDPOINT="https://[$IPV6_ADDRESS]:6443"
echo "π§ Updating cluster endpoint to: $REAL_CLUSTER_ENDPOINT"
# Regenerate config with real endpoint
talosctl gen config talos-cozystack-cluster $REAL_CLUSTER_ENDPOINT \
--with-examples=false \
--with-docs=false \
--with-kubespan \
--install-disk /dev/xvda \
--config-patch '@time-server-patch.yaml' \
--force
# Configure talosctl
export TALOSCONFIG=$(pwd)/talosconfig
talosctl config endpoint $IPV6_ADDRESS
talosctl config nodes $IPV6_ADDRESS
echo "β³ Waiting for Talos API to be ready (this may take 2-3 minutes)..."
for i in {1..30}; do
if talosctl health --server=false 2>/dev/null; then
echo "β
Talos API is ready!"
break
fi
echo "π Attempt $i/30: Talos API not ready yet, waiting 10s..."
sleep 10
done
# Check if we can connect
if ! talosctl health --server=false 2>/dev/null; then
echo "β Failed to connect to Talos API"
echo "π Check console output: aws ec2 get-console-output --region $REGION --instance-id $INSTANCE_ID"
exit 1
fi
echo "π Bootstrapping etcd..."
talosctl bootstrap
echo "β³ Waiting for cluster to be healthy..."
for i in {1..20}; do
if talosctl health 2>/dev/null; then
echo "β
Cluster is healthy!"
break
fi
echo "π Attempt $i/20: Cluster not healthy yet, waiting 15s..."
sleep 15
done
echo "π Retrieving kubeconfig..."
talosctl kubeconfig .
export KUBECONFIG=$(pwd)/kubeconfig
echo ""
echo "π Talos cluster deployed successfully!"
echo "π Test the cluster:"
echo " export KUBECONFIG=$(pwd)/kubeconfig"
echo " kubectl get nodes"
echo " talosctl health"
echo ""
echo "π Configuration files created:"
echo " - talosconfig (Talos API access)"
echo " - kubeconfig (Kubernetes access)"
echo " - controlplane.yaml (machine config)"
echo ""
echo "π Cluster endpoint: $REAL_CLUSTER_ENDPOINT"
echo "π Node IPv6: $IPV6_ADDRESS"
echo "πΎ Instance ID: $INSTANCE_ID"
echo ""
echo "π Monitor: aws ec2 get-console-output --region $REGION --instance-id $INSTANCE_ID"
# Test basic functionality
echo "π§ͺ Testing cluster..."
kubectl get nodes || echo "β Kubernetes not ready yet"
talosctl version || echo "β Talos connection issue"
echo "β¨ Deployment complete!"