Skip to content

Commit cb6da81

Browse files
committed
Update current feature
1 parent ce7c64d commit cb6da81

File tree

2 files changed

+30
-157
lines changed

2 files changed

+30
-157
lines changed

labs/0_kubeadm/exercice-kubeadm.md

Lines changed: 0 additions & 156 deletions
This file was deleted.

labs/0_kubeadm/scw.sh

100644100755
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/bin/bash
2+
# This script creates two instances on Scaleway and updates the SSH config file to include them.
3+
14
set -euxo pipefail
25

36
INSTANCE_TYPE="DEV1-L"
@@ -7,5 +10,31 @@ for i in $(seq 1 2); do
710
INSTANCE_NAME="k8s-$i"
811
echo "Creating instance $INSTANCE_NAME..."
912

10-
scw instance server create zone="fr-par-1" image=$DISTRIBUTION type="$INSTANCE_TYPE" name=$INSTANCE_NAME
13+
scw instance server create zone="fr-par-1" image=$DISTRIBUTION type="$INSTANCE_TYPE" ip="$ip_id" name=$INSTANCE_NAME
14+
instance_id=$(scw instance server list | grep $INSTANCE_NAME | awk '{print $1}')
15+
ip_address=$(scw instance server wait "$instance_id" | grep PublicIP.Address | awk '{print $2}')
16+
17+
CONFIG=~/.ssh/config
18+
HOST_ENTRY="Host $INSTANCE_NAME"
19+
HOSTNAME_LINE=" HostName $ip_address"
20+
USER_LINE=" User ubuntu"
21+
22+
# Update ~/.ssh/config to add the new instance
23+
if grep -q "^Host $INSTANCE_NAME\$" "$CONFIG"; then
24+
# Update HostName line for existing Host entry
25+
awk -v host="$INSTANCE_NAME" -v hostname="$HOSTNAME_LINE" '
26+
$0 == "Host "host {print; inhost=1; next}
27+
inhost && $1 == "HostName" {$0=hostname; inhost=0}
28+
{print}
29+
' "$CONFIG" > "$CONFIG.tmp" && mv "$CONFIG.tmp" "$CONFIG"
30+
else
31+
# Add new Host entry
32+
{
33+
echo "$HOST_ENTRY"
34+
echo "$HOSTNAME_LINE"
35+
echo "$USER_LINE"
36+
} >> "$CONFIG"
37+
fi
38+
39+
echo "Updated ~/.ssh/config for $INSTANCE_NAME"
1140
done

0 commit comments

Comments
 (0)